Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to add fixtures into dependent group #371

Closed
GSpecDrum opened this issue Jul 14, 2022 · 2 comments · Fixed by #421
Closed

Possibility to add fixtures into dependent group #371

GSpecDrum opened this issue Jul 14, 2022 · 2 comments · Fixed by #421

Comments

@GSpecDrum
Copy link

GSpecDrum commented Jul 14, 2022

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 GSpecDrum changed the title Possibility to include dependent fixtures into Fixture Groups Possibility to add fixtures into dependent group Jul 14, 2022
@oleg-andreyev
Copy link

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
Copy link
Contributor

cs278 commented Jan 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants