Skip to content

Commit

Permalink
Merge branch 'trunk' into chore/update-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
unfulvio-godaddy authored Jul 20, 2023
2 parents 0a63e22 + 0ca2039 commit e959863
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 4 additions & 4 deletions php/WP_Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public static function assertHooksAdded()
* It is possible to use Mockery methods to add expectations to the object returned, which will then be combined with any expectations that may have been passed as arguments.
*
* @param string $function function name
* @param array<string, mixed> $args optional arguments to set expectations
* @param mixed[] $args optional arguments to set expectations
* @return Mockery\Expectation
* @throws InvalidArgumentException
*/
Expand All @@ -446,7 +446,7 @@ public static function userFunction(string $function, array $args = [])
* esc_attr_e('some_value'); // echoes "some_value"
*
* @param string $function function name
* @param array<string, mixed>|scalar $args optional arguments
* @param mixed[]|scalar $args optional arguments
* @return Mockery\Expectation
* @throws InvalidArgumentException
*/
Expand All @@ -471,7 +471,7 @@ public static function echoFunction(string $function, $args = [])
* echo esc_attr('some_value'); // echoes "some_value"
*
* @param string $function function name
* @param array<string, mixed>|scalar $args function arguments (optional)
* @param mixed[]|scalar $args function arguments (optional)
* @return Mockery\Expectation
* @throws InvalidArgumentException
*/
Expand All @@ -493,7 +493,7 @@ public static function passthruFunction(string $function, $args = [])
*
* @param string|callable-string $function function to alias
* @param string|callable-string $aliasFunction actual function
* @param array<int|string, mixed>|scalar $args optional arguments
* @param mixed[]|scalar $args optional arguments
* @return Mockery\Expectation
* @throws InvalidArgumentException
*/
Expand Down
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 e959863

Please sign in to comment.