LiipTestFixturesBundle
LiipTestFixturesBundle copied to clipboard
Specifying an entity manager when using the loadFixtures method
Is your feature request related to a problem? Please describe. Hi team, I have two different bundles in my app and each one has their own entity manager. I am writing an integration test for a service in one of the bundles, but I need to load a fixture class from the second bundle. Is this currently possible?
Describe alternatives you've considered
I tried passing in the name of the entity manager for the fixture I'd like to load, in the $omName parameter of the loadFixtures method unsuccessfully. This was the main exception I kept getting:
InvalidArgumentException: Doctrine ORM Manager named "shared" does not exist.
I also tried different variations of the entity manager name but same outcome, eg: "shared", "doctrine.orm.shared_entity_manager" and "shared_entity_manager":
Additional context Here is part of my doctrine orm config with the two entity managers for more context:
orm:
default_entity_manager: default
auto_generate_proxy_classes: '%kernel.debug%'
entity_managers:
default:
connection: client_database
auto_mapping: true
shared:
connection: shared_database
mappings:
AdminBundle:
type: annotation
dir: '%kernel.project_dir%/src/AdminBundle/Entity'
prefix: AdminBundle\Entity
Thanks, -Aleks
You can use 3rd and 4th parameters of loadFixtures for this: https://github.com/liip/LiipFunctionalTestBundle/blob/57f2b4054e86aace108cff2d9e9b7c417884ccf8/src/Test/WebTestCase.php#L250
I thought that it was documented but it looks like it's not.
Thanks for the quick feedback.
This is the way I'm currently trying with those parameters, and with the orm config above:
$this->loadFixtures([SomeEntityFixtures::class], false, 'shared');
The message I get is:
InvalidArgumentException: Doctrine ORM Connection named "shared" does not exist.
Am I doing something obviously wrong here?
Can you please try with shared_database instead of shared?
So if I do that I get this, slightly different message:
InvalidArgumentException: Doctrine ORM Manager named "shared_database" does not exist
Thanks.
Did you change the order of the parameters? You have InvalidArgumentException: Doctrine ORM **Connection** named instead of InvalidArgumentException: Doctrine ORM **Manager** named. This is strange.
No, I definitely didn't switch parameters - just changed the third parameter from 'shared' to 'shared_database'. I am not passing the 4th param as it defaults to 'doctrine' anyways. I agree the messages look strange, which is what threw me off initially (and prompted me to seek help here)
Your code looks valid. We need a test with several entity_managers, it would also fix issue liip/LiipFunctionalTestBundle#470 that use several entity managers too.