2017 © Pedro Peláez
 

symfony-bundle fixture-bundle

FixtureBundle for Symfony2

image

funddy/fixture-bundle

FixtureBundle for Symfony2

  • Tuesday, July 2, 2013
  • by funddy
  • Repository
  • 2 Watchers
  • 3 Stars
  • 1,151 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

FunddyFixtureBundle

Build Status, (*1)

Fixtures bundle for Funddy fixture component., (*2)

Setup and Configuration

Add the following to your composer.json file:, (*3)

{
    "require": {
        "funddy/fixture-bundle": "2.0.*"
    }
}

Update the vendor libraries:, (*4)

curl -s http://getcomposer.org/installer | php
php composer.phar install

For finishing, register the Bundle FunddyFixtureBundle in app/AppKernel.php., (*5)

// ...
public function registerBundles()
{
    $bundles = array(
        // ...
        new Funddy\Bundle\FixtureBundle\FunddyFixtureBundle()
        // ...
    );
    // ...
}

Usage

Create your fixture definition, (*6)

<?php

namespace Acme\DemoBundle\Fixture;

use Acme\DemoBundle\Service\UserService;
use Funddy\Fixture\Fixture\Fixture;

class UserFixture extends Fixture
{
    private $userService;

    public function __construct(UserService $userService)
    {
        $this->userService = $userService;
    }

    public function load()
    {
        $user = $this->userService->create('keyvan@funddy.com', 'Keyvan Akbary');
        $this->addReference($user, 'user-keyvan');
    }

    public function getOrder() {
        return 0;
    }
}

Define your fixtures as services and inject dependencies, (*7)

services:
    acme.demobundle.fixture.userfixture:
        class: Acme\DemoBundle\Fixture\UserFixture
        arguments:
            - @acme.demobundle.service.userservice
        calls:
            - [ setFixtureLinker, [@funddy.component.fixture.fixturelinker] ]

Create a fixtures loader command, (*8)

namespace Acme\DemoBundle\Command;

use Funddy\Bundle\FixtureBundle\ConsoleFixtureLoader\ConsoleFixtureLoader;
use Funddy\Fixture\Fixture\FixtureLoader;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class FixturesLoadCommand extends ContainerAwareCommand
{
    private static $fixtureServiceNames = array(
        'acme.demobundle.fixture.userfixture'
    );

    protected function configure()
    {
        $this
            ->setName('acme:fixtures:load')
            ->setDescription('Load all fixtures');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $fixtureLoader = new ConsoleFixtureLoader(new FixtureLoader(), $output);
        $this->loadFixtureServicesIntoLoader($fixtureLoader);
        $fixtureLoader->loadAll();
    }

    private function loadFixtureServicesIntoLoader($fixtureLoader)
    {
        foreach (self::$fixtureServiceNames as $fixtureServiceName) {
            $fixtureLoader->addFixture($this->getContainer()->get($fixtureServiceName));
        }
    }
}

That's all, time to load your fixtures through your own command acme:fixtures:load., (*9)

The Versions

02/07 2013

dev-master

9999999-dev https://github.com/funddy/fixture-bundle

FixtureBundle for Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

fixture bundle

02/07 2013

v2.0.0

2.0.0.0 https://github.com/funddy/fixture-bundle

FixtureBundle for Symfony2

  Sources   Download

MIT

The Requires

 

The Development Requires

fixture bundle