nelmio/alice — pull request #28 by fspillner (2013-03-22 13:02:56+00:00)
Title: [RFC] Factory for fluent interfaces for defining and building datasets

Instead of doing the dataset inheritances in yaml file (because writing the parser can be very painful) let's introduce Factory class for defining and building datasets with fluent interface. (See https://github.com/nelmio/alice/pull/21)

Inpired from factory_girl (https://github.com/thoughtbot/factory_girl)

### Examples

#### Simple Entity

```php
$factory = new Factory();
$factory
->define('user')
->of('Entity\User')
->values(['username' => 'Bob', 'email' => ''])
;
$user = $factory->build('user');
$loader->load($user, ...);

$users = $factory->build('user', 20, array('username' => '));
$loader->load($users, ...);
```

#### Simple Entity with Inheritance

```php
$factory
->define('user')
->of('Entity\User')
->values(['username' => '', 'email' => '', 'is_admin' => false])
->end()

->define('admin < user')
->values(['username' => 'admin', 'is_admin' => true])
->end()
;
```

#### Complex Entity with Assocations

```php
$factory
->define('user')
->of('Entity\User')
->values(...)
;

$factory
->define('tag')
->of('Entity\Tag')
->values(array('name' => ''))
;

$factory
->define('article')
->of('Entity\Article')
->constructWith('Alice and Bob')
->assocOne('author', 'user')
->assocMany('tags', 'tag*', 5)
->values(array('content' => ''))
;
```