bitecodes / factrine-bundle
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
Requires
- php: >=5.5
- dflydev/dot-access-data: ^1.0
- doctrine/doctrine-bundle: ~1.4
- doctrine/orm: >=2.2.1,<2.6-dev
- fzaninotto/faker: ^1.5
- symfony/console: >=2.6.0
- symfony/dependency-injection: >=2.7.0
- symfony/expression-language: >=2.6.0
- symfony/property-access: >=2.6.0
- symfony/yaml: >=2.6.0
Requires (Dev)
- matthiasnoback/symfony-dependency-injection-test: ^0.7.6
- mikey179/vfsstream: ^1.6.1
- phpunit/phpunit: ^4.8
- satooshi/php-coveralls: ~1.0
- symfony/finder: ^2.6
- symfony/framework-bundle: >=2.6.0
- symfony/http-kernel: >=2.6.0
README
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.