Coder Social home page Coder Social logo

ergebnis / factory-muffin-definition Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 1.39 MB

:girl: Provides an interface for, and an easy way to find and register entity definitions for league/factory-muffin.

License: MIT License

PHP 85.70% Makefile 14.30%
factory-muffin factory-muffin-definition

factory-muffin-definition's Introduction

factory-muffin-definition

Integrate Prune Release Renew

Code Coverage Type Coverage

Latest Stable Version Total Downloads

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.

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.