本文整理汇总了PHP中Doctrine\Common\DataFixtures\Loader::loadFromFile方法的典型用法代码示例。如果您正苦于以下问题:PHP Loader::loadFromFile方法的具体用法?PHP Loader::loadFromFile怎么用?PHP Loader::loadFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\DataFixtures\Loader
的用法示例。
在下文中一共展示了Loader::loadFromFile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLoadFromFile
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: testGetFixture
public function testGetFixture()
{
$loader = new Loader();
$loader->loadFromFile(__DIR__ . '/TestFixtures/MyFixture1.php');
$fixture = $loader->getFixture(MyFixture1::class);
$this->assertInstanceOf(MyFixture1::class, $fixture);
}
示例3: populateTestAction
/**
* 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: testLoadFromFile
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'));
}
示例5: tearDown
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();
}
示例6: execute
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'));
}