Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

♻️ An easy-to-use library for fixture and dependency loading.

License

Notifications You must be signed in to change notification settings

FamilyOfficeOrg/fixtures-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fixtures Library

An easy-to-use library for fixture and dependency loading.

⚠️ Disclaimer: This solution was developed for a very specific use-case. The best way to load fixtures in your use-case is most likely covered by Doctrines data fixtures.

❤️ Feel like contributing?

Read our contribution guidelines and create an issue or a pull request.

Installation

composer require family-office/fixtures-library

💡 Usage

Creating a fixture

Fixtures are regular classes implementing the FixtureInterface.

namespace FamilyOffice\FixturesLibrary\Example\Basic\Fixtures;

use FamilyOffice\FixturesLibrary\FixtureInterface;

final class EarFixture implements FixtureInterface
{
    public function getDependencies(): array
    {
        return [];
    }

    public function load(): void
    {
        // todo: implement data loading
    }
}

All code that should be executed within the fixture should live in the load method.

Sometimes, fixtures need to depend on each other because they must be executed in a certain order.

All dependencies a fixture is dependent on should be returned from the getDependencies method.

namespace FamilyOffice\FixturesLibrary\Example\Basic\Fixtures;

use FamilyOffice\FixturesLibrary\FixtureInterface;

final class ElephantFixture implements FixtureInterface
{
    public function getDependencies(): array
    {
        return [EarFixture::class];
    }

    public function load(): void
    {
        // todo: implement data loading
    }
}

Loading the Fixtures

The quickest and easiest way to load the fixtures is by creating a default chain builder instance.

$defaultChainBuilder = ChainBuilder::createQuickLoader();

The fixtures can then be easily loaded on-the-fly as the dependency tree is built.

$defaultChainBuilder->build([new ElephantFixture()]);

Full Example

A full example of this can be found here.

Advanced Usage

The dependency chain building and loading process can be fully customized to your needs.

An extended documentation on the advanced capabilities of this library can be found here.

📝 License

This project is licensed under the MIT license. Feel free to do whatever you want with the code!