-
-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnitOfWork
may not be empty at the start of test in case of database population
#26
Comments
…ating database. Fixes theofidry#26
I am not sure this can be changed. IIRC there was in the past an attempt made there, but I had to revert it because it was breaking too many things. Indeed you can get the objects from the loader in your tests in which case you want persisted objects. If you do the clear you will end up with objects you will have to persist manually |
Maybe it will be worth having an option to choose to clear At the very minimum, it needs to be mentioned in the documentation that the identity map in |
yea because with a lot of releations the entitys does not filled up correctly. i run into this issue: the roles doesn't load into the user entity. |
If you need a clear it's best to do it yourself. If it's systematic you can create a decorator service to handle this. Otherwise you use the service to load objects and you expect those objects to be in a managed state. If not, you would need to reattach all of them. |
Currently, the database population using traits does not include a cleanup of the identity map within Doctrine's
UnitOfWork
.It causes
UnitOfWork
to be in a "dirty" state by the time of running the test method and may cause unexpected side effects in the test.In my application, I have a test that fails because of entity information that is left during the database population, so the case is practical.
The solution is simple: a call of
EntityManager::clear()
needs to be added after loading of the fixturesAliceBundle/src/PhpUnit/BaseDatabaseTrait.php
Lines 69 to 77 in 0dd4e9e
The text was updated successfully, but these errors were encountered: