PHPUnit assert no method is called(PHPUnit 断言没有调用任何方法)
问题描述
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.
This can be done as follows:
$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 断言没有调用任何方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!