doctrine / DoctrineFixturesBundle

Symfony integration for the doctrine/data-fixtures library
MIT License
2.46k stars 202 forks source link

Possibility to add fixtures into dependent group #371

Closed GSpecDrum closed 5 months ago

GSpecDrum commented 2 years ago

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

oleg-andreyev commented 1 year ago

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.

cs278 commented 8 months ago

@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!