AliceDataFixtures: Doctrine lifecycle postLoad does not fire, clear() after LoaderInterface::load?
This was quite the challenge to debug so I’m just putting it here, at least for Google to find. It’s very simple and perfectly uinderstandable if you know about it.
TLDR If you’re persisting fixtures for use in tests, note that some Doctrine’s lifecycle events such as postLoad will not fire if you’re testing loading those items (or have custom handlers).
Reason is simple: you’re fetching an entity by ID? Entity manager already has it (since the fixture loader just created it), it will NOT:
- do a query
- trigger
postLoadevent(s)
If you want the system to behave as it should under test, make sure to clear() the entity manager(s) after loading the fixtures.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 16 (13 by maintainers)
Yes, I’m using it from Behat (for API Platform) and don’t modify objects at all (directly, that is), it’s just used to get the DB to a known state. When the fixtures are loaded, it should be handed over to my app.
Sounds good too. 👍