liip / liip/LiipTestFixturesBundle

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

Open
#225 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
178
Forks
48
PR merge metrics
No merged PRs in 30d

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:
https://github.com/liip/LiipTestFixturesBundle/blob/9ec9d52903df0c723b8d6489842c5b205a08bf8d/src/Services/DatabaseTools/AbstractDatabaseTool.php#L107-L112

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/Services/DatabaseTools/AbstractDatabaseTool.php at setObjectManagerName(), then trace DatabaseToolCollection service selection for the two configurations in the issue. Reproduce the fixture-loading failures and verify fixtures load successfully when an entity manager name differs from its connection name or multiple entity managers share a connection.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, symfony
Domain
databases, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.