与此类似的问题:PHPUnit assert no method is called
如何断言除了我可以定义的一些方法之外没有调用任何方法?以下测试没有通过,因为PHPUnit验证所有expected()。
//Here assert that only 'firstMethodToBeCalled' and 'secondMethodToBeCalled' are called, and no more
$mock = $this->getMockBuilder('SomeClass')->getMock();
$mock->expects($this->never())
->method($this->anything());
$mock->expects($this->once())
->method('firstMethodToBeCalled');
$mock->expects($this->once())
->method('secondMethodToBeCalled');
答案 0 :(得分:1)
尝试使用它:
$mock = $this->getMockBuilder('SomeClass')->getMock();
$mock->expects($this->once())
->method('firstMethodToBeCalled');
$mock->expects($this->once())
->method('secondMethodToBeCalled');
$mock->expects($this->never())
->method(
$this->logicalAnd(
$this->logicalNot($this->equalTo('firstMethodToBeCalled')),
$this->logicalNot($this->equalTo('secondMethodToBeCalled')),
)
);