本文整理汇总了PHP中Doctrine\Common\DataFixtures\Loader::addFixture方法的典型用法代码示例。如果您正苦于以下问题:PHP Loader::addFixture方法的具体用法?PHP Loader::addFixture怎么用?PHP Loader::addFixture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\DataFixtures\Loader
的用法示例。
在下文中一共展示了Loader::addFixture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
parent::setUp();
Artisan::call('doctrine:schema:create');
$this->em = App::make('Doctrine\\ORM\\EntityManagerInterface');
$this->repository = new PostDoctrineORMRepository($this->em);
$this->executor = new ORMExecutor($this->em, new ORMPurger());
$this->loader = new Loader();
$this->loader->addFixture(new PostFixtures());
}
示例2: testLoader
public function testLoader()
{
$loader = new Loader();
$loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\FixtureInterface'), array(), array(), 'Mock1');
$loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\FixtureInterface', array(), array(), 'Mock2'));
$loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\SharedFixtureInterface', array(), array(), 'Mock3'));
$this->assertEquals(3, count($loader->getFixtures()));
$loader->loadFromDirectory(__DIR__ . '/TestFixtures');
$this->assertEquals(7, count($loader->getFixtures()));
$this->assertTrue($loader->isTransient('TestFixtures\\NotAFixture'));
$this->assertFalse($loader->isTransient('TestFixtures\\MyFixture1'));
}
示例3: testLoader
public function testLoader()
{
$loader = new Loader();
$loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\FixtureInterface'));
$loader->addFixture($this->getMock('Doctrine\Common\DataFixtures\FixtureInterface'));
$this->assertEquals(2, count($loader->getFixtures()));
$loader->loadFromDirectory(__DIR__.'/TestFixtures');
$this->assertEquals(4, count($loader->getFixtures()));
$this->assertTrue($loader->isTransient('TestFixtures\NotAFixture'));
$this->assertFalse($loader->isTransient('TestFixtures\MyFixture1'));
}
示例4: testFixtureOrder
public function testFixtureOrder()
{
$loader = new Loader();
$loader->addFixture(new OrderedFixture1());
$loader->addFixture(new OrderedFixture2());
$loader->addFixture(new OrderedFixture3());
$loader->addFixture(new BaseFixture1());
$orderedFixtures = $loader->getFixtures();
$this->assertCount(4, $orderedFixtures);
$this->assertInstanceOf(__NAMESPACE__ . '\\BaseFixture1', $orderedFixtures[0]);
$this->assertInstanceOf(__NAMESPACE__ . '\\OrderedFixture2', $orderedFixtures[1]);
$this->assertInstanceOf(__NAMESPACE__ . '\\OrderedFixture1', $orderedFixtures[2]);
$this->assertInstanceOf(__NAMESPACE__ . '\\OrderedFixture3', $orderedFixtures[3]);
}
示例5: testFixtureOrder
public function testFixtureOrder()
{
$loader = new Loader();
$loader->addFixture(new OrderedFixture1());
$loader->addFixture(new OrderedFixture2());
$loader->addFixture(new OrderedFixture3());
$loader->addFixture(new BaseFixture1());
$orderedFixtures = $loader->getFixtures();
$this->assertEquals(4, count($orderedFixtures));
$this->assertTrue($orderedFixtures[0] instanceof BaseFixture1);
$this->assertTrue($orderedFixtures[1] instanceof OrderedFixture2);
$this->assertTrue($orderedFixtures[2] instanceof OrderedFixture1);
$this->assertTrue($orderedFixtures[3] instanceof OrderedFixture3);
}
示例6: beforeScenario
/**
* @BeforeScenario
*/
public function beforeScenario()
{
$loader = new Loader();
$loader->addFixture(new \Stfalcon\Bundle\EventBundle\DataFixtures\ORM\LoadEventData());
$loader->addFixture(new \Stfalcon\Bundle\EventBundle\DataFixtures\ORM\LoadNewsData());
$loader->addFixture(new \Application\Bundle\UserBundle\DataFixtures\ORM\LoadUserData());
$this->em = $this->kernel->getContainer()->get('doctrine.orm.entity_manager');
$this->em->getConnection()->executeUpdate("SET foreign_key_checks = 0;");
$purger = new ORMPurger();
$purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
$executor = new ORMExecutor($this->em, $purger);
$executor->purge();
$executor->execute($loader->getFixtures(), true);
$this->em->getConnection()->executeUpdate("SET foreign_key_checks = 1;");
}
示例7: setUp
public function setUp()
{
static::$kernel = static::createKernel();
static::$kernel->boot();
$this->application = new Application(static::$kernel);
// drop the database
$command = new DropDatabaseDoctrineCommand();
$this->application->add($command);
$input = new ArrayInput(['command' => 'doctrine:database:drop', '--force' => true]);
$command->run($input, new NullOutput());
// we have to close the connection after dropping the database so we don't get "No database selected" error
$connection = $this->application->getKernel()->getContainer()->get('doctrine')->getConnection();
if ($connection->isConnected()) {
$connection->close();
}
// create the database
$command = new CreateDatabaseDoctrineCommand();
$this->application->add($command);
$input = new ArrayInput(['command' => 'doctrine:database:create']);
$command->run($input, new NullOutput());
// create schema
$command = new CreateSchemaDoctrineCommand();
$this->application->add($command);
$input = new ArrayInput(['command' => 'doctrine:schema:create']);
$command->run($input, new NullOutput());
// get the Entity Manager
$this->em = static::$kernel->getContainer()->get('doctrine')->getManager();
// load fixtures
// not work
// $client = static::createClient();
// $loader = new ContainerAwareLoader($client->getContainer());
// $loader->loadFromDirectory(static::$kernel->locateResource('@Art\JobtestBundle\DataFixtures\ORM'));
//
// $purger = new ORMPurger($this->em);
// $executor = new ORMExecutor($this->em, $purger);
// $executor->execute($loader->getFixtures());
$loader = new Loader();
$loader->addFixture(new LoadCategoryData());
$loader->addFixture(new LoadJobData());
$loader->addFixture(new LoadAffiliateData());
$userFixture = new LoadUserData();
$userFixture->setContainer(static::$kernel->getContainer());
$loader->addFixture($userFixture);
$purger = new ORMPurger($this->em);
$executor = new ORMExecutor($this->em, $purger);
$executor->execute($loader->getFixtures());
parent::setUp();
}
示例8: testLoadFromFile
public function testLoadFromFile()
{
$loader = new Loader();
$loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock1')->getMock());
$loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock2')->getMock());
$loader->addFixture($this->getMockBuilder(SharedFixtureInterface::class)->setMockClassName('Mock3')->getMock());
$this->assertCount(3, $loader->getFixtures());
$loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php');
$this->assertCount(4, $loader->getFixtures());
$loader->loadFromFile(__DIR__ . '/TestFixtures/NotAFixture.php');
$this->assertCount(4, $loader->getFixtures());
$loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture2.php');
$this->assertCount(5, $loader->getFixtures());
$this->assertTrue($loader->isTransient('TestFixtures\\NotAFixture'));
$this->assertFalse($loader->isTransient('TestFixtures\\MyFixture1'));
}
示例9: addFixture
/**
* {@inheritdoc}
*/
public function addFixture(FixtureInterface $fixture)
{
if ($fixture instanceof ContainerAwareInterface) {
$fixture->setContainer($this->container);
}
parent::addFixture($fixture);
}
示例10: addFixture
public function addFixture(FixtureInterface $fixture)
{
if ($fixture instanceof ApplicationInterface) {
$fixture->setApp($this->app);
}
parent::addFixture($fixture);
}
示例11: testLoadFromFile
public function testLoadFromFile()
{
$loader = new Loader();
$loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\FixtureInterface'), array(), array(), 'Mock1');
$loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\FixtureInterface', array(), array(), 'Mock2'));
$loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\SharedFixtureInterface', array(), array(), 'Mock3'));
$this->assertCount(3, $loader->getFixtures());
$loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php');
$this->assertCount(4, $loader->getFixtures());
$loader->loadFromFile(__DIR__ . '/TestFixtures/NotAFixture.php');
$this->assertCount(4, $loader->getFixtures());
$loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture2.php');
$this->assertCount(5, $loader->getFixtures());
$this->assertTrue($loader->isTransient('TestFixtures\\NotAFixture'));
$this->assertFalse($loader->isTransient('TestFixtures\\MyFixture1'));
}
示例12: execute
/**
* Executes the current command.
*
* This method is not abstract because you can use this class
* as a concrete class. In this case, instead of defining the
* execute() method, you set the code to execute by passing
* a Closure to the setCode() method.
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return null|int null or 0 if everything went fine, or an error code
*
* @throws LogicException When this abstract method is not implemented
*
* @see setCode()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (empty($this->fixtures)) {
$output->writeln('No fixtures found.');
return -1;
}
$loader = new Loader();
foreach ($this->fixtures as $fixture) {
$loader->addFixture($fixture);
}
$purger = new ORMPurger($this->em);
$executor = new ORMExecutor($this->em, $purger);
$executor->setLogger(function ($message) use($output) {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
});
/** @var QuestionHelper $questionHelper */
$questionHelper = $this->getHelper('question');
$question = new ConfirmationQuestion('WARNING! Database will be purged before loading initialization data. Do you want to continue?', false);
if (!$questionHelper->ask($input, $output, $question)) {
$output->writeln('CMS initialization has been CANCELED!');
return;
}
try {
$executor->execute($loader->getFixtures());
$output->writeln('Basic CMS data has been SUCCESSFULLY loaded!');
return 0;
} catch (\Exception $e) {
$output->writeLn("That's bad. An Error occurred: <error>{$e->getMessage()}</error>");
return -1;
}
}
示例13: addFixture
/**
* Add a fixture object instance to the loader.
*
* @param FixtureInterface $fixture
*/
public function addFixture(FixtureInterface $fixture)
{
if ($fixture instanceof ServiceLocatorAwareInterface) {
$fixture->setServiceLocator($this->serviceLocator);
}
parent::addFixture($fixture);
}
示例14: loadWholeFixtures
private function loadWholeFixtures()
{
$loader = new Loader();
$loader->addFixture(new LoadItems());
$purger = new ORMPurger($this->getEntityManager());
$executor = new ORMExecutor($this->getEntityManager(), $purger);
$executor->execute($loader->getFixtures());
}
示例15: loadFixture
/**
* Load the given fixture
*
* @param \Doctrine\Common\DataFixtures\FixtureInterface $fixture
*/
protected function loadFixture(FixtureInterface $fixture)
{
$loader = new Loader();
$loader->addFixture($fixture);
$purger = new ORMPurger();
$executor = new ORMExecutor(static::$em, $purger);
$executor->execute($loader->getFixtures());
}