SlideShare ist ein Scribd-Unternehmen logo
1 von 12
Downloaden Sie, um offline zu lesen
Doctrine Fixtures
with Fake Data
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();
}
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
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;
fzaninotto/Faker - Formats
Localation
● Person
● Address
● Company
● PhoneNumber
General
● Lorem
● Internet / UserAgent
● File
● Color
● Uuid
● DateTime
● Base(Random, Regex)
● Miscellaneous
● CreditCard
zaninotto/Faker
● Localization
$faker = FakerFactory::create('en_US');
$faker = FakerFactory::create('fr_FR');
● Seed
$faker = FakerFactory::create();
$faker->seed(1234);
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;
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
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") ;
}
));
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 Faker ?
○ http://image-faker.rmhdev.net/
○ http://fakeimg.pl/
Thank For your Listenting !

Weitere ähnliche Inhalte

Was ist angesagt?

Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201
Fabien Potencier
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Masahiro Nagano
 
Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Dependency injection-zendcon-2010
Dependency injection-zendcon-2010
Fabien Potencier
 

Was ist angesagt? (20)

Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php framework
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful software
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
 
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
 
Building Lithium Apps
Building Lithium AppsBuilding Lithium Apps
Building Lithium Apps
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
 
Agile database access with CakePHP 3
Agile database access with CakePHP 3Agile database access with CakePHP 3
Agile database access with CakePHP 3
 
Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)Doctrine MongoDB ODM (PDXPHP)
Doctrine MongoDB ODM (PDXPHP)
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Dependency injection-zendcon-2010
Dependency injection-zendcon-2010
 
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo EditionLithium: The Framework for People Who Hate Frameworks, Tokyo Edition
Lithium: The Framework for People Who Hate Frameworks, Tokyo Edition
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language Trivia
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
 

Ähnlich wie Doctrine fixtures

Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
Alexei Gorobets
 
Databases and doctrine
Databases and doctrineDatabases and doctrine
Databases and doctrine
Glenn Guden
 
Auto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK NodesAuto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK Nodes
nihiliad
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objects
webhostingguy
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking
Sebastian Marek
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
Jonathan Wage
 

Ähnlich wie Doctrine fixtures (20)

Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016Coming to Terms with OOP In Drupal - php[world] 2016
Coming to Terms with OOP In Drupal - php[world] 2016
 
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
Dicoding Developer Coaching #27: Android | Membuat Aplikasi Support Online Ma...
 
Phactory
PhactoryPhactory
Phactory
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Writing and Publishing Puppet Modules
Writing and Publishing Puppet ModulesWriting and Publishing Puppet Modules
Writing and Publishing Puppet Modules
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
 
Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014Getting started with TDD - Confoo 2014
Getting started with TDD - Confoo 2014
 
Databases and doctrine
Databases and doctrineDatabases and doctrine
Databases and doctrine
 
Auto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK NodesAuto-loading of Drupal CCK Nodes
Auto-loading of Drupal CCK Nodes
 
Magic methods
Magic methodsMagic methods
Magic methods
 
09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboards09 Object Oriented Programming in PHP #burningkeyboards
09 Object Oriented Programming in PHP #burningkeyboards
 
vfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent testsvfsStream - a better approach for file system dependent tests
vfsStream - a better approach for file system dependent tests
 
Opps Concept
Opps ConceptOpps Concept
Opps Concept
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
 
Android Data Storagefinal
Android Data StoragefinalAndroid Data Storagefinal
Android Data Storagefinal
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
Zend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingZend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching logging
 
Introducing PHP Data Objects
Introducing PHP Data ObjectsIntroducing PHP Data Objects
Introducing PHP Data Objects
 
vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking vfsStream - effective filesystem mocking
vfsStream - effective filesystem mocking
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Doctrine fixtures

  • 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. 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. 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. fzaninotto/Faker - Formats Localation ● Person ● Address ● Company ● PhoneNumber General ● Lorem ● Internet / UserAgent ● File ● Color ● Uuid ● DateTime ● Base(Random, Regex) ● Miscellaneous ● CreditCard
  • 6. zaninotto/Faker ● Localization $faker = FakerFactory::create('en_US'); $faker = FakerFactory::create('fr_FR'); ● Seed $faker = FakerFactory::create(); $faker->seed(1234);
  • 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. 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. 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. fzaninotto/Faker ● Internal Provider ○ FakerGenerator ○ FakerFactory::create(); ● Custom Provider
  • 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. Thank For your Listenting !