This command will list all the available fixtures, by order of execution.
php bin/doctrine fixtures:list
This command will execute all or one fixture.
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 2 requirements :
data/doctrine/fixtures
FixtureInterface
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 we ordered using 2 methods :
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