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



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

class CalculatorControllerTest extends WebTestCase
{
public function testSumPost()
{
$client = static::createClient();
$client->request('GET', '/calculator/sum');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
}

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

You cannot create the client used in functional tests if the "framework.test" config is not set to true

我的测试框架:

framework:
test: ~
session:
storage_id: session.storage.mock_file
router:
resource: "%kernel.root_dir%/config/routing_test.yml"
profiler:
collect: false

我的phpunit.xml:(我也尝试在APP_ENV&Debug中测试而不是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>

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

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

<php>
<env name="APP_ENV" value="test" force="true"/>
</php>

最新更新