【发布时间】:2015-09-18 21:56:55
【问题描述】:
我有索引方法
public function indexAction()
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('AppBundle:Blog')->findAll();
return array(
'entities' => $entities,
);
} // End of method
当我尝试对此操作进行单元测试时,如下所示
public function testIndexAction()
{
$entityManager = $this->getMockBuilder('BlogController')
->disableOriginalConstructor()
->setMethods(array('getRepository'))
->getMock();
$entityManager->expects($this->once())
->method('findAll')
->will($this->returnValue(0));
} // End of method
它在下面给我错误
AppBundle\Tests\Controller\BlogController\BlogControllerTest::testIndexAction 方法名称的期望失败等于何时 调用了 1 次。
方法预期调用1次,实际调用0次。
【问题讨论】:
-
findAll 在存储库对象而不是实体管理器上被调用。两个完全不同的对象。