Skip to content
👧 Provides an interface for, and an easy way to find and register entity definitions for league/factory-muffin.
PHP Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.dependabot
.github
src
test
.editorconfig
.gitattributes
.gitignore
.php_cs
CHANGELOG.md
LICENSE.md
Makefile
README.md
composer.json
composer.lock
infection.json
phpstan-baseline.neon
phpstan.neon
psalm-baseline.xml
psalm.xml

README.md

factory-muffin-definition

Continuous Deployment Continuous Integration

Code Coverage Type Coverage

Latest Stable Version Total Downloads

Inspired by ergebnis/factory-girl-definition, this provides an interface for, and an easy way to find and register entity definitions for league/factory-muffin.

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.

You can’t perform that action at this time.