本文介绍了嘲笑应该接收()->一次()似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让Mockery断言给定方法至少被调用一次.
I'm trying to get Mockery to assert that a given method is called at least once.
我的考试班是:
use \Mockery as m;
class MyTest extends \PHPUnit_Framework_TestCase
{
public function testSetUriIsCalled()
{
$uri = 'http://localhost';
$httpClient = m::mock('Zend\Http\Client');
$httpClient->shouldReceive('setUri')->with($uri)->atLeast()->once();
}
}
如您所见,有一个测试(希望)创建了一个预期将调用setUri的测试.由于没有涉及其他任何代码,因此我无法想象可以 调用它,但是我的测试通过了.谁能解释为什么?
As you can see, there's one test that (hopefully) creates an expectation that setUri will be called. Since there isn't any other code involved, I can't imagine that it could be called and yet my test passes. Can anyone explain why?
推荐答案
您需要致电Mockery:close()
进行符合您期望的验证.它还处理下一个测试用例的嘲笑容器的清理.
You need to call Mockery:close()
to run verifications for your expectations. It also handles the cleanup of the mockery container for the next testcase.
public function tearDown()
{
parent::tearDown();
m::close();
}
这篇关于嘲笑应该接收()->一次()似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!