Skip to content

Latest commit

 

History

History
executable file
·
100 lines (69 loc) · 2.94 KB

README.md

File metadata and controls

executable file
·
100 lines (69 loc) · 2.94 KB

Doctrine Fixtures

Build Status Quality Score Code Coverage Downloads this Month Latest stable

This package implements all you need for effective dummy data generation:

Install

Via Composer:

$ composer require zenify/doctrine-fixtures

Register extensions in config.neon (includes Kdyby/Doctrine configuration):

extensions:
    - Kdyby\Annotations\DI\AnnotationsExtension
    - Kdyby\Events\DI\EventsExtension
    - Kdyby\Console\DI\ConsoleExtension
    doctrine: Kdyby\Doctrine\DI\OrmExtension
	fixtures: Zenify\DoctrineFixtures\DI\FixturesExtension

doctrine:
    host: localhost
    user: root
    password: 
    dbname: database

Configuration

# default values
fixtures:
	enabled: FALSE # turns on by default in CLI
	faker:
		providers: [] # here you can add list of custom providers
	alice:
		seed: 1
		locale: "cs_CZ"
		loaders:
			neon: Zenify\DoctrineFixtures\Alice\Loader\Neon

Fixture files

This extension loads fixtures from *.neon files, turns them into entities and inserts them to database.

To understand fixture files, just check nelmio/alice.

Short example: this will create 100 products with generated name:

Zenify\DoctrineFixtures\Tests\Entities\Product:
	"product{1..100}":
		__construct: ["<shortName()>"]

Usage

When you have your fixtures files ready, you have 2 options to load them:

Via CLI

Run in console in your project's root:

# show all commands
$ php www/index.php
 
# run fixture command 
$ php www/index.php doctrine:fixtures:load 

# get info about fixture command 
$ php www/index.php doctrine:fixtures:load -h 

In the code via FixturesLoader

$fixturesLoader = new Zenify\DoctrineFixtures\DataFixtures\Loader;
$fixturesLoader->loadFromDirectory(__DIR__ . '/fixtures');

$loadedEntities = $this->fixturesLoader->getFixtures(); // get loaded entities