PHPackages                             nnx/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. nnx/data-fixtures

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

nnx/data-fixtures
=================

Data Fixtures for all Doctrine Object Managers

2.0.0(9y ago)017MITPHPPHP ^5.6 || ^7.0

Since Jan 12Pushed 9y ago2 watchersCompare

[ Source](https://github.com/nnx-framework/data-fixtures)[ Packagist](https://packagist.org/packages/nnx/data-fixtures)[ Docs](http://www.doctrine-project.org)[ RSS](/packages/nnx-data-fixtures/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (4)Versions (15)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

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor4

4 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 ~130 days

Total

14

Last Release

3583d ago

Major Versions

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

v1.2.1 → 2.0.02016-09-07

PHP version history (2 changes)v1.0.0-ALPHA1PHP &gt;=5.3.2

v1.2.0PHP ^5.6 || ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f0442374274922dd6b7c1690cbb8b5fd4fdc39d2b5ec93362eed0529dfc371b2?d=identicon)[nnx-framework](/maintainers/nnx-framework)

---

Top Contributors

[![Ocramius](https://avatars.githubusercontent.com/u/154256?v=4)](https://github.com/Ocramius "Ocramius (51 commits)")[![guilhermeblanco](https://avatars.githubusercontent.com/u/208883?v=4)](https://github.com/guilhermeblanco "guilhermeblanco (34 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)")[![peterrehm](https://avatars.githubusercontent.com/u/2010989?v=4)](https://github.com/peterrehm "peterrehm (10 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)")[![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)")[![mgirouard](https://avatars.githubusercontent.com/u/206137?v=4)](https://github.com/mgirouard "mgirouard (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)")

---

Tags

database

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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