davidbadura/fixtures
Flexible PHP fixtures library with YAML/JSON/TOML/PHP loaders, Faker support, automatic dependency resolution, configurable converters, tagging/filtering, validation via events, expression language, and persisters for Doctrine ORM/MongoDB and Propel.
Features:
Todos:
You can easily install this package over composer
composer require 'davidbadura/fixtures'
First, you must create fixtures files in yaml, json, toml, php or mixed. In this example, we have different formats:
YAML
user:
properties:
class: DavidBadura\Fixtures\TestObjects\User
constructor: [name, email]
data:
david:
name: "David Badura"
email: "d.badura@gmx.de"
group: ["@group:owner", "@group:developer"]
role: ["@role:admin"]
other:
name: "Somebody"
email: "test@example.de"
group: ["@group:developer"]
role: ["@role:user"]
PHP
<?php
return array(
'role' =>
array(
'properties' =>
array(
'class' => 'DavidBadura\\Fixtures\\TestObjects\\Role',
),
'data' =>
array(
'admin' =>
array(
'name' => 'Admin',
),
'user' =>
array(
'name' => 'User',
),
),
)
);
JSON
{
"group": {
"properties": {
"class": "DavidBadura\\Fixtures\\TestObjects\\Group"
},
"data": {
"developer": {
"name": "Developer",
"leader": "@@user:david"
}
}
}
}
You can reference to other objects with following expression @{fixture-name}:{fixture-key}. The references will resolved automatically.
What other formats are supported you can read under Loader.
How the fixture manager converte the fixtures to objects can you read in the Converter section. You can use the default fixture converter or write your own converter.
Load Fixtures
Now, you can load the fixtures, crate the objects and persist these in the database. For this, we use the default fixture manager.
use DavidBadura\Fixtures\FixtureManager\FixtureManager;
// $objectManager can be curently Doctrine ORM Entity Manager or other Doctrine DocumentManager like MongoODM or CouchODM
$fixtureManager = FixtureManager::createDefaultFixtureManager($objectManager);
$fixtureManager->load('path/to/fixtures');
You can easily instance your own fixture manager. For more information you can read FixtureManager documentation.
How can I help you explore Laravel packages today?