Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Fixtures Laravel Package

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.

View on GitHub
Deep Wiki
Context7

davidbadura\fixtures

Build Status Latest Stable Version Total Downloads License

Features:

  • Use Services like fzaninotto/Faker, a PHP library that generates fake data for you
  • Resolve object dependency automatically (also bidirectional references)
  • Configurable default fixture converter (constructor, properties, set* and add* methods)
  • Easy to create your own converter
  • Many fixtures loader: Yaml, Json, Toml und PHP
  • Extendable by events (currently with symfony/event-dispatcher)
  • Fixture filtering by tags
  • Object validation (currently with symfony/validator over events)
  • Persist Fixtures with Doctrine ORM, Doctrine MongoDb or Propel
  • Easy to add your own Persister
  • Use an expression-language with symfony/expression-language

Todos:

  • Add cli functionality.
  • Translate documentation ( my english is really bad ;) )
  • Write documentation

Documentation

Installation

You can easily install this package over composer

composer require 'davidbadura/fixtures'

Useage

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky