Skip to content

Commit

Permalink
Update return type for mockPost() (#226)
Browse files Browse the repository at this point in the history
Co-authored-by: Willington Vega <[email protected]>
Co-authored-by: Fulvio Notarstefano <[email protected]>
  • Loading branch information
3 people authored Jul 20, 2023
1 parent db23b60 commit 0ca2039
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions php/WP_Mock/Traits/MockWordPressObjectsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace WP_Mock\Traits;

use Mockery;
use Mockery\LegacyMockInterface;
use Mockery\MockInterface;
use WP;
use WP_Post;

Expand All @@ -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<string, mixed> $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 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,
Expand Down Expand Up @@ -52,10 +60,11 @@ protected function mockPost(array $postData = [])
* Mocks a WordPress instance.
*
* @param array<string, mixed> $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;
Expand Down

0 comments on commit 0ca2039

Please sign in to comment.