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.
Read our contribution guidelines and create an issue or a pull request.
composer require family-office/fixtures-library
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
}
}
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()]);
A full example of this can be found here.
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.
This project is licensed under the MIT license. Feel free to do whatever you want with the code!