protected function execute(InputInterface $input, OutputInterface $output)
 {
     $emName = $input->getOption('em');
     $emName = $emName ? $emName : 'default';
     $emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
     if (!$this->getContainer()->has($emServiceName)) {
         throw new InvalidArgumentException(sprintf('Could not find an entity manager configured with the name "%s". Check your ' . 'application configuration to configure your Doctrine entity managers.', $emName));
     }
     $em = $this->getContainer()->get($emServiceName);
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = array();
         foreach ($this->getApplication()->getKernel()->getBundles() as $bundle) {
             $paths[] = $bundle->getPath() . '/DataFixtures/ORM';
         }
     }
     $loader = new DataFixturesLoader($this->getContainer());
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         }
     }
     $fixtures = $loader->getFixtures();
     if (!$fixtures) {
         throw new InvalidArgumentException(sprintf('Could not find any fixtures to load in: %s', "\n\n- " . implode("\n- ", $paths)));
     }
     $purger = new ORMPurger($em);
     $executor = new ORMExecutor($em, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
 }
 public function testShouldSetContainerOnContainerAwareFixture()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $loader = new Loader($container);
     $fixture = new ContainerAwareFixture();
     $loader->addFixture($fixture);
     $this->assertSame($container, $fixture->container);
 }
 /**
  * Load a data fixture class.
  *
  * @param Loader $loader
  * @param string $className
  */
 protected function loadFixtureClass($loader, $className)
 {
     $fixture = new $className();
     if ($loader->hasFixture($fixture)) {
         unset($fixture);
         return;
     }
     $loader->addFixture($fixture);
     if ($fixture instanceof DependentFixtureInterface) {
         foreach ($fixture->getDependencies() as $dependency) {
             $this->loadFixtureClass($loader, $dependency);
         }
     }
 }