How to use fixtures in WebTestCase PHPUnit

六眼飞鱼酱① 提交于 2019-12-13 06:49:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!