loadFromFile() публичный Метод

Find fixtures classes in a given file and load them.
public loadFromFile ( string $fileName ) : array
$fileName string File to find fixture classes in.
Результат array $fixtures Array of loaded fixture object instances.
Пример #1
0
 public function testLoadFromFile()
 {
     $loader = new Loader();
     $loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\FixtureInterface'), array(), array(), 'Mock1');
     $loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\FixtureInterface', array(), array(), 'Mock2'));
     $loader->addFixture($this->getMock('Doctrine\\Common\\DataFixtures\\SharedFixtureInterface', array(), array(), 'Mock3'));
     $this->assertCount(3, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php');
     $this->assertCount(4, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/NotAFixture.php');
     $this->assertCount(4, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture2.php');
     $this->assertCount(5, $loader->getFixtures());
     $this->assertTrue($loader->isTransient('TestFixtures\\NotAFixture'));
     $this->assertFalse($loader->isTransient('TestFixtures\\MyFixture1'));
 }
Пример #2
0
 public function testGetFixture()
 {
     $loader = new Loader();
     $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php');
     $fixture = $loader->getFixture(MyFixture1::class);
     $this->assertInstanceOf(MyFixture1::class, $fixture);
 }
Пример #3
0
 /**
  * Napolni podatke iz Fixtures
  */
 public function populateTestAction()
 {
     $logger = function ($message) {
         echo $message . PHP_EOL;
     };
     $em = $this->serviceLocator->get("\\Doctrine\\ORM\\EntityManager");
     $config = new Config($this->serviceLocator->get('config'));
     $loader = new Loader();
     $fixtures = isset($config->test_fixtures) ? $config->test_fixtures : [];
     $fixturename = $this->params('fixturename');
     if (!empty($fixturename)) {
         foreach ($fixtures as $dir) {
             $loader->loadFromFile($dir . '/' . $fixturename . 'Fixture.php');
             /**
              * če je dependent naj ne izvede nobenega
              */
             if (count($loader->getFixtures()) > 1) {
                 throw new \InvalidArgumentException('Loadanih več fixtur-jev -verjetno zaradi dependencies. Kot parameter možen le fixture brez odvisnosti.');
             }
         }
     } else {
         foreach ($fixtures as $dir) {
             $loader->loadFromDirectory($dir);
         }
     }
     $executor = new ORMExecutor($em);
     $executor->setLogger($logger);
     $executor->execute($loader->getFixtures(), true);
 }
Пример #4
0
 public function testLoadFromFile()
 {
     $loader = new Loader();
     $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock1')->getMock());
     $loader->addFixture($this->getMockBuilder(FixtureInterface::class)->setMockClassName('Mock2')->getMock());
     $loader->addFixture($this->getMockBuilder(SharedFixtureInterface::class)->setMockClassName('Mock3')->getMock());
     $this->assertCount(3, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php');
     $this->assertCount(4, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/NotAFixture.php');
     $this->assertCount(4, $loader->getFixtures());
     $loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture2.php');
     $this->assertCount(5, $loader->getFixtures());
     $this->assertTrue($loader->isTransient('TestFixtures\\NotAFixture'));
     $this->assertFalse($loader->isTransient('TestFixtures\\MyFixture1'));
 }
 protected function tearDown()
 {
     $loader = new Loader();
     $loader->loadFromFile('src/PadelTFG/GeneralBundle/DataFixtures/ORM/SponsorTest/SponsorTestRemove.php');
     $purger = new ORMPurger();
     $executor = new ORMExecutor($this->em, $purger);
     $executor->execute($loader->getFixtures(), true);
     $this->em->close();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getHelper('em')->getEntityManager();
     if ($input->isInteractive() && !$input->getOption('append')) {
         if (!$this->askConfirmation($input, $output, '<question>Careful, database will be purged. Do you want to continue y/N ?</question>', false)) {
             return;
         }
     }
     if ($input->getOption('shard')) {
         if (!$em->getConnection() instanceof PoolingShardConnection) {
             throw new LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $input->getOption('em')));
         }
         $em->getConnection()->connect($input->getOption('shard'));
     }
     $dirOrFile = $input->getOption('fixtures');
     if ($dirOrFile) {
         $paths = is_array($dirOrFile) ? $dirOrFile : array($dirOrFile);
     } else {
         $paths = $this->paths;
     }
     $loader = new DataFixturesLoader();
     foreach ($paths as $path) {
         if (is_dir($path)) {
             $loader->loadFromDirectory($path);
         } elseif (is_file($path)) {
             $loader->loadFromFile($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'), $input->getOption('multiple-transactions'));
 }