protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var $doctrine \Doctrine\Common\Persistence\ManagerRegistry */
     $doctrine = $this->getContainer()->get('doctrine');
     $em = $doctrine->getManager($input->getOption('em'));
     if ($input->isInteractive() && !$input->getOption('append')) {
         $dialog = $this->getHelperSet()->get('dialog');
         if (!$dialog->askConfirmation($output, '<question>Careful, database will be purged. Do you want to continue Y/N ?</question>', false)) {
             return;
         }
     }
     $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);
     $purger->setPurgeMode($input->getOption('purge-with-truncate') ? ORMPurger::PURGE_MODE_TRUNCATE : ORMPurger::PURGE_MODE_DELETE);
     $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'));
     // Serialize reference repository to a file. So fixtures will be accessible by names inside functional tests.
     $referenceRepositoryFile = $this->getContainer()->getParameter('fixtures.reference_repository_path');
     $serializedReferenceRepository = (new FixtureReferenceRepositorySerializer())->serialize($executor->getReferenceRepository());
     file_put_contents($referenceRepositoryFile, $serializedReferenceRepository);
     $output->writeln(sprintf('<info>Reference repository saved to:</info> <comment>%s</comment>', realpath($referenceRepositoryFile)));
 }
Ejemplo n.º 2
0
 public function testSharedFixtures()
 {
     if (!extension_loaded('pdo_sqlite')) {
         $this->markTestSkipped('Missing pdo_sqlite extension.');
     }
     $em = $this->getMockSqliteEntityManager();
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema(array($em->getClassMetadata(self::TEST_ENTITY_ROLE), $em->getClassMetadata(self::TEST_ENTITY_USER)));
     $purger = new ORMPurger();
     $executor = new ORMExecutor($em, $purger);
     $userFixture = new TestFixtures\UserFixture();
     $roleFixture = new TestFixtures\RoleFixture();
     $executor->execute(array($roleFixture, $userFixture), true);
     $referenceRepository = $executor->getReferenceRepository();
     $references = $referenceRepository->getReferences();
     $this->assertEquals(2, count($references));
     $roleReference = $referenceRepository->getReference('admin-role');
     $this->assertTrue($roleReference instanceof Role);
     $this->assertEquals('admin', $roleReference->getName());
     $userReference = $referenceRepository->getReference('admin');
     $this->assertTrue($userReference instanceof User);
     $this->assertEquals('*****@*****.**', $userReference->getEmail());
 }
Ejemplo n.º 3
0
 /**
  * @param array $classNames
  * @param bool  $force
  */
 protected function loadFixtures(array $classNames, $force = false)
 {
     if (!$force) {
         $classNames = array_filter($classNames, function ($value) {
             return !in_array($value, self::$loadedFixtures);
         });
         if (!$classNames) {
             return;
         }
     }
     self::$loadedFixtures = array_merge(self::$loadedFixtures, $classNames);
     $loader = $this->getFixtureLoader($classNames);
     $fixtures = array_values($loader->getFixtures());
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $executor = new ORMExecutor($em, new ORMPurger($em));
     $executor->execute($fixtures, true);
     self::$referenceRepository = $executor->getReferenceRepository();
     $this->postFixtureLoad();
 }
Ejemplo n.º 4
0
 public function get($reference)
 {
     $this->loadEntities();
     return $this->executor->getReferenceRepository()->getReference($reference);
 }