Skip to content

[Bug]: Multiple entity managers per connection OR entity manager name does not match connection name #225

@olifrieda

Description

@olifrieda

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:

public function setObjectManagerName(string $omName = null): void
{
$this->omName = $omName;
$this->om = $this->registry->getManager($omName);
$this->connection = $this->registry->getConnection($omName);
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions