Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the EntityManager inside of webtestcases in Symfony2

Tags:

I was wondering how I could retrieve the entitymanager inside of a WebTestCase instance.

e.g. to look whether a entity was really created in DB during the testrun.

Any ideas on that ?

like image 257
stoefln Avatar asked Apr 19 '11 12:04

stoefln


1 Answers

You can retrieve the DIC (Dependency Injection Container) through the Kernel, which is a protected member of the WebTestCase.

You could do this from within your WebTestCase:

$em = $this->kernel->getContainer()->get('doctrine.orm.entity_manager'); 

Update

From your own comment, there is even a shortcut for this (since you will have a client anyway):

$client = $this->getClient(); $container = $client->getContainer(); 

As is mentioned in the docs.

like image 121
igorw Avatar answered Jun 06 '23 22:06

igorw