大佬教程收集整理的这篇文章主要介绍了单元测试Doctrine ODM,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有人有他们认为最佳测试方法的最佳实践或示例?
class SomeSerivce { private $dm; public function __construct(DocumentManager $dm) { $this->dm = $dm; } public function doSomeMagic($someDocument,$somevalue) { $someDocument->setSomeValue($somevalue); $this->dm->persist($someDocument); $this->dm->flush(); } }
现在,您不会检查文档是否真的存在,因为这是在ID Doctrine代码的某处测试的.您可以假设persist和flush方法正常工作.您要检查的是您的代码是否正确调用这些方法.
所以,你的测试看起来像:
(...) public function testDoSomeMagic() { $documment = new Document(); // preapre expected object $expectedValue = 123; $expectedDocument = new Document(); $expectedDocument->SETVALue($expectedvalue); // prepare mock $dmmock = $this->getmockBuilder('DocumentManager') ->setMethods(array('persist','flush')) ->disabLeoriginalConstructor() ->getmock(); $dmmock->expects($this->once()) ->method('persist'); ->with($this->equalTo($expectedDocument)); $dmmock->expects($this->once()) ->method('flush'); // new we start tesTing with the mock $someservice = new Someservice($dmmock); $someservice->doSomeMagic($document,$expectedvalue); }
以上是大佬教程为你收集整理的单元测试Doctrine ODM全部内容,希望文章能够帮你解决单元测试Doctrine ODM所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。