如果“framework.test”配置未设置为 true,则无法创建功能测试中使用的客户端

yos*_*ini 11 phpunit symfony symfony4

我正在尝试使用 WebTestCase 应用功能测试。

class CalculatorControllerTest extends WebTestCase
{
    public function testSumPost()
    {
        $client = static::createClient();

        $client->request('GET', '/calculator/sum');

        $this->assertEquals(200, $client->getResponse()->getStatusCode());
    }
}
Run Code Online (Sandbox Code Playgroud)

当我运行测试时,出现以下错误消息:

 You cannot create the client used in functional tests if the "framework.test" config is not set to true
Run Code Online (Sandbox Code Playgroud)

我的测试框架:

framework:
 test: ~
 session:
   storage_id: session.storage.mock_file
 router:
   resource: "%kernel.root_dir%/config/routing_test.yml"
  profiler:
   collect: false
Run Code Online (Sandbox Code Playgroud)

我的 phpunit.xml:(我也尝试在 APP_ENV 中测试而不是 dev & 调试 1 而不是 0)

<?xml version="1.0" encoding="UTF-8"?>

<phpunit
    backupGlobals               = "false"
    backupStaticAttributes      = "false"
    colors                      = "true"
    convertErrorsToExceptions   = "true"
    convertNoticesToExceptions  = "true"
    convertWarningsToExceptions = "true"
    processIsolation            = "false"
    stopOnFailure               = "false"
    bootstrap                   = "config/bootstrap.php" >

<php>
    <ini name="error_reporting" value="-1" />
    <server name="KERNEL_CLASS" value="AppKernel" />
    <env name="APP_ENV" value="dev" />
    <env name="APP_DEBUG" value="0" />
    <env name="SHELL_VERBOSITY" value="-1" />
    <!-- define your env variables for the test env here -->
</php>

<testsuites>
    <testsuite name="Plein Test Suite">
        <directory>tests/unit</directory>
    </testsuite>
</testsuites>
Run Code Online (Sandbox Code Playgroud)

我查看了所有相关问题,但找不到好的答案,请问有什么想法吗?

Bra*_*ley 21

我通过将以下内容添加到我的phpunit.xml.dist/phpunit.xml文件(标记内phpunit)来解决此问题:

<php>
    <env name="APP_ENV" value="test" force="true"/>
</php>
Run Code Online (Sandbox Code Playgroud)