protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dmName = $input->getOption('dm');
     $dmName = $dmName ? $dmName : 'default';
     $dmServiceName = sprintf('doctrine.odm.mongodb.%s_document_manager', $dmName);
     if (!$this->container->has($dmServiceName)) {
         throw new InvalidArgumentException(sprintf('Could not find a document manager configured with the name "%s". Check your ' . 'application configuration to configure your Doctrine document managers.', $dmName));
     }
     $dm = $this->container->get($dmServiceName);
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = array();
         foreach ($this->container->get('kernel')->getBundles() as $bundle) {
             $paths[] = $bundle->getPath() . '/DataFixtures/MongoDB';
         }
     }
     $loader = new DataFixturesLoader($this->container);
     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 MongoDBPurger($dm);
     $executor = new MongoDBExecutor($dm, $purger);
     $executor->setLogger(function ($message) use($output) {
         $output->writeln(sprintf('  <comment>></comment> <info>%s</info>', $message));
     });
     $executor->execute($fixtures, $input->getOption('append'));
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $emName = $input->getOption('em');
     $emName = $emName ? $emName : 'default';
     $emServiceName = sprintf('doctrine.orm.%s_entity_manager', $emName);
     $em = $this->container->get($emServiceName);
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = array();
         foreach ($this->application->getKernel()->getBundles() as $bundle) {
             $paths[] = $bundle->getPath() . '/DataFixtures/ORM';
         }
     }
     $loader = new DataFixturesLoader($this->container);
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         }
     }
     $fixtures = $loader->getFixtures();
     $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'));
 }
Пример #3
0
 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);
 }