Skip to content

Latest commit

 

History

History
93 lines (72 loc) · 1.49 KB

symfony.md

File metadata and controls

93 lines (72 loc) · 1.49 KB

Symfony

  1. Installation

Add DavidBadura Fixtures in your composer.json

{
    "require": {
        "davidbadura/fixtures": "~1.0"
    }
}

Add the DavidBaduraFixturesBundle to your application kernel:

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new DavidBadura\Fixtures\Extension\Symfony\DavidBaduraFixturesBundle(),
        // ...
    );
}
  1. Configuration

Configure DavidBaduraFixturesBundle:

# app/config/config.yml
david_badura_fixtures:
  bundles: [AppBundle]

Activate support for MongoDB:

# app/config/config.yml
david_badura_fixtures:
  persister: odm
  1. Create fixtures

Now you should create your fixture data:

# @AppBundle/Resource/fixtures/install.yml
user:
    properties:
        class: "AppBundle\Entity\User"
    data:
        david:
            name: David
            email: "[email protected]"
            groups: ["@group:admin"] # <- reference to group.admin

group:
    properties:
        class: "AppBundle\Entity\Group"
    data:
        admin:
            name: Admin
        member:
            name: Member

The fixture files will be automatically loaded from the Resources\fixtures folder.

  1. Load fixtures

Command:

php app/console davidbadura:fixtures:load

Service:

$fixtureManager = $container->get('davidbadura_fixtures.fixture_manager');
$fixtureManager->load();