dev-master
9999999-devProvide solution to process simple fixtures
MIT
The Requires
by Johann Saunier
fixtures easy simple tool doctrine fixtures
Provide solution to process simple fixtures
This project is currently in development, so please take care., (*2)
Create fixture can be painful mainly when you write them for little entity.You would create them faster as possible and with specific values., (*3)
Here an example from doctrine-data-fixture., (*4)
namespace MyDataFixtures; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\Persistence\ObjectManager; class LoadUserRoleData extends AbstractFixture { public function load(ObjectManager $manager) { $adminRole = new Role(); $adminRole->setName('admin'); $anonymousRole = new Role; $anonymousRole->setName('anonymous'); $manager->persist($adminRole); $manager->persist($anonymousRole); $manager->flush(); // store reference to admin role for User relation to Role $this->addReference('admin-role', $adminRole); } }
If you hate store data in php array and dont want take time to create a dedicated component, it's for you. Store their in YAML file and fetch easily your data !, (*5)
namespace MyDataFixtures; use Doctrine\Common\DataFixtures\AbstractFixture; use Doctrine\Common\Persistence\ObjectManager; class LoadUserRoleData extends AbstractFixture { public function load(ObjectManager $manager) { //Instanciate the fixture component with the path of folder who contains our YAML data fixture //File are retrieve via Symfony Finder Component, so your do path/*/*/folder and all think who is //interpreted by the finder $fixture = new Fixture('path/to/my/fixture/folder', $this); //If you want split / order your fixture you can also add dynamically some folder $this->fixture->addDirectory('path/to/my/fixture/another_folder'); //Now load your specific file $fixture->load('myDataFixture.yml'); //And now you can fetch your data foreach($this->fixture->fetch() as $data){ //attach to your entity with PropertyAccess or by the hand. } } }
Here an example of YAML data :, (*6)
database: name: - 'fr' - 'en' - 'it' - 'es' locale: - 'fr_FR' - 'en_US' - 'it_IT' - 'es_ES' status: - 'active' - 'active' - 'active' - 'inactive' default: - true
collection: scope: [ "roles" ] database: username: - 'alice' - 'bob' - 'peter' roles: #this is a one to Many - 'client' - 'editor' - 'admin'
database: user: - &alice
Actually this component not cover all features you can meet. You can't create reference from YAML, and collection are not fully supported, currently they just convert array into ArrayCollection because we dont have meet this use case at this time, but it's we will, so we plan., (*7)
[] Generate reference directly from YAML [] Fully support for Collection, (*8)
public function load(ObjectManager $manager) { $fixture = new Fixture('src/*/*/DataFixtures/YML/'); $this->localeManager = $this->container->get('gos.i18n_bundle.locale_entity.manager'); $this->fixture->load('LocaleData.yml', $this); foreach ($this->fixture->fetch() as $data) { $locale = $this->localeManager->create($data); $this->setReference($locale->getName(), $locale); } $this->localeManager->save(); }
PHPUnit 3.5 or newer together with Mock_Object package is required. To setup and run tests follow these steps:, (*9)
The project is under MIT lisence, for more information see the LICENSE file inside the project, (*10)
Provide solution to process simple fixtures
MIT
fixtures easy simple tool doctrine fixtures