Open
Description
Preconditions
If the entity manager does have a name not matching the connection name or if having multiple entity managers per connection, it is not possible to load fixtures.
The reason is because of this:
public function setObjectManagerName(string $omName = null): void
{
$this->omName = $omName;
$this->om = $this->registry->getManager($omName);
$this->connection = $this->registry->getConnection($omName); <<<<< Connection name may not the same as OM name
}
See:
LiipTestFixturesBundle/src/Services/DatabaseTools/AbstractDatabaseTool.php
Lines 107 to 112 in 9ec9d52
Versions:
Bundle 2.6.0
PHP 8.1
Steps to reproduce
Configure doctrine like this:
doctrine:
dbal:
default_connection: core
connections:
core:
...
orm:
entity_managers:
core:
...
a_second_entity_manager:
...
or this:
doctrine:
dbal:
default_connection: core
connections:
default:
...
orm:
entity_managers:
a_name_not_matching_connection_name:
...
Then inside your test load a fixture like this:
static::getContainer()
->get(DatabaseToolCollection::class)
->get('a_second_entity_manager')
->loadFixtures([YourFixtures::class]);
or this:
static::getContainer()
->get(DatabaseToolCollection::class)
->get('a_name_not_matching_connection_name')
->loadFixtures([YourFixtures::class]);
Expected result
Successfully loading fixtures.
Actual result
InvalidArgumentException : Doctrine ORM Connection named "a_second_entity_manager" does not exist.
or:
InvalidArgumentException : Doctrine ORM Connection named "a_name_not_matching_connection_name" does not exist.