Could I load fixtures from different entity managers with LiipTestFixturesBundle

253 Views Asked by At

I have entities which are managed by two entity managers in Symfony 4 project and I would like to load fixtures from both connections for functional tests. For instance :

class AdapterTest extends KernelTestCase
{
    use FixturesTrait;

    ...

    protected function setUp(): void
    {
        self::bootKernel();

        // Not working, just for example
        $this->loadFixtures([CounterFixtures::class], false, 'counter');
        $this->loadFixtures([CountryFixtures::class]);

        ...
    }

    ...
}

Unfortunatly, tables are dropped and only tables related to last entity manager connection are loaded.

I use LiipTestFixturesBundle v1.9.1.

Does this bundle support it or do you know how I can do that?

1

There are 1 best solutions below

0
On

The second parameter of loadFixtures is $append, its value is false by default.

It should work with this code:

class AdapterTest extends KernelTestCase
{
    use FixturesTrait;

    ...

    protected function setUp(): void
    {
        self::bootKernel();

        // Different entity manager but append = false so it clears the database
        $this->loadFixtures([CounterFixtures::class], false, 'counter');
        // Default entity manager but append = true so existing data is kept
        $this->loadFixtures([CountryFixtures::class], true);

        ...
    }

    ...
}