I am looking at doctrine2 and how to handle data fixtures. I am especially interested in reading them from flat files (csv, yaml, xls).
In doctrine 1.2 data fixtures are handled like this: http://www.doctrine-project.org/projects/orm/1.2/docs/manual/data-fixtures/en#data-fixtures
Any suggestion how to handle this in doctrine2?
As already mentioned by Steven the fixture-feature comes as a separate repo. It took me some time to figure out how to install the data fixtures feature in Symfony2, so here is how I did it:
add sources to your deps file:
[doctrine-fixtures] git=http://github.com/doctrine/data-fixtures.git [DoctrineFixturesBundle] git=http://github.com/symfony/DoctrineFixturesBundle.git target=/bundles/Symfony/Bundle/DoctrineFixturesBundle
update your vendors
$ php bin/vendors install
register in in autoload.php:
$loader->registerNamespaces(array(
//...
'Doctrine\\Common\\DataFixtures' => __DIR__.'/../vendor/doctrine-fixtures/lib',
'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
//..
));
add class which subclasses FixtureInterface:
<?php
use Doctrine\ORM\EntityManager,
Doctrine\Common\DataFixtures\FixtureInterface;
/**
*
* setup of initial data for the unit- and functional tests
* @author stephan
*/
class LoadTestingData implements FixtureInterface{
/**
*
* @param EntityManager $manager
*/
public function load($manager) {
$user = new User();
$user->setUsername("testuser");
$manager->persist($user);
}
//...
load data fixtures via console command
./app/console doctrine:data:load
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With