I am trying to mock a repository in symfony 2, so that I can work on a test data. The problem is that the entity manager returns empty entity object, with all values as NULL, as if it's from the real database. What's wrong here? This is the code I've written so far:
$user = $this->getMock('\Acme\AdminBundle\Entity\Users');
$user->expects($this->once())
->method('getId')
->will($this->returnValue(1));
$user->expects($this->once())
->method('getEmail')
->will($this->returnValue('aaa'));
$userRepository = $this->getMockBuilder('\Doctrine\ORM\EntityRepository')
->disableOriginalConstructor()
->getMock();
$userRepository->expects($this->once())
->method('find')
->will($this->returnValue($user));
$entityManager = $this->getMockBuilder('\Doctrine\Common\Persistence\ObjectManager')
->disableOriginalConstructor()
->getMock();
$entityManager->expects($this->once())
->method('getRepository')
->will($this->returnValue($userRepository));
var_dump($entityManager->getRepository('Acme:Users')->find(1)); die();
Aucun commentaire:
Enregistrer un commentaire