/** * {@inheritdoc} */ public function generate(LoaderInterface $loader, FixturesLoaderInterface $fixturesLoader, array $bundles, $environment) { $doctrineDataLoaders = $this->fixturesFinder->getDataLoaders($bundles, $environment); $_fixturesLoader = clone $fixturesLoader; $_fixturesLoader->addProvider($doctrineDataLoaders); return new Loader($_fixturesLoader, $loader->getProcessors(), $loader->getPersistOnce()); }
/** * {@inheritdoc} */ public function generate(LoaderInterface $loader, FixturesLoaderInterface $fixturesLoader, array $bundles, $environment) { if (!$loader instanceof Loader) { throw new \UnexpectedValueException('Unsupported loader for this generator. Must be an instance of Hautelook\\AliceBundle\\Alice\\DataFixtures\\Loader.'); } $doctrineDataLoaders = $this->fixturesFinder->getDataLoaders($bundles, $environment); $_fixturesLoader = clone $fixturesLoader; $_fixturesLoader->addProvider($doctrineDataLoaders); return new Loader($_fixturesLoader, $loader->getProcessorChain(), $loader->getPersistOnce(), $loader->getLoadingLimit()); }
/** * @cover ::getDataLoaders * @dataProvider dataLoadersProvider */ public function testGetDataLoaders($bundles, $environment, $expected) { $finder = new FixturesFinder('DataFixtures/ORM'); $loaders = $finder->getDataLoaders($bundles, $environment); try { foreach ($loaders as $index => $loader) { $loaders[$index] = get_class($loader); } $this->assertCount(0, array_diff($expected, $loaders)); } catch (\InvalidArgumentException $exception) { if (0 !== count($expected)) { throw $exception; } } }
/** * {@inheritdoc} * * \RuntimeException Unsupported Application type */ protected function execute(InputInterface $input, OutputInterface $output) { if (false !== strpos($input->getFirstArgument(), 'hautelook_alice:fixtures:load') || false !== strpos($input->getFirstArgument(), 'h:f:l')) { $output->writeln('<comment>The use of "hautelook_alice:fixtures:load" command is deprecated since 1.0 and will be removed in 2.0. Use the "hautelook_alice:doctrine:fixtures:load" instead.</comment>'); } // Warn the user that the database will be purged // Ask him to confirm his choice if ($input->isInteractive() && !$input->getOption('append')) { if (false === $this->askConfirmation($input, $output, '<question>Careful, database will be purged. Do you want to continue y/N ?</question>', false)) { return; } } $manager = $this->doctrine->getManager($input->getOption('manager')); $environment = $input->getOption('env'); $bundles = $input->getOption('bundle'); /** @var Application $application */ $application = $this->getApplication(); if (false === $application instanceof Application) { throw new \RuntimeException('Expected Symfony\\Bundle\\FrameworkBundle\\Console\\Application application.'); } // Get bundles if (true === empty($bundles)) { $bundles = $application->getKernel()->getBundles(); } else { $bundles = $this->bundlesResolver->resolveBundles($application, $bundles); } $fixtures = $this->fixturesFinder->getFixtures($application->getKernel(), $bundles, $environment); $output->writeln(sprintf(' <comment>></comment> <info>%s</info>', 'fixtures found:')); foreach ($fixtures as $fixture) { $output->writeln(sprintf(' <comment>-</comment> <info>%s</info>', $fixture)); } $truncate = $input->hasOption('purge-with-truncate') ? $input->getOption('purge-with-truncate') : false; // Shard database $shard = $input->getOption('shard'); if (!empty($shard)) { $connection = $manager->getConnection(); if (!$connection instanceof PoolingShardConnection) { throw new \RuntimeException('Expected Doctrine\\DBAL\\Sharding\\PoolingShardConnection connection when using shard option.'); } // Switch to shard database $connection->connect($shard); } $this->fixturesExecutor->execute($manager, $this->loaderGenerator->generate($this->loader, $this->fixturesLoader, $bundles, $environment), $fixtures, $input->getOption('append'), function ($message) use($output) { $output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message)); }, $truncate); $output->writeln(sprintf(' <comment>></comment> <info>%s</info>', 'fixtures loaded')); }