PHPUnit assert no method is called

旧街凉风 提交于 2019-12-21 06:47:30

问题


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?


回答1:


Yes, it's quite simple, try this:

$classA->expects($this->never())->method($this->anything());


来源:https://stackoverflow.com/questions/18745032/phpunit-assert-no-method-is-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!