Add a fixture object instance to the loader.
public addFixture ( Doctrine\Common\DataFixtures\FixtureInterface $fixture ) | ||
$fixture | Doctrine\Common\DataFixtures\FixtureInterface |
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()); }
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')); }
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')); }
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]); }
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); }
/** * @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;"); }
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(); }
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')); }
/** * {@inheritdoc} */ public function addFixture(FixtureInterface $fixture) { if ($fixture instanceof ContainerAwareInterface) { $fixture->setContainer($this->container); } parent::addFixture($fixture); }
public function addFixture(FixtureInterface $fixture) { if ($fixture instanceof ApplicationInterface) { $fixture->setApp($this->app); } parent::addFixture($fixture); }
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')); }
/** * 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; } }
/** * 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); }
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()); }
/** * 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()); }
private function loadFixtures() { $loader = new Loader(); $loader->addFixture(new LoadAchievementData()); $purger = new ORMPurger(); $executor = new ORMExecutor($this->manager, $purger); $executor->execute($loader->getFixtures()); }
protected function loadFixtures() { $loader = new Loader(); $loader->addFixture(new DataFixtures()); $purger = new ORMPurger(); $executor = new ORMExecutor($this->app['orm.em'], $purger); $executor->execute($loader->getFixtures()); }
/** @before */ public function doLoadFixtures() { $loader = new Loader(); foreach ($this->loadFixtures() as $fixture) { $loader->addFixture($fixture); } $purger = new ORMPurger(); $executor = new ORMExecutor($this->em, $purger); $executor->execute($loader->getFixtures()); }
/** * @param BaseFixtureInterface $fixture */ public function addFixture(BaseFixtureInterface $fixture) { if (!$fixture instanceof FixtureInterface || $this->hasFixture($fixture)) { return; } $fixture->setContainer($this->getContainer()); $searchPaths = FixturePaths::create()->cartesianProductFromPaths([$this->container->getParameter('kernel.root_dir')], ...$this->container->getParameter('s.arthur_doctrine_fixtures.fixture_search_parts')); $fixture->loadFixtureMetadata($searchPaths); parent::addFixture($fixture); }
/** * @BeforeScenario */ public function beforeScen() { $loader = new Loader(); $loader->addFixture(new \Stfalcon\Bundle\EventBundle\DataFixtures\ORM\LoadEventData()); $loader->addFixture(new \Stfalcon\Bundle\EventBundle\DataFixtures\ORM\LoadNewsData()); $em = $this->kernel->getContainer()->get('doctrine.orm.entity_manager'); /** @var $em \Doctrine\ORM\EntityManager */ $connection = $em->getConnection(); $connection->beginTransaction(); $connection->query('SET FOREIGN_KEY_CHECKS=0'); $connection->commit(); $purger = new ORMPurger(); $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE); $executor = new ORMExecutor($em, $purger); $executor->purge(); $connection->beginTransaction(); $connection->query('SET FOREIGN_KEY_CHECKS=1'); $connection->commit(); $executor->execute($loader->getFixtures(), true); }
public function setUp() { parent::setUp(); $this->createDb(); $loader = new FixtureLoader(); $loader->addFixture(new TestFixture()); $purger = new ORMPurger(); $executor = new ORMExecutor($this->getEntityManager(), $purger); $executor->execute($loader->getFixtures()); $this->hydrator = new DoctrineEntityHydrator($this->getEntityManager()); }
/** * @BeforeScenario */ public function purgeDatabase(BeforeScenarioScope $scope) { $loader = new Loader(); $loader->addFixture(new \Application\Bundle\CoreBundle\DataFixtures\ORM\LoadSolutionData()); $loader->addFixture(new \Application\Bundle\CoreBundle\DataFixtures\ORM\LoadTaskData()); $entityManager = $this->getService('doctrine.orm.entity_manager'); /** @var $em \Doctrine\ORM\EntityManager */ $connection = $entityManager->getConnection(); $connection->beginTransaction(); $connection->query('SET FOREIGN_KEY_CHECKS=0'); $connection->commit(); $purger = new ORMPurger($entityManager); $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE); $executor = new ORMExecutor($entityManager, $purger); $executor->purge(); $connection->beginTransaction(); $connection->query('SET FOREIGN_KEY_CHECKS=1'); $connection->commit(); $executor->execute($loader->getFixtures(), true); }
/** * Загружаем необходимые фикстуры перед выполнением сценария * * @BeforeScenario */ public function beforeScen() { $loader = new Loader(); $loader->addFixture(new \Application\Bundle\UserBundle\DataFixtures\ORM\LoadUserData()); /** @var $em \Doctrine\ORM\EntityManager */ $em = $this->kernel->getContainer()->get('doctrine')->getManager(); $purger = new ORMPurger(); $executor = new ORMExecutor($em, $purger); $executor->purge(); $executor->execute($loader->getFixtures()); }
public function setUp() { parent::setUp(); $this->createDb(); $loader = new FixtureLoader(); $loader->addFixture(new TestFixture()); $purger = new ORMPurger(); $executor = new ORMExecutor($this->getEntityManager(), $purger); $executor->execute($loader->getFixtures()); $this->element = new DoctrineEntityElement('foo', array('object_manager' => $this->getEntityManager(), 'target_class' => 'DoctrineORMModuleTest\\Assets\\Entity\\Test')); }
/** @AfterScenario */ public function purgeTestDatabase() { // Purge tables $purger = new ORMPurger($this->em); $executor = new ORMExecutor($this->em, $purger); $executor->purge(); // Load standard fixtures $userFixtures = new LoadUsers(); $loader = new Loader(); $loader->addFixture($userFixtures); $executor->execute($loader->getFixtures()); }
/** * @throws \Doctrine\DBAL\DBALException * @throws \Doctrine\ORM\ORMException * @throws \Doctrine\ORM\Tools\ToolsException * @author Andreas Glaser */ protected function setUp() { $conn = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'dbname' => ':memory:', 'memory' => true]); $config = ORM\Tools\Setup::createAnnotationMetadataConfiguration([__DIR__ . '/../Entity'], true, null, null, false); $this->em = EntityManager::create($conn, $config); $schemaTools = new ORM\Tools\SchemaTool($this->em); $schemaTools->createSchema($this->em->getMetadataFactory()->getAllMetadata()); $loader = new DataFixtures\Loader(); $loader->addFixture(new Fixtures\ORM()); $executor = new DataFixtures\Executor\ORMExecutor($this->em, new DataFixtures\Purger\ORMPurger()); $executor->execute($loader->getFixtures()); }
/** * {@inheritDoc} */ public function setUp() { self::bootKernel(); $this->em = static::$kernel->getContainer()->get('doctrine')->getManager(); // loading Address fixtures // https://github.com/doctrine/data-fixtures $loader = new Loader(); $loader->addFixture(new LoadAddressData()); $purger = new ORMPurger(); $executor = new ORMExecutor($this->em, $purger); $executor->execute($loader->getFixtures()); }
protected function execute(InputInterface $input, OutputInterface $output) { $fixtures = $this->getFixtures($input); $loader = new Loader(); foreach ($fixtures as $fixture) { $loader->addFixture(new $fixture()); } $purger = new ORMPurger(); /** @var $em \Doctrine\ORM\EntityManager */ $em = $this->getContainer()->get('doctrine.orm.entity_manager'); $executor = new ORMExecutor($em, $purger); $executor->execute($loader->getFixtures()); }
public function setUp() { parent::setUp(); $this->createDb(); $loader = new FixtureLoader(); $loader->addFixture(new TestFixture()); $purger = new ORMPurger(); $executor = new ORMExecutor($this->getEntityManager(), $purger); $executor->execute($loader->getFixtures()); $this->qb = $this->getEntityManager()->createQueryBuilder()->select('t')->from('DoctrineORMModuleTest\\Assets\\Entity\\Test', 't')->orderBy('t.id', 'ASC'); $this->paginator = new DoctrinePaginator($this->qb); $this->paginatorAdapter = new PaginatorAdapter($this->paginator); }
/** * Append a certain fixture * * @param AbstractFixture $fixture * @param array $options (default: []) * @return void */ protected static function appendFixture(AbstractFixture $fixture, array $options = []) { $em = static::getClient(isset($options['new_client']) ? $options['new_client'] : false)->getContainer()->get('doctrine')->getManager(); $loader = new Loader(); $loader->addFixture($fixture); if (isset($options['purge']) && $options['purge']) { $purger = new ORMPurger($em); $executor = new ORMExecutor($em, $purger); $executor->execute($loader->getFixtures(), false); } else { $executor = new ORMExecutor($em); $executor->execute($loader->getFixtures(), true); } }