Skip to content

--list or --dry-run option for doctrine:fixtures:load command #508

@alexdawn

Description

@alexdawn

Feature Request

What

Add a --list or --dry-run option the the command to previous what fixtures will be run without actually running them.

A second feature would be a command option for --filter-name to be able to filter by FullyQualifiedClass name

Why

The project I'm working on has a complex mixture fixtures across libraries, bundles and in the symfony Apps themselves. I'm often debugging service.yaml and doctrine_fixture.yaml to work out why a given fixture is not appearing in the doctrine:fixtures:load command.

More than that some of the fixtures are not in a good state (they are not idempontent) and throw Exceptions when executing. Other times fixtures are in different entity-managers. A --filter-name would allow me to execute the desired fixtures without worrying about the rest of the fixtures

How

for the preview table, in the console command doExecute:

if ($input->getOption('list')) {
            $ui->table(
                ['name', 'group', 'dependencies'],
                array_map(
                    /** @param Fixture|FixtureGroupInterface|DependentFixtureInterface $fixture */
                    fn(Fixture $fixture) => [
                        $fixture::class,
                        implode(',', method_exists($fixture, 'getGroups') ? $fixture->getGroups() : []),
                        implode(',', method_exists($fixture, 'getDependencies') ? $fixture->getDependencies() : [])
                    ],
                    $fixtures
                )
            );
            return 0;
        }

to be able to filter more than just by group:

tweak the SymfonyFixturesLoader::getFixtures to:

public function getFixtures(array $groups = [], ?string $nameFilter = null): array
...
$filteredFixtures = [];
        foreach ($fixtures as $order => $fixture) {
            $fixtureClass = get_class($fixture);
            if (
                isset($requiredFixtures[$fixtureClass])
                && (empty($nameFilter) || str_contains($fixtureClass, $nameFilter))) {
                $filteredFixtures[$order] = $fixture;
                continue;
            }
        }

        return array_values($filteredFixtures);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions