Code Monkey home page Code Monkey logo

alicedatafixtures's Introduction

AliceDataFixtures

Alice 3.x no longer ships with a persistence layer, so this library provides one!

Package version Build Status Slack license

Documentation

  1. Installation
    1. Symfony Bundle
      1. Doctrine ORM
      2. Eloquent ORM
      3. Configuration
  2. Basic usage
  3. Advanced usage
    1. Processors
    2. Purge data
  4. Contributing

Installation

You can use Composer to install the library to your project:

composer require --dev "theofidry/alice-data-fixtures:^1.0@beta" "nelmio/alice:^3.0@beta"

# with Doctrine
composer require --dev "theofidry/alice-data-fixtures:^1.0@beta" \
  doctrine/orm:^2.5 \
  doctrine/data-fixtures

# with Eloquent
composer require --dev "theofidry/alice-data-fixtures:^1.0@beta" \
  illuminate/database:~5.3.0

Symfony

This library ships with a Symfony bundle FidryAliceDataFixturesBundle.

Doctrine ORM

To use it with Doctrine do not forget to install doctrine/doctrine-bundle and enable the DoctrineBundle (done by default in Symfony Standard Edition).

Then, enable the bundle by updating your app/AppKernel.php file to enable the bundle:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        // ...
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
    ];

    if (in_array($this->getEnvironment(), ['dev', 'test'])) {
        //...
        $bundles[] = new Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle();
        $bundles[] = new Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle();
    }

    return $bundles;
}

Eloquent ORM

To use it with Eloquent do not forget to install illuminate/database and WouterJEloquentBundle (wouterj/eloquent-bundle).

Then, enable the bundle by updating your app/AppKernel.php file to enable the bundle:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        // ...
        new WouterJ\EloquentBundle\WouterJEloquentBundle(),
    ];

    if (in_array($this->getEnvironment(), ['dev', 'test'])) {
        //...
        $bundles[] = new Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle();
        $bundles[] = new Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle();
    }

    //...
    if (in_array($this->getEnvironment(), ['dev', 'test'])) {
        //...
        $bundles[] = new Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle();
    }

    return $bundles;
}

Configuration

The full configuration reference is:

# app/config/config.yml

# Default config
fidry_alice_data_fixtures:
    db_drivers:
        doctrine_orm: ~
        doctrine_mongodb_odm: ~
        doctrine_phpcr_odm: ~
        eloquent_orm: ~

For each driver, is the appropriate bundle is detected, e.g. DoctrineORMBundle for Doctrine and WouterJEloquentBundle for Eloquent, the services related to those driver will be enabled. If you want to skip those checks you can turn a specific driver to true instead. If you want to disable a specific driver, simply force the value false instead.

Basic usage

Create a fixture file in src/AppBundle/Resources/fixtures:

# src/AppBundle/Resources/fixtures/dummy.yml

AppBundle\Entity\Dummy:
    dummy_{1..10}:
        name: <name()>
        related_dummy: '@related_dummy*'
# src/AppBundle/Resources/fixtures/related_dummy.yml

AppBundle\Entity\RelatedDummy:
    related_dummy_{1..10}:
        name: <name()>

Then you can load those files using a LoaderInterface:

$files = [
    'path/to/src/AppBundle/Resources/fixtures/dummy.yml',
    'path/to/src/AppBundle/Resources/fixtures/related_dummy.yml',
];

$loader = $container->get('fidry_alice_data_fixtures.doctrine.persister_loader'); // For Doctrine ORM
$loader = $container->get('fidry_alice_data_fixtures.doctrine_mongodb.persister_loader'); // For Doctrine MongoDB ODM
$loader = $container->get('fidry_alice_data_fixtures.doctrine_phpcr.persister_loader'); // For Doctrine PHPCR
$loader = $container->get('fidry_alice_data_fixtures.eloquent.persister_loader'); // For Eloquent ORM
$objects = $loader->load($files);

// $objects is now an array of persisted `Dummy` and `RelatedDummy`

Check more advanced doc.

Contributing

Clone the project, install the dependencies and use bin/test.sh to run all the tests!

alicedatafixtures's People

Contributors

alekitto avatar dunglas avatar robotzero avatar theofidry avatar

Watchers

 avatar

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.