本文介绍了如何在WebTestCase PHPUnit中使用fixture的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试完成的是:
在执行WebTestCase之前,在PHP代码中加载新鲜的灯具。据我所知,这段代码应该完成它的工作:

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());

...但是失败:

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?

提前感谢:)

推荐答案

解决方案清除并加载PHPCR的新灯具:

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());

感谢您的帮助!

这篇关于如何在WebTestCase PHPUnit中使用fixture的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 14:21