dotkernel/dot-data-fixtures

Provides a CLI interface for listing & executing doctrine data fixtures

Maintainers

👁 dotkernel

Package info

github.com/dotkernel/dot-data-fixtures

pkg:composer/dotkernel/dot-data-fixtures

Statistics

Installs: 38 862

Dependents: 3

Suggesters: 0

Stars: 7

Open Issues: 0

1.5.0 2025-10-30 13:02 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 00ee227565ab8a818092135b492300d54e587107

  • Dotkernel Team <team.woop@dotkernel.com>

fixturesdoctrinedata-fixturesdotkernellaminasdoctrine-data-fixtures

This package is auto-updated.

Last update: 2026-06-29 01:53:53 UTC


README

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

dot-data-fixtures is a wrapper on top of doctrine/data-fixtures

Documentation

Documentation is available at: https://docs.dotkernel.org/dot-data-fixtures/.

Badges

👁 OSS Lifecycle
👁 PHP from Packagist (specify version)

👁 GitHub issues
👁 GitHub forks
👁 GitHub stars
👁 GitHub license

👁 Build Static
👁 codecov
👁 PHPStan

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

Executing fixtures will append data to the tables.

Requirements

  • PHP: 8.2, 8.3 or 8.4
  • doctrine/orm: => 3.0
  • doctrine/data-fixtures: => 2.0

Installation

Run the following command in your project directory

composer require dotkernel/dot-data-fixtures

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

\Dot\DataFixtures\ConfigProvider::class,

In doctrine.global.php (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)

<?php

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 = [
 $container->get(Dot\DataFixtures\Command\ExecuteFixturesCommand::class),
 $container->get(Dot\DataFixtures\Command\ListFixturesCommand::class),
];

ConsoleRunner::run(
 new SingleManagerProvider($entityManager),
 $commands
);

Usage

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

Creating fixtures

When creating a new fixture, we have two 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

<?php

declare(strict_types=1);

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

Ordering fixtures

Fixtures can be ordered:

  • by order
  • by dependencies

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