如果 "framework.test" 配置未设置为 true,则无法创建用于功能测试的客户端
You cannot create the client used in functional tests if the "framework.test" config is not set to 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 中测试而不是开发并调试 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>
我正在尝试使用 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 中测试而不是开发并调试 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>