PHPUnit断言没有调用任何方法 [英] PHPUnit assert no method is called
本文介绍了PHPUnit断言没有调用任何方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用ServiceB的ClassA.在某些情况下,ClassA应该最终不调用ServiceB的任何方法.我现在想测试一下,确实没有真正调用任何方法.
I have a ClassA that uses a ServiceB. In a certain case, ClassA should end up not invoking any methods of ServiceB. I now want to test this and verity no methods are indeed called.
这可以如下进行:
$classA->expects( $this->never() )->method( 'first_method' );
$classA->expects( $this->never() )->method( 'second_method' );
...
有没有一种方法可以简单地声明不应在此对象上调用任何方法",而是必须为每个方法指定一个限制?
Is there a way to simply state "no method should be called on this object" rather then having to specify a restriction for each method?
推荐答案
是的,非常简单,请尝试以下操作:
Yes, it's quite simple, try this:
$classA->expects($this->never())->method($this->anything());
这篇关于PHPUnit断言没有调用任何方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文