正如 Steven 已经提到的,fixture-feature 是作为一个单独的 repo 提供的。
我花了一些时间才弄清楚如何在 Symfony2 中安装数据夹具功能,所以我是这样做的:
将来源添加到您的 deps 文件中:
[教义装置]
git=http://github.com/doctrine/data-fixtures.git
[DoctrineFixturesBundle]
git=http://github.com/symfony/DoctrineFixturesBundle.git
目标=/bundles/Symfony/Bundle/DoctrineFixturesBundle
更新您的供应商
$ php bin/vendors 安装
在 autoload.php 中注册:
$loader->registerNamespaces(array(
//...
'Doctrine\\Common\\DataFixtures' => __DIR__.'/../vendor/doctrine-fixtures/lib',
'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
//..
));
添加子类 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);
}
//...
通过控制台命令加载数据夹具
./app/console doctrine:data:load