I am following the guide from Zend Framework 2's website on Unit Testing. My 'skeleton' app differs from the tutorial slightly in that I have integrated Doctrine 2 instead of using Zend's built in DB adapter.
Within the indexAction() of my AlbumController.php I am using the following snippet to retrieve all album records:
return new ViewModel(array(
'albums' => $this->getEntityManager()->getRepository('Album\Entity\Album')->findAll()
));
How can I mock this in testIndexActionCanBeAccessed() within the IndexControllerTest.php file so that it returns dummy values?
Appreciate the help.
create a mock of the EntityManager
create a mock of the AlbumRepository
create a mock of the AlbumEntity
then with PHP UNIT you would need to
create an $entityMock->expects($PHPUnit->once())->method('getRepository')->will($PHPUnit->returnValue($repositoryMock));
create a $repositoryMock->expects($PHPUnit->once())->method('findAll')->will($PHPUnit->returnValue(array($albumEntityMock));
depending on how you are implementing your PHPUnit testing the syntax may differ, but the steps should help you along the way.