脚本宝典收集整理的这篇文章主要介绍了嘲笑 – PHPUnit模拟多个期望,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我只想确保从不使用特定的类类型调用方法,但可以为其他类类型调用.所以这里有我解释我想要的代码:
$this->entITyManagerMock ->expects($this->any()) ->method('PErsist'); $this->entityManagerMock ->expects($this->never()) ->method('persist') ->with($this->isinstanceOf('MySpecificClass'));
现在我收到类似这样的消息:
Doctrine\ORM\EntityManager::persist(DifferentClassType Object (...)) was not expected to be called.
当我期望第一次期望处理它.
我尝试了这个,但结果是一样的:
$this->entityManagerMock ->expects($this->any()) ->method('persist') ->with($this->anything()); $this->entityManagerMock ->expects($this->never()) ->method('persist') ->with($this->isinstanceOf('MySpecificClass'));
这是我第一次在PHPUnit中使用模拟,但在我看来,它已被破坏和/或没用.我知道现在大多数Web开发人员都使用TDD,所以必须有更好的方法来实现这一点.
returnCallback
:
$this->entityManagerMock ->expects($this->any()) ->method('persist') ->will($this->returnCallback(function ($object) { self::assertnotinstanceOf('MySpecificClass',$object); }));
以上是脚本宝典为你收集整理的嘲笑 – PHPUnit模拟多个期望全部内容,希望文章能够帮你解决嘲笑 – PHPUnit模拟多个期望所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。