kupishkis / doctrine-fixtures-module
Zend Framework 2 integration with the Doctrine Fixtures library
Package info
github.com/kupishkis/DoctrineFixturesModule
Type:zf2-module
pkg:composer/kupishkis/doctrine-fixtures-module
Requires
- php: ^7.1
- doctrine/data-fixtures: ^1.3.0
- doctrine/doctrine-module: ~0.7
- symfony/console: ^2.8 || ^3.0
- zendframework/zendframework: 2.*
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
About
The KupDoctrineFixtures module provides ZF2 integration with the Doctrine Fixtures library. Difference from EwgoDoctrineFixtures is that this module actually supports fixtures loading from single file.
Installation
$ php composer.phar require kupishkis/doctrine-fixtures-module
Add "KupDoctrineFixtures" 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 KupDoctrineFixtures\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.