InvalidConfigurationException KernelTestCase

时间:2016-09-07 10:21:28

标签: php symfony doctrine phpunit

我正在研究Symfony项目并使用Doctrine ORM。

我安装了PhpUnit进行单元测试。

我试着用这个来测试我的应用程序实体:

class ApplicationTest extends KernelTestCase
{
    /**
     * @var \Doctrine\ORM\EntityManager
     */
    private $em;

    private $application;

    /**
     * {@inheritDoc}
     */
    protected function setUp()
    {
        self::bootKernel();

        $this->em = static::$kernel->getContainer()
            ->get('doctrine')
            ->getManager();
    }

    public function testApplicationConstruct()
    {
        $this->application = new Application();

        $app = $this->em
            ->getRepository('CEPNPrincipalBundle:Applications')
            ->searchByRoute($this->application->getRoute());
        ;


        $this->assertEquals($app->getRoute(), $this->application->getRoute());
        $this->assertContains('app', $this->application->getRoute());
    }

    /**
     * {@inheritDoc}
     */
    protected function tearDown()
    {
        parent::tearDown();

        $this->em->close();
        $this->em = null; // avoid memory leaks
    }
}

运行

时出现此错误
bin/phpunit --configuration app/config/phpunit.xml.dist 
RuntimeException: Either set KERNEL_DIR in your phpunit.xml according to https://symfony.com/doc/current/book/testing.html#your-first-functional-test or override the WebTestCase::createKernel() method.

我用phpunit.xml.dist中的这一行修复了它:

<php>
    <server name="KERNEL_DIR" value="../../app" />
</php>

我又得到了一个错误:

Symfony\Component\Config\Definition\Exception\InvalidConfigurationException: You are not allowed to define new elements for path "security.firewalls". Please define all elements for this path in one config file

你能帮我吗?

0 个答案:

没有答案