错误:“在phpunit.xml中设置KERNEL_DIR”,但在phpunit.xml.dist中将KERNEL_DIR设置为“<server name =”KERNEL_DIR“value =”./“>”

时间:2016-05-28 09:13:50

标签: symfony phpunit

在尝试PHPUnit功能测试时,我得到了 错误:

1) TreningBundle\Tests\Controller\DefaultControllerTest::testIndex
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.

http://symfony.com/doc/2.8/book/testing.html说:

  

如果您的内核位于非标准目录中,则需要进行修改   你的phpunit.xml.dist

我在phpunit.xml.dist目录中的deafult Symfony(2.8)位置有AppKErnel.phpapp\文件。无论如何,我在app/phpunit.xml.dist中添加了以下行:

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

结果相同的错误。

已安装的软件包:

doctrine/annotations                 v1.2.7
doctrine/cache                       v1.6.0
doctrine/collections                 v1.3.0
doctrine/common                      v2.6.1
doctrine/dbal                        v2.5.4
doctrine/doctrine-bundle             1.6.2
doctrine/doctrine-cache-bundle       1.3.0
doctrine/inflector                   v1.1.0
doctrine/instantiator                1.0.5
doctrine/lexer                       v1.0.1
doctrine/orm                         v2.5.4
incenteev/composer-parameter-handler v2.1.2
ircmaxell/password-compat            v1.0.4
jdorn/sql-formatter                  v1.2.17
monolog/monolog                      1.19.0
myclabs/deep-copy                    1.5.1
paragonie/random_compat              v2.0.2
phpdocumentor/reflection-docblock    2.0.4
phpspec/prophecy                     v1.6.0
phpunit/php-code-coverage            3.3.2
phpunit/php-file-iterator            1.4.1
phpunit/php-text-template            1.2.1
phpunit/php-timer                    1.0.8
phpunit/php-token-stream             1.4.8
phpunit/phpunit                      5.3.4
phpunit/phpunit-mock-objects         3.1.3
phpunit/phpunit-skeleton-generator   2.0.1
psr/log                              1.0.0
sebastian/code-unit-reverse-lookup   1.0.0
sebastian/comparator                 1.2.0
sebastian/diff                       1.4.1
sebastian/environment                1.3.7
sebastian/exporter                   1.2.1
sebastian/global-state               1.1.1
sebastian/object-enumerator          1.0.0
sebastian/recursion-context          1.0.2
sebastian/resource-operations        1.0.0
sebastian/version                    1.0.6
sensio/distribution-bundle           v5.0.6
sensio/framework-extra-bundle        v3.0.16
sensio/generator-bundle              v3.0.6
sensiolabs/security-checker          v3.0.2
swiftmailer/swiftmailer              v5.4.2
symfony/monolog-bundle               2.11.1
symfony/phpunit-bridge               v2.8.6
symfony/polyfill-apcu                v1.2.0
symfony/polyfill-intl-icu            v1.2.0
symfony/polyfill-mbstring            v1.2.0
symfony/polyfill-php54               v1.2.0
symfony/polyfill-php55               v1.2.0
symfony/polyfill-php56               v1.2.0
symfony/polyfill-php70               v1.2.0
symfony/polyfill-util                v1.2.0
symfony/security-acl                 v3.0.0
symfony/swiftmailer-bundle           v2.3.11
symfony/symfony                      v2.8.6
twig/twig                            v1.24.0

绝对路径:

<server name="KERNEL_DIR" value="C:\wamp\www\treningPHPUnitSymfony2.8\app" />

同样的错误。

1 个答案:

答案 0 :(得分:5)

使用Symfony 2.8.17我们的内核位于同一级别的/appphpunit.xml.dist。 所以我们补充说;

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

PS:额外信息; 由于我们的设置,我们还需要使用putenv("X_ENV=test")来获取配置详细信息以完成测试。