2017 © Pedro Peláez
 

library doctrine-fixtures

Doctrine Fixtures, Faker and Alice integration into Nette

image

zenify/doctrine-fixtures

Doctrine Fixtures, Faker and Alice integration into Nette

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 17 Versions
  • 4 % Grown

The README.md

Doctrine Fixtures

Build Status Quality Score Code Coverage Downloads Latest stable, (*1)

Integration of nelmio/alice to Nette DI. This package adds .neon support to Alice., (*2)

Alice uses fzaninotto/Faker to generate fake data, so be sure to check that too., (*3)

Install

composer require zenify/doctrine-fixtures

Register extensions:, (*4)

# app/config/config.neon
extensions:
    - Kdyby\Annotations\DI\AnnotationsExtension
    - Kdyby\Events\DI\EventsExtension
    doctrine: Kdyby\Doctrine\DI\OrmExtension
    fixtures: Zenify\DoctrineFixtures\DI\FixturesExtension

Configuration

# default values
fixtures:
    locale: "cs_CZ" # e.g. change to en_US in case you want to use English
    seed: 1

For all supported locales, just check Faker Providers., (*5)

Usage

We can load .neon/.yaml with specific fixtures structure. Alice turns them into entities and inserts them to database. To understand fixture files, just check the README of nelmio/alice., (*6)

For example, this fixture will create 100 products with generated name:, (*7)

fixtures/products.neon, (*8)

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

You can also include other fixtures

fixtures/products.neon, (*9)

include:
    - categories.neon

Zenify\DoctrineFixtures\Tests\Entity\Product:
    "product{1..100}":
        __construct: ["<shortName()>"]
        category: "@category@brand<numberBetween(1, 10)>"

fixtures/categories.neon, (*10)

Zenify\DoctrineFixtures\Tests\Entity\Category:
    "category{1..10}":
        __construct: ["<shortName()>"]

And then we can load them:, (*11)

use Zenify\DoctrineFixtures\Contract\Alice\AliceLoaderInterface;


class SomeClass
{

    /**
     * @var AliceLoaderInterface
     */
    private $aliceLoader;


    public function __construct(AliceLoaderInterface $aliceLoader)
    {
        $this->aliceLoader = $aliceLoader;
    }


    public function loadFixtures()
    {
        // arg can be used file(s) or dir(s) with fixtures
        $entities = $this->aliceLoader->load(__DIR__ . '/fixtures');
        // ...
    }

}

That's it!, (*12)

Testing

composer check-cs
vendor/bin/phpunit

Contributing

Rules are simple:, (*13)

  • new feature needs tests
  • all tests must pass
  • 1 feature per PR

We would be happy to merge your feature then!, (*14)

The Versions

03/11 2015

v4.0.2

4.0.2.0

Doctrine Fixtures, Faker and Alice integration into Nette

  Sources   Download

MIT

The Requires

 

The Development Requires

12/06 2015
12/06 2015