Doctrine Entity Administrator crashes and remains

So, when I run tests in my ZF / Doctrine application, some tests happen to break the Doctrine Entity Manager, and all consecutive tests fail because EM is closed.

I install EM in my /bootstrap.php tests:

$application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap(); (...) $bootstrap = $application->getBootstrap(); $em = $bootstrap->getResource('doctrinemanager'); 

Then I install it inside the setUp () function ($ this → _ service is the checked service):

 $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 is the correct behavior for me), it remains closed in all tests, which, of course, cannot complete due to EM closing. This is simply not the behavior that I expect for tests, as you might guess.

I tried to clone EM before installing it in the service, but that did not work.

Is there an easy way to reopen EM using some Doctrine methods?

+6
source share
1 answer

No, not what I know. The easiest way is to simply (reinstall) download the application to run at the setup stage of each test. Thus, each test receives a new instance of $application and a new, new $em along with it. This is a quick fix.

The correct solution is probably to separate your tests from your Zend_Application . Allow your tests to work with a simple entity manager, possibly using a connection layout or connection to an in-memory SQLite database . Create only this object manager at the testing stage, so each test receives a new entity manager. This seems like a quick fix above, except that now you only intentionally create an object manager for testing instead of loading your entire application for each test. It is more compact and simpler.

+6
source

Source: https://habr.com/ru/post/892641/


All Articles