代码之家  ›  专栏  ›  技术社区  ›  Michael Millar

如何在PHPUnit中解决这个问题,它要求我在PHPUnit中设置KERNEL\u DIR。xml?

  •  4
  • Michael Millar  · 技术社区  · 6 年前

    这是我的护照。xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <phpunit
            colors="true"
            convertErrorsToExceptions="true"
            convertNoticesToExceptions="true"
            convertWarningsToExceptions="true"
            stopOnFailure="true"
            strict="true"
            bootstrap="./vendor/autoload.php">
        <testsuites>
            <php>
                <server name="KERNEL_DIR" value="app" />
                <ini name="display_errors" value="true"/>
            </php>
            <testsuite name="Functional Tests">
                <directory>./tests/src/myApp/AppBundle/functional</directory>
            </testsuite>
        </testsuites>
    
        <filter>
            <whitelist processUncoveredFilesFromWhitelist="true">
                <directory suffix=".php">./src/</directory>
            </whitelist>
        </filter>
    </phpunit>
    

    这是考试课

    use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
    
    class MyTest extends WebTestCase
    {
        private $client;
    
        public function setUp()
        {
            $this->client = static::createClient();
        }
    

    运行测试时,我在设置中的行中得到:

    在phpunit中设置KERNEL\u DIR。xml依据 https://symfony.com/doc/current/book/testing.html#your-first-functional-test 或者重写WebTestCase::createKernel()方法

    1 回复  |  直到 6 年前
        1
  •  10
  •   Alister Bulman    6 年前

    移动 <php> ... </php> 超出 <testsuites>... 阻止到它自己的顶级。

    以下是我自己的主要项目的精简副本:

    <phpunit 
        bootstrap = "app/bootstrap_test.php"
        verbose = "true"
    >
        <php>
            <ini name="memory_limit" value="-1" />
            <!-- <server name="KERNEL_DIR" value="./app/" /> older-style -->
            <server name="KERNEL_CLASS" value="AppKernel" />
            <server name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
        </php>
    
        <testsuites>
            <testsuite name="project.name">
                <directory suffix=".php">./src/*Bundle</directory>
                <directory suffix=".php">./src/AppBundle</directory> -->
                <directory>./tests/App</directory>
            </testsuite>
        </testsuites>