Provides a CLI interface for listing & executing doctrine data fixtures

1.1.3 2023-11-30 10:18 UTC

This package is auto-updated.

Last update: 2024-04-04 13:44:16 UTC


OSS Lifecycle PHP from Packagist (specify version)

GitHub issues GitHub forks GitHub stars GitHub license

Build Static codecov


This package provides a CLI interface for interacting with doctrine/data-fixtures.

Executing fixtures will append data to the tables.


  • PHP >= 8.1
  • doctrine/data-fixtures => 1.5


Run the following command in you project directory

$ composer require dotkernel/dot-data-fixtures

Next, register the package's ConfigProvider into your application config.


In (or your custom doctrine config file) add a new key fixtures, in the doctrine array, the value should be a valid path to a folder where your fixtures can be found.

Make sure the path is valid before proceeding to the next step.

Example :

return [
    'dependencies' => [ ... ],
    'doctrine' => [
        'fixtures' => getcwd() . '/data/doctrine/fixtures',

The last step is to register the commands. We can register the commands to work with the default CLI that doctrine provides us. Create a new php file bin/doctrine (if you don't already have this file feel free to copy it from the below example)


use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;

require_once 'vendor/autoload.php';

$container = require getcwd() . '/config/container.php' ;

$entityManager = $container->get(\Doctrine\ORM\EntityManager::class);

$commands = [

    new SingleManagerProvider($entityManager),


List fixtures command - will list all the available fixtures, by order of execution.

php bin/doctrine fixtures:list

Execute fixtures command - 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

Creating fixtures

When creating a new fixture we have 2 requirements :

  • Fixtures should be created in the folder we configured earlier. data/doctrine/fixtures
  • Fixtures should implement FixtureInterface and have a load method.
  • Create a new php file and copy the below code-block.

Example :


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();

        $userRole = new UserRole();
        $guestRole = new UserRole();


Ordering fixtures

Fixtures can we ordered using 2 methods :

  • by order
  • by dependencies

Please reffer to this link for further details on ordering fixtures: