PHPackages                             theodordiaconu/doctrine-fixture-helper - 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. theodordiaconu/doctrine-fixture-helper

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

theodordiaconu/doctrine-fixture-helper
======================================

Helping you work with Doctrine Fixtures much faster

81.6k2[1 issues](https://github.com/theodorDiaconu/doctrine-fixture-helper/issues)PHP

Since Feb 24Pushed 10y ago1 watchersCompare

[ Source](https://github.com/theodorDiaconu/doctrine-fixture-helper)[ Packagist](https://packagist.org/packages/theodordiaconu/doctrine-fixture-helper)[ RSS](/packages/theodordiaconu-doctrine-fixture-helper/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Doctrine Fixture Helper
=======================

[](#doctrine-fixture-helper)

The main idea of this is to decouple your DataFixture classes to avoid spaghetti, and write elegant code by using a bit of functional PHP.

This works with both ODM and ORM of Doctrine.

Installation
============

[](#installation)

```
composer require theodordiaconu/doctrine-fixture-helper dev-master

```

Add the fixtures bundle to AppKernel.php:

```
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),

```

Usage
=====

[](#usage)

To understand how it works, let's take the following scenario:

- You want to generate a bunch of users
- You want each user to have a given number of blog posts
- Each blog posts can have a certain number of comments given by some other users in the system.

In your DataFixtures/ORM folder from your bundle, we recommend having a Configuration class:

```
class Configuration
{
    const USERS = 100;
    const BLOG_POSTS_PER_USER = 5;
    const COMMENTS_PER_BLOG_POST = 15;

    public static $jobTitles = [
        'Manager', 'Customer Relation', 'Web-Consultant', 'Web Architect', 'Loan Provider', 'Boss'
    ];
}

```

Let's begin with Users.

```
use TD\FixtureHelper\BaseFixture;

class LoadUserData extends BaseFixture
{
    public function doLoad()
    {
        $this->userService = $this->container->get('user_service');

        $this->iterator(Configuration::USERS, function($index) {
            $user = new User();
            $user->setFirstname($this->faker->firstname());
            $user->setLastname($this->faker->lastname());
            $user->setJob($this->faker->randomElement(Configuration::$jobTitles));

            $this->userService->doSomething($user);

            return $user; // you must return the object.
        }, 'user'); // note: user is our reference name, the script will create user-1, user-2, user-3 accordingly.
    }

    public function getOrder()
    {
        return 1;
    }
}

```

Now let's create some blog posts for each user

```
    // in LoadBlogPostData.php
    public function doLoad()
    {
        $this->iterator('user', function(User $user) { // this will iterate through all existing users
            $this->iterator(Configuration::BLOG_POSTS_PER_USER, function($index) use ($user) {
                $blog = new BlogPost($user);
                $blog->setTitle($this->faker->sentence());
                $blog->setText($this->faker->text());

                return $blog;
            }, 'post')
        });
    }
    // update getOrder

```

Now let's leave comments to the blog posts:

```
    // in LoadCommentData.php
    public function doLoad()
    {
        $this->iterator('post', function(BlogPost $post) {
            $this->iterator(Configuration::COMMENTS_PER_BLOG_POST, function($index) use ($post) {
                $comment = new Comment($this->getRandomObject('user'));
                $comment->setPost($post);

                return $comment;
            }, 'comment-for-'.$post->getId())
        });
    }

    // update getOrder

```

Conclusion
==========

[](#conclusion)

As you might have already noticed, if the iterator gets an integer as the first parameter, it iterates one by one until that limit is reached, if it gets a string it assumes that you want to iterate through a collection of pre-existing object references.

As you can see we have written this with very few lines of code. And the sky is the limit. This will help you create very complex and interconnected entities.

API
===

[](#api)

```
$this->container // container
$this->manager // ObjectManager
$this->faker // faker
$this->getObjects('user') // will return all users
$this->getReference('user-1') // will return user-1
$this->getRandomObject('user') // will return a random element from user collection

```

Take a look at faker helper methods:

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1814863?v=4)[Theodor Diaconu](/maintainers/theodorDiaconu)[@theodorDiaconu](https://github.com/theodorDiaconu)

---

Top Contributors

[![theodorDiaconu](https://avatars.githubusercontent.com/u/1814863?v=4)](https://github.com/theodorDiaconu "theodorDiaconu (12 commits)")

### Embed Badge

![Health badge](/badges/theodordiaconu-doctrine-fixture-helper/health.svg)

```
[![Health](https://phpackages.com/badges/theodordiaconu-doctrine-fixture-helper/health.svg)](https://phpackages.com/packages/theodordiaconu-doctrine-fixture-helper)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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