【发布时间】:2016-11-14 22:02:33
【问题描述】:
我是 phpunit 的新手。
我使用这个 sn-p 来模拟我的 EntityManager
$emMock = $this->getMock('\Doctrine\ORM\EntityManager',
array('getRepository', 'getClassMetadata', 'persist', 'flush'), array(), '', false);
$emMock->expects($this->any())
->method('getRepository')
->will($this->returnValue(new \it\foo\Entity\File()));
$emMock->expects($this->any())
->method('persist')
->will($this->returnValue(null));
$emMock->expects($this->any())
->method('getClassMetadata')
->will($this->returnValue((object) array('name' => 'aClass')));
$emMock->expects($this->any())
->method('flush')
->will($this->returnValue(null));
运行测试时出现此错误
错误:调用未定义的方法 it\foo\Entity\File::findBy()
如何模拟这个方法?
【问题讨论】:
标签: doctrine-orm phpunit