This command will list all the available fixtures, by order of execution.
php ./bin/doctrine fixtures:list
This command will execute one or all fixtures.
To execute all the fixtures, run:
php ./bin/doctrine fixtures:execute
To execute a specific fixture, run:
php ./bin/doctrine fixtures:execute --class=RoleLoader
When creating a new fixture, we have two requirements:
data/doctrine/fixturesFixtureInterface and have a load method.<?php
namespace Frontend\Fixtures;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Frontend\User\Entity\UserRole;
class RoleLoader implements FixtureInterface
{
public function load(ObjectManager $manager): void
{
$adminRole = new UserRole();
$adminRole->setName('admin');
$userRole = new UserRole();
$userRole->setName('user');
$guestRole = new UserRole();
$guestRole->setName('guest');
$manager->persist($adminRole);
$manager->persist($userRole);
$manager->persist($guestRole);
$manager->flush();
}
}
Fixtures can be ordered:
Please refer to this link for further details on ordering fixtures :
https://www.doctrine-project.org/projects/doctrine-data-fixtures/en/latest/how-to/fixture-ordering.html#fixture-ordering