bitecodes/factrine-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

An entity factory for Doctrine2 and Symfony2

Installs: 1 729

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

v0.8.0 2016-04-17 06:46 UTC

This package is not auto-updated.

Last update: 2022-08-01 07:28:56 UTC


README

Build Status Coverage Status Quality Score SensioLabsInsight

Useage

Create entity files

Will be added later

How to use factrine

Get a persisted entity

Most of the time you want persist an entity to the database. Call the create method and the factory will hand you a new persisted entity

$post = $factory->create(Post::class);

$post->getid();       // 1
$post->getTitle();    // Lorem ipsum dolores
$post->getComments(); // Get a collection of comments

Notice that the associated entities will also be generated, if they are specified in the YAML file.

Multiple entites

Maybe you need a set of entities. You can use the times method.

$comments = $factory->times(10)->create(Comment::class);

// You will receive 10 persisted comments with fake values

Override fake data

You might want to override some of the fake data. The create method takes an array as the second argument. Pass in the arguments you want to override.

$user = $factory->create(User::class, ['username' => 'admin']);

$user->getUsername(); // admin
$user->getEmail();    // wizfarrell@downdrum.org (fake data)

Get a new instance

If you don't want to persist the entity, you can call make and get a new instance of the entity.

$post = $factory->make(Post::class)

$post->getId()       // null
$post->getTitle()    // Hic clares nombre

Of course, you can also use the times method or override the default values.

Get fake values for an entity

Maybe you don't want an instance of the entity, but need some fake data to create you entity object. The values method will return an array of fake values for an entity.

$productData = $factory->values(Product::class);

$productData['category'] // Electronics
$productData['price']    // $20.87

$this->productHandler->create($productData);

Calling the times method, you will receive an array of array with fake data.