背景:,我仍在学习使用模拟,并试图测试一个WordPress插件。我不喜欢加载WordPress,而只是在需要时使用模拟来伪造类/函数,并且只测试代码的输入和输出。
我想做以下几点:
// 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());
上述的可能与嘲弄吗?
发布于 2014-11-16 01:32:43
当将数组作为第二个参数传递给Mockery::mock
时,它期待的是构造函数参数,而不是要模拟的方法。
相反,你需要:
$mock = \Mockery::mock('WP_Query');
$mock->shouldReceive('have_posts')->andReturn(true);
https://stackoverflow.com/questions/26955474
复制相似问题