PHPackages                             pinknoisebabies/data-fixtures - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. pinknoisebabies/data-fixtures

ActiveLibrary[Database &amp; ORM](/categories/database)

pinknoisebabies/data-fixtures
=============================

Data Fixtures for all Doctrine Object Managers

v1.1.2(10y ago)017MITPHPPHP &gt;=5.3.2

Since Jan 12Pushed 10y ago1 watchersCompare

[ Source](https://github.com/pinknoisebabies/data-fixtures)[ Packagist](https://packagist.org/packages/pinknoisebabies/data-fixtures)[ Docs](https://github.com/pinknoisebabies)[ RSS](/packages/pinknoisebabies-data-fixtures/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (2)Versions (13)Used By (0)

Doctrine Data Fixtures Extension
================================

[](#doctrine-data-fixtures-extension)

[![Build Status](https://camo.githubusercontent.com/786aa85831db8610c7f4bd68a368c59a9a3a7761e3020cbf5eccc4624db839e1/68747470733a2f2f7472617669732d63692e6f72672f646f637472696e652f646174612d66697874757265732e706e67)](https://travis-ci.org/doctrine/data-fixtures)

This extension aims to provide a simple way to manage and execute the loading of data fixtures for the [Doctrine ORM or ODM](http://www.doctrine-project.org/). You can write fixture classes by implementing the [`Doctrine\Common\DataFixtures\FixtureInterface`](lib/Doctrine/Common/DataFixtures/FixtureInterface.php) interface:

```
namespace MyDataFixtures;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\FixtureInterface;

class UserFixtureLoader implements FixtureInterface
{
    public function load(ObjectManager $manager)
    {
        $user = new User();
        $user->setUsername('jwage');
        $user->setPassword('test');

        $manager->persist($user);
        $manager->flush();
    }
}
```

Now you can begin adding the fixtures to a loader instance:

```
use Doctrine\Common\DataFixtures\Loader;
use MyDataFixtures\LoadUserData;

$loader = new Loader();
$loader->addFixture(new LoadUserData());
```

You can load a set of fixtures from a directory as well:

```
$loader->loadFromDirectory('/path/to/MyDataFixtures');
```

Or you can load a set of fixtures from a file:

```
$loader->loadFromFile('/path/to/MyDataFixtures/MyFixture1.php');

```

You can get the added fixtures using the getFixtures() method:

```
$fixtures = $loader->getFixtures();
```

Now you can easily execute the fixtures:

```
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;

$purger = new ORMPurger();
$executor = new ORMExecutor($em, $purger);
$executor->execute($loader->getFixtures());
```

If you want to append the fixtures instead of purging before loading then pass true to the 2nd argument of execute:

```
$executor->execute($loader->getFixtures(), true);
```

Sharing objects between fixtures
--------------------------------

[](#sharing-objects-between-fixtures)

In case if fixture objects have relations to other fixtures, it is now possible to easily add a reference to that object by name and later reference it to form a relation. Here is an example fixtures for **Role** and **User** relation

```
namespace MyDataFixtures;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;

class LoadUserRoleData extends AbstractFixture
{
    public function load(ObjectManager $manager)
    {
        $adminRole = new Role();
        $adminRole->setName('admin');

        $anonymousRole = new Role();
        $anonymousRole->setName('anonymous');

        $manager->persist($adminRole);
        $manager->persist($anonymousRole);
        $manager->flush();

        // store reference to admin role for User relation to Role
        $this->addReference('admin-role', $adminRole);
    }
}
```

And the **User** data loading fixture:

```
namespace MyDataFixtures;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;

class LoadUserData extends AbstractFixture
{
    public function load(ObjectManager $manager)
    {
        $user = new User();
        $user->setUsername('jwage');
        $user->setPassword('test');
        $user->setRole(
            $this->getReference('admin-role') // load the stored reference
        );

        $manager->persist($user);
        $manager->flush();

        // store reference of admin-user for other Fixtures
        $this->addReference('admin-user', $user);
    }
}
```

Fixture ordering
----------------

[](#fixture-ordering)

**Notice** that the fixture loading order is important! To handle it manually implement one of the following interfaces:

### OrderedFixtureInterface

[](#orderedfixtureinterface)

Set the order manually:

```
namespace MyDataFixtures;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class MyFixture extends AbstractFixture implements OrderedFixtureInterface
{
    public function load(ObjectManager $manager)
    {}

    public function getOrder()
    {
        return 10; // number in which order to load fixtures
    }
}
```

### DependentFixtureInterface

[](#dependentfixtureinterface)

Provide an array of fixture class names:

```
namespace MyDataFixtures;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;

class MyFixture extends AbstractFixture implements DependentFixtureInterface
{
    public function load(ObjectManager $manager)
    {}

    public function getDependencies()
    {
        return array('MyDataFixtures\MyOtherFixture'); // fixture classes fixture is dependent on
    }
}

class MyOtherFixture extends AbstractFixture
{
    public function load(ObjectManager $manager)
    {}
}
```

**Notice** the ordering is relevant to Loader class.

Running the tests:
------------------

[](#running-the-tests)

PHPUnit 3.5 or newer together with Mock\_Object package is required. To setup and run tests follow these steps:

- go to the root directory of data-fixtures
- run: **composer install --dev**
- copy the phpunit config **cp phpunit.xml.dist phpunit.xml**
- run: **phpunit**

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor5

5 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~146 days

Recently: every ~74 days

Total

11

Last Release

3771d ago

Major Versions

v1.0.0 → 2.0.x-dev2014-03-25

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ead5e414ce47a7c5a732a58b47677c77c49509e3b490c2a59f29dc93755d993?d=identicon)[pinknoisebabies](/maintainers/pinknoisebabies)

---

Top Contributors

[![guilhermeblanco](https://avatars.githubusercontent.com/u/208883?v=4)](https://github.com/guilhermeblanco "guilhermeblanco (31 commits)")[![beberlei](https://avatars.githubusercontent.com/u/26936?v=4)](https://github.com/beberlei "beberlei (21 commits)")[![jwage](https://avatars.githubusercontent.com/u/97422?v=4)](https://github.com/jwage "jwage (15 commits)")[![djlambert](https://avatars.githubusercontent.com/u/1187338?v=4)](https://github.com/djlambert "djlambert (13 commits)")[![lavoiesl](https://avatars.githubusercontent.com/u/1216046?v=4)](https://github.com/lavoiesl "lavoiesl (12 commits)")[![Ocramius](https://avatars.githubusercontent.com/u/154256?v=4)](https://github.com/Ocramius "Ocramius (11 commits)")[![stof](https://avatars.githubusercontent.com/u/439401?v=4)](https://github.com/stof "stof (9 commits)")[![comfortablynumb](https://avatars.githubusercontent.com/u/556188?v=4)](https://github.com/comfortablynumb "comfortablynumb (9 commits)")[![robocoder](https://avatars.githubusercontent.com/u/922051?v=4)](https://github.com/robocoder "robocoder (8 commits)")[![pinknoisebabies](https://avatars.githubusercontent.com/u/13955471?v=4)](https://github.com/pinknoisebabies "pinknoisebabies (5 commits)")[![l3pp4rd](https://avatars.githubusercontent.com/u/132389?v=4)](https://github.com/l3pp4rd "l3pp4rd (5 commits)")[![arendjantetteroo](https://avatars.githubusercontent.com/u/713066?v=4)](https://github.com/arendjantetteroo "arendjantetteroo (3 commits)")[![awartoft](https://avatars.githubusercontent.com/u/1127626?v=4)](https://github.com/awartoft "awartoft (3 commits)")[![theofidry](https://avatars.githubusercontent.com/u/5175937?v=4)](https://github.com/theofidry "theofidry (2 commits)")[![DenysMedvid](https://avatars.githubusercontent.com/u/639684?v=4)](https://github.com/DenysMedvid "DenysMedvid (2 commits)")[![jmikola](https://avatars.githubusercontent.com/u/244663?v=4)](https://github.com/jmikola "jmikola (2 commits)")[![leek](https://avatars.githubusercontent.com/u/60204?v=4)](https://github.com/leek "leek (2 commits)")[![makasim](https://avatars.githubusercontent.com/u/143206?v=4)](https://github.com/makasim "makasim (2 commits)")[![marijn](https://avatars.githubusercontent.com/u/65233?v=4)](https://github.com/marijn "marijn (2 commits)")[![plfort](https://avatars.githubusercontent.com/u/1080255?v=4)](https://github.com/plfort "plfort (2 commits)")

---

Tags

database

### Embed Badge

![Health badge](/badges/pinknoisebabies-data-fixtures/health.svg)

```
[![Health](https://phpackages.com/badges/pinknoisebabies-data-fixtures/health.svg)](https://phpackages.com/packages/pinknoisebabies-data-fixtures)
```

###  Alternatives

[sp/fixture-dumper

Dump fixtures from doctrine.

1114.6k1](/packages/sp-fixture-dumper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
