Code Monkey home page Code Monkey logo

doctrinefixtures's Introduction

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!

doctrinefixtures's People

Contributors

tomasvotruba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.