ewgo/doctrine-fixtures-module

There is no license information available for the latest version (dev-master) of this package.

Zend Framework 2 integration with the Doctrine Fixtures library

Installs: 4 830

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 4

Forks: 3

Open Issues: 0

Type:zf2-module

dev-master 2013-07-26 16:48 UTC

This package is not auto-updated.

Last update: 2024-12-17 04:57:09 UTC


README

About

The EwgoDoctrineFixtures module provides ZF2 integration with the Doctrine Fixtures library.

Installation

$ php composer.phar require ewgo/doctrine-fixtures-module

Add "EwgoDoctrineFixtures" to the list of loaded modules.

Configuration

Add the paths to the fixtures in your modules configuration

array(
    'doctrinefixtures' => array(
        'paths' => array(
            'MyModule' => __DIR__ . '/../src/MyModule/DataFixtures/ORM'
        )
    )
)

Usage

Create your fixture classes.
You can implement Zend\ServiceManager\ServiceLocatorAwareInterface in order to use the ServiceManager in your fixture class.
You can also directly extend EwgoDoctrineFixtures\Fixture\ServiceLocatorAwareAbstractFixture in order to get the benefits of both ServiceLocatorAwareInterface and AbstractFixture.

namespace MyModule\DataFixtures\ORM;

use EwgoDoctrineFixtures\Fixture\ServiceLocatorAwareAbstractFixture;
use Doctrine\Common\Persistence\ObjectManager;
use MyModule\Entity\User;

class LoadUserData extends ServiceLocatorAwareAbstractFixture
{
    public function load(ObjectManager $manager)
    {
        // Encode the password any way you want
        $password = $this->serviceLocator->get('MySuperEncoder')->encode('myAwesomePassword');

        $user = new User();
        $user->setUsername('test');
        $user->setPassword($password);
        $user->setPassword('test@test.com');

        $manager->persist($user);
        $manager->flush();
    }
}
$ vendor/bin/doctrine-module fixtures:load

See the help (--help) for options.

For more information see the Doctrine Fixtures documentation.