问题
what I try to accomplish is: Loading fresh fixtures in PHP code before a WebTestCase is executed. As far as i know this code should do its work:
// Get a kernel instance and boot it up!
static::$kernel = static::createKernel();
static::$kernel->boot();
// Get entity manager
$em = static::$kernel->getContainer()->get('doctrine_phpcr.odm.default_document_manager');
$loader = new Loader();
foreach (self::$fixturesRequired as $fixtureClass) {
$loader->addFixture(new $fixtureClass);
}
$purger = new ORMPurger($em);
$executor = new ORMExecutor($em, $purger);
$executor->execute($loader->getFixtures());
... but it fails with:
AnnounceControllerTest::testAnnounce
Argument 1 passed to Doctrine\Common\DataFixtures\Purger\ORMPurger::__construct() must be an instance of Doctrine\ORM\EntityManagerInterface, instance of Doctrine\ODM\PHPCR\DocumentManager given, called in /opt/development/cms/.../WebTestCase.php
So does anyone know what I'm missing?
Thanks a lot in advance :)
回答1:
Solution to purge and load new fixtures for PHPCR:
// Get a kernel instance and boot it up!
static::$kernel = static::createKernel();
static::$kernel->boot();
// Get entity manager
$em = static::$kernel->getContainer()->get('doctrine_phpcr.odm.default_document_manager');
$loader = new Loader();
foreach (self::$fixturesRequired as $fixtureClass) {
$loader->addFixture(new $fixtureClass);
}
$purger = new PHPCRPurger($em);
$executor = new PHPCRExecutor($em, $purger);
$executor->execute($loader->getFixtures());
Thanks for the help!
来源:https://stackoverflow.com/questions/31969281/how-to-use-fixtures-in-webtestcase-phpunit