DoctrineFixturesBundle icon indicating copy to clipboard operation
DoctrineFixturesBundle copied to clipboard

Possibility to add fixtures into dependent group

Open GSpecDrum opened this issue 3 years ago • 2 comments

I have strange behaviour when attempting to load fixture group by class name with dependent fixtures.

Example: Let's create two fixture classes:

<?php

declare(strict_types=1);

namespace App\DataFixtures;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

class InitFixtures extends Fixture
{
    public function load(ObjectManager $manager): void
    {
        // load init fixtures
    }
}
<?php

declare(strict_types=1);

namespace App\DataFixtures;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;

class DevFixtures extends Fixture implements DependentFixtureInterface
{
    public function load(ObjectManager $manager): void
    {
        // load dev fixtures
    }

    public function getDependencies(): array
    {
        return [
            InitFixtures::class,
        ];
    }
}

Then runing php bin/console doctrine:fixtures:load --group=DevFixtures --no-interaction caused error

In SymfonyFixturesLoader.php line 148:

  Fixture "App\DataFixtures\InitFixtures" was declared as a dependency for fixture "App\DataFixtures\DevFixtures", but it was not included in any of the loaded fixture groups.

Because InitFixtures doesn't have such group.

It would be great if dependent fixtures will be added automatically into groups, which from they depend. Like it is made in main library - https://github.com/doctrine/data-fixtures/blob/1.5.x/lib/Doctrine/Common/DataFixtures/Loader.php#L171-L177

GSpecDrum avatar Jul 14 '22 09:07 GSpecDrum

This is something I'd like to see too, IIRC at some point it was possible to load fixtures by name, and it would be great to have an ability to load fixtures by including all dependencies.

oleg-andreyev avatar Feb 08 '23 10:02 oleg-andreyev

@GSpecDrum @oleg-andreyev I've raised a PR to add this feature as I've stumbled upon this error and with a large fixture set it's quite a frustrating limitation!

cs278 avatar Jan 16 '24 16:01 cs278