public function execute(InputInterface $input, OutputInterface $output) { $loader = new ServiceLocatorAwareLoader($this->serviceLocator); $purger = new ORMPurger(); if ($input->getOption('purge-with-truncate')) { $purger->setPurgeMode(self::PURGE_MODE_TRUNCATE); } $executor = new ORMExecutor($this->em, $purger); foreach ($this->paths as $key => $value) { $loader->loadFromDirectory($value); } $executor->execute($loader->getFixtures(), $input->getOption('append')); }
/** * Ensures that the Service Locator instance passed into the ServiceLocatorAwareLoader * actually makes it to the SL-aware fixtures loaded */ public function testLoadingFixtureWhichIsServiceLocatorAware() { $fixtureClassName = 'DoctrineDataFixtureTest\\TestAsset\\Fixtures\\HasSL\\FixtureA'; $serviceLocator = new ServiceManager(new ServiceManagerConfig()); $loader = new ServiceLocatorAwareLoader($serviceLocator); $loader->loadFromDirectory(__DIR__ . '/../TestAsset/Fixtures/HasSL'); $fixtures = $loader->getFixtures(); $this->assertArrayHasKey($fixtureClassName, $fixtures); $fixture = $fixtures[$fixtureClassName]; $this->assertInstanceOf('Doctrine\\Common\\DataFixtures\\FixtureInterface', $fixture); $this->assertInstanceOf('Zend\\ServiceManager\\ServiceLocatorAwareInterface', $fixture); $this->assertSame($serviceLocator, $fixture->getServiceLocator()); }
public function importAction() { $console = $this->getServiceLocator()->get('console'); // Make sure that we are running in a console and the user has not tricked our // application into running this action from a public web server. $request = $this->getRequest(); if (!$request instanceof ConsoleRequest) { throw new RuntimeException('You can only use this action from a console.'); } // Lodgable default fixtures $loader = new ServiceLocatorAwareLoader($this->getServiceLocator()); $purger = new ORMPurger(); $executor = new ORMExecutor($this->getAuditObjectManager(), $purger); $loader->loadFromDirectory(__DIR__ . '/../Fixture'); $executor->execute($loader->getFixtures(), true); $console->write("Audit data fixture import complete", Color::GREEN); }
public static function createDatabase(\Zend\Mvc\Application $application) { // build test database $entityManager = $application->getServiceManager()->get('doctrine.entitymanager.orm_default'); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager); $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata()); // build audit database $auditEntityManager = $application->getServiceManager()->get('doctrine.entitymanager.orm_zf_doctrine_audit'); $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($auditEntityManager); $schemaTool->createSchema($auditEntityManager->getMetadataFactory()->getAllMetadata()); // Run audit fixtures $loader = new ServiceLocatorAwareLoader($application->getServiceManager()); $purger = new ORMPurger(); $executor = new ORMExecutor($auditEntityManager, $purger); $loader->loadFromDirectory(__DIR__ . '/../src/Fixture'); $executor->execute($loader->getFixtures(), true); }