So, when I run tests on my ZF/Doctrine application, some tests happen to break the Doctrine Entity Manager, and all the sequential tests fail due to EM being closed.
I set the EM up in my tests/bootstrap.php:
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap();
(...)
$bootstrap = $application->getBootstrap();
$em = $bootstrap->getResource('doctrinemanager');
Then I set it inside the test setUp() function ($this->_service is the service being tested):
$em = App::getEntityManager();
$this->_em = clone $em;
$this->_service->setEm($this->_em);
And then when I run a test that causes EM to throw an exception and close (and that's the correct behaviour for me), it stays closed throughout all the tests which of course fail due to EM being closed. That's just not the behaviour I expect for tests, as you can guess.
I tried cloning the EM before setting it in the service, but it didn't work.
Is there an easy way to reopen the EM maybe using some Doctrine methods?