Doctrine Fixtures
with Fake Data
Doctrine Fixtures
● Installation
○ composer.json
{
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "dev-master"
}
}
...
DoctrineFixtures Structure
● Source folder : {BundlesName}DataFixturesORMLoad{EntityName}Data.php
● class naming : Load{En...
fzaninotto/Faker
● Installation
php composer.phar require “fzaninotto/faker dev-master”
● Base Usage
$faker = FakerFactory...
fzaninotto/Faker - Formats
Localation
● Person
● Address
● Company
● PhoneNumber
General
● Lorem
● Internet / UserAgent
● ...
zaninotto/Faker
● Localization
$faker = FakerFactory::create('en_US');
$faker = FakerFactory::create('fr_FR');
● Seed
$fak...
fzaninotto/Faker
Unique and Optional modifiers
● required value
$faker->randomDigit;
● non-required values (default 0.5)
$...
fzaninotto/Faker (work with ORM entity)
● Orm adapters : Propel, Doctrine2,
Mandango
$generator = FakerFactory::create();
...
fzaninotto/Faker (work with ORM entity)
custom populating value
● Null Value
$populator->addEntity('Book', 5, array(
'Crea...
fzaninotto/Faker
● Internal Provider
○ FakerGenerator
○ FakerFactory::create();
● Custom Provider
Other Agenda
● Alice Faker Library
○ https://github.com/nelmio/alice
○ https://github.com/hautelook/AliceBundle
● Image Fa...
Thank For your Listenting !
Upcoming SlideShare
Loading in …5
×

Doctrine fixtures

4,621 views

Published on

Published in: Technology, Spiritual
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
4,621
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Doctrine fixtures

  1. 1. Doctrine Fixtures with Fake Data
  2. 2. Doctrine Fixtures ● Installation ○ composer.json { "require-dev": { "doctrine/doctrine-fixtures-bundle": "dev-master" } } ○ php composer.phar update doctrine/doctrine-fixtures- bundle ○ app/appKernel.php if (in_array($this->getEnvironment(), array('dev', 'test'))) { /* ... other bundles */ $bundles[] = new DoctrineBundleFixturesBundleDoctrineFixturesBundle(); }
  3. 3. DoctrineFixtures Structure ● Source folder : {BundlesName}DataFixturesORMLoad{EntityName}Data.php ● class naming : Load{EntityName}Data ● extends class: ○ DoctrineCommonDataFixturesAbstractFixture ○ method: Load(DoctrineCommonPersistenceObjectManager $em) ● Implements interface: ○ DoctrineCommonDataFixturesOrderedFixtureInterface ○ method: getOrder() ● Internal method ○ addReference($name,$entityObject); ○ hasReference($name) ○ getReference($name) ● Command: php app/console doctrine:fixtures:load
  4. 4. fzaninotto/Faker ● Installation php composer.phar require “fzaninotto/faker dev-master” ● Base Usage $faker = FakerFactory::create(); $name = $faker->name; $phone = $faker->phoneNumber; $url = $faker->url;
  5. 5. fzaninotto/Faker - Formats Localation ● Person ● Address ● Company ● PhoneNumber General ● Lorem ● Internet / UserAgent ● File ● Color ● Uuid ● DateTime ● Base(Random, Regex) ● Miscellaneous ● CreditCard
  6. 6. zaninotto/Faker ● Localization $faker = FakerFactory::create('en_US'); $faker = FakerFactory::create('fr_FR'); ● Seed $faker = FakerFactory::create(); $faker->seed(1234);
  7. 7. fzaninotto/Faker Unique and Optional modifiers ● required value $faker->randomDigit; ● non-required values (default 0.5) $faker->optional($weight = 0.1)->randomDigit; // 10% chance to get null $faker->optional($weight = 0.9)->randomDigit; // 90% chance to get null ● unique value(); $faker->unique()->randomDigit; $faker->unique($reset=true)->randomDigit;
  8. 8. fzaninotto/Faker (work with ORM entity) ● Orm adapters : Propel, Doctrine2, Mandango $generator = FakerFactory::create(); $populator = new FakerORMPropelPopulator($generator); $populator->addEntity('Author', 5); $populator->addEntity('SomeOneBundleEntityBook', 10); $insertedPKs = $populator->execute(); ● Populator by guessing ○ column name ○ column type ○ column length
  9. 9. fzaninotto/Faker (work with ORM entity) custom populating value ● Null Value $populator->addEntity('Book', 5, array( 'CreatedAt' => null )); ● anonyomous function $populator->addEntity('SomeOneBundleEntityPerson', 10,array( 'birthday' => function() use ($gen) { return $gen->dateTimeBetween($startDate = '-80 years', $endDate = '-10 years')->format("Y-m-d") ; } ));
  10. 10. fzaninotto/Faker ● Internal Provider ○ FakerGenerator ○ FakerFactory::create(); ● Custom Provider
  11. 11. Other Agenda ● Alice Faker Library ○ https://github.com/nelmio/alice ○ https://github.com/hautelook/AliceBundle ● Image Faker ? ○ http://image-faker.rmhdev.net/ ○ http://fakeimg.pl/
  12. 12. Thank For your Listenting !

×