ergebnis / factory-muffin-definition
Provides an interface for, and an easy way to find and register entity definitions for league/factory-muffin.
Fund package maintenance!
localheinz
Installs: 6 507
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.2
- ergebnis/classy: ~0.5.0
- league/factory-muffin: ^3.0.1
Requires (Dev)
- ergebnis/php-cs-fixer-config: ~1.0.0
- ergebnis/phpstan-rules: ~0.14.0
- ergebnis/test-util: ~0.9.0
- infection/infection: ~0.14.2
- jangregor/phpstan-prophecy: ~0.4.2
- localheinz/composer-normalize: ^1.3.1
- phpstan/extension-installer: ^1.0.3
- phpstan/phpstan: ~0.11.19
- phpstan/phpstan-deprecation-rules: ~0.11.2
- phpstan/phpstan-strict-rules: ~0.11.1
- phpunit/phpunit: ^8.4.3
Replaces
This package is auto-updated.
Last update: 2020-08-28 18:47:13 UTC
README
Provides an interface for, and an easy way to find and register entity definitions for league/factory-muffin
, inspired by ergebnis/factory-girl-definition
.
Installation
Run
$ composer require --dev ergebnis/factory-muffin-definition
Usage
Create Definitions
Implement the Definition
interface and use the instance of League\FactoryMuffin\FactoryMuffin
that is passed in into accept()
to define entities:
<?php namespace Foo\Bar\Test\Fixture\Entity; use Ergebnis\FactoryMuffin\Definition\Definition; use Foo\Bar\Entity; use League\FactoryMuffin\FactoryMuffin; final class UserDefinition implements Definition { public function accept(FactoryMuffin $factoryMuffin): void { $factoryMuffin->define(Entity\User::class)->setDefinitions([ // ... ]); } }
💡 Any number of entities can be defined within a definition. However, it's probably a good idea to create a definition for each entity.
Register Definitions
Lazily instantiate an instance of League\FactoryMuffin\FactoryMuffin
and use Definitions
to find definitions and register them with the factory:
<?php namespace Foo\Bar\Test\Integration; use Ergebnis\FactoryMuffin\Definition\Definitions; use League\FactoryMuffin\FactoryMuffin; use League\FactoryMuffin\Stores; use PHPUnit\Framework; abstract class AbstractIntegrationTestCase extends Framework\TestCase { final protected function factoryMuffin(): FactoryMuffin { static $factoryMuffin = null; if (null === $factoryMuffin) { $factoryMuffin = new FactoryMuffin(new Stores\ModelStore('save')); Definitions::in(__DIR__ . '/../Fixture')->registerWith($factoryMuffin); } return $factoryMuffin; } }
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
Curious what I am building?
📬 Subscribe to my list, and I will occasionally send you an email to let you know what I am working on.