Componette

Componette

deprecated-packages

deprecated-packages / DoctrineFixtures v4.0.3

[READ-ONLY] Nelmio\Alice integration to Nette

download-cloud-line composer require zenify/doctrine-fixtures

Doctrine Fixtures

Build Status Quality Score Code Coverage Downloads Latest stable

Integration of nelmio/alice to Nette DI. This package adds .neon support to Alice.

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

Install

composer require zenify/doctrine-fixtures

Register extensions:

# 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.

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.

For example, this fixture will create 100 products with generated name:

fixtures/products.neon

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

You can also include other fixtures

fixtures/products.neon

include:
	- categories.neon

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

fixtures/categories.neon

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

And then we can load them:

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!

Testing

composer check-cs
vendor/bin/phpunit

Contributing

Rules are simple:

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

We would be happy to merge your feature then!

  • v4.0.3 v4.0.3

    • Allow symfony/console v3.0
  • v4.0.0 Released version 4.0

    New features

    • #4 support for single files added, thanks to @trebi
    • support for .yaml files added

    Changes

    • update to Nelmio\Alice 2.0
    • update to fzaninotto/faker 1.5
    • bump min version to Nette 2.3
    • bump min version to PHP 5.6
    • dropped Doctrine\DataFixtures - not really useful concept
      • prefer Nelmio\Alice fixture files instead
      • or Doctrine\Migrations for production web data
    • Contracts introduced

    Full diff: v3.0.1...v4.0.0

  • v3.0.1 Released version 3.0.1

    New features

    • compatible with Nette 2.3
    • README in now complete with rich Install and Usage sections
    • tests now respect PSR-4 and src dir structure

    Bug fixes

    • added missing Kdyby\Doctrine dependency

    Full diff: v3.0.0...v3.0.1

Componette Componette felix@nette.org