Git Product home page Git Product logo

fixtures's Introduction

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 (XML is coming soon)
  • 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 or Doctrine MongoDb (Propel is coming soon)
  • Easy to add your own Persister
  • Use an expression-language with symfony/expression-language

Todos:

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

Documentation

Installation

You can easily install this package over composer

{
    "require": {
        "davidbadura/fixtures": "1.0@beta"
    }
}

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: "[email protected]"
      group: ["@group:owner", "@group:developer"]
      role: ["@role:admin"]
    other:
      name: "Somebody"
      email: "[email protected]"
      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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.