protected function execute(InputInterface $input, OutputInterface $output) { $registry = $this->getContainer()->get('doctrine_phpcr'); $dm = $registry->getManager($input->getOption('name')); $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/PHPCR'; } } $loader = new ContainerAwareLoader($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 PHPCRPurger($dm); $executor = new PHPCRExecutor($dm, $purger); $executor->setLogger(function ($message) use($output) { $output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message)); }); $executor->execute($fixtures, $input->getOption('append')); }
public function purge() { parent::purge(); if ($this->initializerManager) { $this->initializerManager->setLoggingClosure($this->logger); $this->initializerManager->initialize(); } }
public function testFailedTransactionalStopsPurgingAndFixtureLoading() { $dm = $this->getDocumentManager(); $purger = $this->getPurger(); $executor = new PHPCRExecutor($dm, $purger); $fixture = $this->getMockFixture(); $exception = new Exception(); $fixture->expects($this->never())->method('load'); $dm->expects($this->once())->method('transactional')->will($this->throwException($exception)); $purger->expects($this->never())->method('purge'); try { $executor->execute(array($fixture), true); } catch (\Exception $caughtException) { $this->assertSame($exception, $caughtException); } }
/** * Construct new fixtures loader instance. * * @param DocumentManager $manager DocumentManager instance used for persistence. * @param LoaderInterface $loader * @param PHPCRPurger $purger */ public function __construct(DocumentManager $manager, LoaderInterface $loader, PHPCRPurger $purger = null) { parent::__construct($manager, $purger); $this->loader = $loader; }