Background: I am still learning to use mocks and am trying to test a WordPress plugin. I would prefer to not load WordPress and simply use mocks to fake class/function where needed and only test my code’s inputs and outputs.
I am trying to do the following:
// WP_Query IS NOT DEFINED
$mock = Mockery::mock('WP_Query', array('have_posts' => true));
$this->assertTrue($mock->have_posts());
$q = new WP_Query();
// fails with "Call to undefined method WP_Query::have_posts()"
$this->assertTrue($q->have_posts());
Is the above possible with Mockery?
When passed an array as the second argument to
Mockery::mock
, it’s expecting constructor arguments, not the methods to be mocked.Instead, you need: