PHPackages                             odolbeau/datagen - 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. odolbeau/datagen

Abandoned → [shapin/datagen](/?search=shapin%2Fdatagen)Symfony-bundle[Database &amp; ORM](/categories/database)

odolbeau/datagen
================

A simple lib to deal with fixtures.

221[1 issues](https://github.com/shapintv/datagen/issues)PHPCI failing

Since Dec 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/shapintv/datagen)[ Packagist](https://packagist.org/packages/odolbeau/datagen)[ RSS](/packages/odolbeau-datagen/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Datagen
=======

[](#datagen)

[![Latest Version](https://camo.githubusercontent.com/3b4822223577e6b3f161e75eaa300ef2f2994813eb8aa7b73b3b505801bf8b8b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73686170696e74762f6461746167656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/shapintv/datagen/releases)[![Build Status](https://camo.githubusercontent.com/09d81b369962e5b50e9c506c2706fd949e6a6bbfd77985193d637870ced5d5b1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f73686170696e74762f6461746167656e2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/shapintv/datagen)[![Code Coverage](https://camo.githubusercontent.com/f99b17fdb22c5c99d6722b50796c080c795e77000eff44c724a1516314cc897d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f73686170696e74762f6461746167656e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/shapintv/datagen)[![Quality Score](https://camo.githubusercontent.com/e3201d152530fb45c70897631a446022673591ab5442a29012629bcd5d7b620b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f73686170696e74762f6461746167656e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/shapintv/datagen)[![Total Downloads](https://camo.githubusercontent.com/29b06b7fd478b7a7d6194a1f8ca79018b671794db24b5e10e346e29ecc3fb044/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73686170696e2f6461746167656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/shapin/datagen)

Datagen is a PHP library to deal with fixtures loading.

Installation
------------

[](#installation)

The recommended way to install Datagen is through [Composer](http://getcomposer.org/). Require the `shapin/datagen` package:

```
$ composer require shapin/datagen

```

Usage
-----

[](#usage)

The main entrypoint is the `Shapin\Datagen\Datagen` class and its `load` method.

```
use Doctrine\DBAL\DriverManager;
use Shapin\Stripe\StripeClient;
use Symfony\Component\HttpClient\HttpClient;

use Shapin\Datagen\Datagen;
use Shapin\Datagen\DBAL\Processor as DBALProcessor;
use Shapin\Datagen\Loader;
use Shapin\Datagen\Stripe\Processor as StripeProcessor;
use Shapin\Datagen\ReferenceManager;

// Create a Loader for your fixtures
$loader = new Loader();
$loader->addFixture(new MyAwesomeFixture(), ['group1', 'group2']);
$loader->addFixture(new AnotherAwesomeFixture()); // Groups are faculative

$referenceManager = new ReferenceManager();

$connectionParams = [
    'dbname' => 'testDB',
    'user' => 'user',
    'password' => 'pass',
    'host' => 'localhost',
    'driver' => 'pdo_mysql',
];
$connection = DriverManager::getConnection($connectionParams);

$httpClient = HttpClient::create([
    'base_uri' => 'http://127.0.0.1:12111/v1/',
    'auth_bearer' => 'api_key',
    'headers' => [
        'Content-Type' => 'application/json',
    ],
]);
$stripeClient = new StripeClient($httpClient);

// Create your processors (see next section for more information regarding supported fixtures)
$processors = [
    new DBALProcessor($connection, $referenceManager),
    new StripeProcessor($stripeClient, $referenceManager),
];

// Create a Datagen
$datagen = new Datagen($loader, $processors);

// Load everything!
$datagen->load();
```

### Symfony

[](#symfony)

This library contains a bundle in order to integrate seamlessly with Symfony. For now, there isn't any symfony recipe so you'll need to manually register the bundle into your Kernel:

```
    public function registerBundles()
    {
        $contents = require $this->getProjectDir().'/config/bundles.php';
        foreach ($contents as $class => $envs) {
            if ($envs[$this->environment] ?? $envs['all'] ?? false) {
                yield new $class();
            }
        }

        // No symfony recipe (yet) for Datagen
        if (in_array($this->environment, ['dev', 'test'])) {
            yield new \Shapin\Datagen\Bridge\Symfony\Bundle\ShapinDatagenBundle();
        }
    }
```

Once registered, you'll have access to new commands in order to play with datagen.

Creating fixtures
-----------------

[](#creating-fixtures)

### DBAL

[](#dbal)

In order to create a table and hydrate it, extends the `Table` base class:

```
