Hello,
I am hoping someone can help me with an issue I am having.
*[ISSUE]*
I'm mocking out Doctrine Repository*[1]* and Entity Manger*[2*] in my
functional test. So that when my requests are made I do not hit the
database and I can verify that the controllers response and route. However,
when I mock these entities and inject them into the service container, the
mocked entities only persist for the initial GET request. After the initial
GET request I use the crawler to identify my form and perform a POST via
the 'submit' method on the form. As a sanity check, inside my controller I
extract the container and see that my mocked entities are being used during
the GET, but during the POST symfony injects its own entitiy manger*[3]*instead
of mine.
*Please see [CODE] section below.*
*[GOAL]*
Can anyone help me understand why this is occurring and help me understand
how to keep my mocked entities in the container for the life of my
controller test?
*[1]* Doctrine\ORM\EntityRepository
*[2]* Doctrine\ORM\EntityManager
*[3]*
EntityManager5144076565ee8_546a8d27f194334ee012bfe64f629947b07e4919\__CG__\Doctrine\ORM\EntityManager
*[CODE]*
*final public function testPost() {*
*
*
* // Mocks*
* $entityRepository = $this*
* ->getMockBuilder('Doctrine\ORM\EntityRepository')*
* ->setMethods(array('findby'))->disableOriginalConstructor()*
* ->getMock();*
*
*
* $entityRepository->expects($this->any())->method('findBy')*
* ->will($this->returnValue(array()));*
*
*
* $em = $this->getMockBuilder('Doctrine\ORM\EntityManager')*
* ->setMethods(*
* array('getRepository', 'getClassMetadata', 'flush',*
* 'persist'))->disableOriginalConstructor()*
* ->getMock();*
* $em->expects($this->any())->method('flush')*
* ->will($this->returnValue(TRUE));*
* $em->expects($this->any())->method('persist')*
* ->will($this->returnValue(TRUE));*
*
*
* $em->expects($this->any())->method('getRepository')*
* ->will($this->returnValue($entityRepository));*
*
*
* $em->expects($this->any())->method('getClassMetadata')*
* ->will($this->returnValue(new ClassMetadata("test")));*
*
*
* // Create test client.*
* $client = static::createClient();*
*
*
* // Inject entity mock into service container.*
* $client->getContainer()*
* ->set('doctrine.orm.default_entity_manager', $em, 'container');*
*
*
* // Define request*
* $crawler = $client->request('GET', '/locations/types/add');*
*
*
* // Test form submission*
* $form = $crawler->selectButton('submit')->form();*
*
*
* $form['location_type[title]'] = 'FORM_TITLE';*
* $form['location_type[description]'] = "TEST DESCP";*
*
*
* $crawler = $client->submit($form);*
* }*
*[/CODE]*
--
--
If you want to report a vulnerability issue on Symfony, please read the
procedure on http://symfony.com/security
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
---
You received this message because you are subscribed to the Google Groups
"Symfony developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.