コード例 #1
0
ファイル: FinderTest.php プロジェクト: Vowow/AliceBundle
 /**
  * @cover ::resolveBundles
  */
 public function testResolveBundles()
 {
     $finder = new Finder();
     $kernel = $this->prophesize('Symfony\\Component\\HttpKernel\\KernelInterface');
     $kernel->getBundles()->willReturn(['ABundle' => 'ABundleInstance', 'BBundle' => 'BBundleInstance', 'CBundle' => 'CBundleInstance']);
     $application = $this->prophesize('Symfony\\Bundle\\FrameworkBundle\\Console\\Application');
     $application->getKernel()->willReturn($kernel->reveal());
     $bundles = $finder->resolveBundles($application->reveal(), ['ABundle']);
     $this->assertEquals(['ABundle' => 'ABundleInstance'], $bundles);
     $bundles = $finder->resolveBundles($application->reveal(), ['ABundle', 'BBundle']);
     $this->assertEquals(['ABundle' => 'ABundleInstance', 'BBundle' => 'BBundleInstance'], $bundles);
     try {
         $finder->resolveBundles($application->reveal(), ['UnknownBundle']);
         $this->fail('Expected exception to be thrown');
     } catch (\RuntimeException $exception) {
         // Expected result
     }
     try {
         $finder->resolveBundles($application->reveal(), ['ABundle', 'UnknownBundle']);
         $this->fail('Expected exception to be thrown');
     } catch (\RuntimeException $exception) {
         // Expected result
     }
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  *
  * \RuntimeException Unsupported Application type
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var Application $application */
     $application = $this->getApplication();
     if (false === $application instanceof Application) {
         throw new \RuntimeException('Expected Symfony\\Bundle\\FrameworkBundle\\Console\\Application application.');
     }
     $environment = $input->getOption('env');
     $manager = $this->doctrine->getManager($input->getOption('manager'));
     // 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;
         }
     }
     // Get bundles
     $bundles = $input->getOption('bundle');
     if (true === empty($bundles)) {
         $bundles = $application->getKernel()->getBundles();
     } else {
         $bundles = $this->finder->resolveBundles($application, $bundles);
     }
     // Get fixtures
     $fixtures = $this->finder->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));
     }
     // Get data loaders to generate the new loader
     // Have to create a new one to add each data loader as a provider
     $loaders = $this->finder->getDataLoaders($bundles, $environment);
     $newLoader = new Loader(new ProcessorChain($this->loader->getProcessors()), new ProviderChain(array_merge($this->loader->getOptions()['providers'], $loaders)), $this->loader->getOptions()['locale'], $this->loader->getOptions()['seed'], $this->loader->getOptions()['persist_once'], true === isset($this->loader->getOptions()['logger']) ? $this->loader->getOptions()['logger'] : null);
     // Get executor
     $purger = new ORMPurger($manager);
     $purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     $executor = new ORMExecutor($manager, $newLoader, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     // Purge database and load fixtures
     $executor->execute($fixtures, $input->getOption('append'));
     $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', 'fixtures loaded'));
 }