From 4c9f604d817866d73073193953f18b3bdc4a79b8 Mon Sep 17 00:00:00 2001 From: Willington Vega <72778787+wvega-godaddy@users.noreply.github.com> Date: Wed, 19 Jul 2023 13:15:29 -0500 Subject: [PATCH 1/3] Update return type for mockPost() --- php/WP_Mock/Traits/MockWordPressObjectsTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/WP_Mock/Traits/MockWordPressObjectsTrait.php b/php/WP_Mock/Traits/MockWordPressObjectsTrait.php index 0a676b4..d6f94a6 100644 --- a/php/WP_Mock/Traits/MockWordPressObjectsTrait.php +++ b/php/WP_Mock/Traits/MockWordPressObjectsTrait.php @@ -15,7 +15,7 @@ trait MockWordPressObjectsTrait * Mocks a WordPress post. * * @param array $postData optional post data to add to the post - * @return Mockery\LegacyMockInterface|Mockery\MockInterface|WP_Post|(WP_Post&Mockery\LegacyMockInterface)|(WP_Post&Mockery\MockInterface) + * @return WP_Post&Mockery\MockInterface&Mockery\LegacyMockInterface */ protected function mockPost(array $postData = []) { From 7f2fae0317bc56d8d8f72f9ee9ab848a7e1703f2 Mon Sep 17 00:00:00 2001 From: Willington Vega Date: Wed, 19 Jul 2023 14:14:21 -0500 Subject: [PATCH 2/3] Update return type of mockPost() --- php/WP_Mock/Traits/MockWordPressObjectsTrait.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/php/WP_Mock/Traits/MockWordPressObjectsTrait.php b/php/WP_Mock/Traits/MockWordPressObjectsTrait.php index d6f94a6..eea575c 100644 --- a/php/WP_Mock/Traits/MockWordPressObjectsTrait.php +++ b/php/WP_Mock/Traits/MockWordPressObjectsTrait.php @@ -3,6 +3,8 @@ namespace WP_Mock\Traits; use Mockery; +use Mockery\LegacyMockInterface; +use Mockery\MockInterface; use WP; use WP_Post; @@ -14,12 +16,18 @@ trait MockWordPressObjectsTrait /** * Mocks a WordPress post. * + * Users of this method should add `@var WP_Post $variable` or `@var Mockery\MockInterface $variable` to + * set the necessary type for the resulting mock. Unfortunately, PHPStan doesn't allow WP_Post in an + * intersection type, because the class is marked as final. + * * @param array $postData optional post data to add to the post - * @return WP_Post&Mockery\MockInterface&Mockery\LegacyMockInterface + * @return Mockery\LegacyMockInterface&Mockery\MockInterface */ protected function mockPost(array $postData = []) { + /** @var Mockery\LegacyMockInterface&Mockery\MockInterface $post */ $post = Mockery::mock(WP_Post::class); + $postData = array_merge([ 'ID' => 0, 'post_author' => 0, From f32043b5cbafa36e25b1ba40c3b9f0a703fb1547 Mon Sep 17 00:00:00 2001 From: Willington Vega Date: Wed, 19 Jul 2023 14:14:31 -0500 Subject: [PATCH 3/3] Update return type of mockWp() --- php/WP_Mock/Traits/MockWordPressObjectsTrait.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/WP_Mock/Traits/MockWordPressObjectsTrait.php b/php/WP_Mock/Traits/MockWordPressObjectsTrait.php index eea575c..155d159 100644 --- a/php/WP_Mock/Traits/MockWordPressObjectsTrait.php +++ b/php/WP_Mock/Traits/MockWordPressObjectsTrait.php @@ -60,10 +60,11 @@ protected function mockPost(array $postData = []) * Mocks a WordPress instance. * * @param array $queryVars - * @return Mockery\LegacyMockInterface|Mockery\MockInterface|WP|(WP&Mockery\LegacyMockInterface)|(WP&Mockery\MockInterface) + * @return WP&LegacyMockInterface&MockInterface */ protected function mockWp(array $queryVars = []) { + /** @var WP&Mockery\LegacyMockInterface&Mockery\MockInterface $wp */ $wp = Mockery::mock(WP::class); /** @phpstan-ignore-next-line */ $wp->query_vars = $queryVars;