dknx01/factory-muffin-backery

A backery for FactoryMuffin. For creating object by an alias including only setting the arguments during instantiating

dev-master 2017-03-26 10:22 UTC

This package is auto-updated.

Last update: 2022-01-15 01:51:49 UTC


README

FactoryMuffinBackery

A wrapper for Factory Muffin (https://github.com/thephpleague/factory-muffin)

Usage

The Muffin class

Dknx01\FactoryMuffinBackery\DVO\Muffin:

setObjectClass: setting the full qualified class name

setCreatorMethod: setting the create method: create, instance, seed

setArguments: setting the arguments for the objects

setSeedTimes: setting the number of object to be created

setMaker: setting a maker function

setCallback: setting a callback function

Example Class:

namespace dknx01\FactoryMuffinBackery\Test;

class TestStub
{

}

use Dknx01\FactoryMuffinBundle\DVO\Muffin;
use Dknx01\FactoryMuffinBundle\MuffinBackery;
use League\FactoryMuffin\FactoryMuffin;
use League\FactoryMuffin\Stores\ModelStore;

class TestFactory
{
    /**
     * @var MuffinBackery
     */
    private $backery;

    public function createObject()
    {
        $this->backery = new MuffinBackery();
        $this->backery->setFactoryMuffin(new FactoryMuffin(new ModelStore()));

        $muffin = new Muffin();
        $muffin->setObjectClass(TestStub::class)->setCreatorMethod('instance');
        $this->backery->addMuffin($muffin, 'myStub');
    }
    /**
    * @return MuffinBackery
     */
    public function getBackery(): MuffinBackery
    {
        return $this->backery;
    }
}

Test class

class DefaultControllerTest extends TestCase
{
    public function testIndex()
    {
        $factory = new TestFactory();
        $factory->createObject();
        var_dump($factory->getBackery()->load()->getByAlias('myStub'));
    }
}