Skip to content
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

Specifying an entity manager when using the loadFixtures method #85

Open
leksinteractive opened this issue Jan 16, 2019 · 7 comments
Open
Labels
enhancement New feature or request

Comments

@leksinteractive
Copy link

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

@alexislefebvre
Copy link
Collaborator

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.

@leksinteractive
Copy link
Author

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?

@alexislefebvre
Copy link
Collaborator

Can you please try with shared_database instead of shared?

@leksinteractive
Copy link
Author

So if I do that I get this, slightly different message:

InvalidArgumentException: Doctrine ORM Manager named "shared_database" does not exist

Thanks.

@alexislefebvre
Copy link
Collaborator

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.

@leksinteractive
Copy link
Author

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)

@alexislefebvre
Copy link
Collaborator

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.

@alexislefebvre alexislefebvre transferred this issue from liip/LiipFunctionalTestBundle Jan 13, 2021
@alexislefebvre alexislefebvre added the enhancement New feature or request label Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants