Symfony 如果;框架.测试“;配置未设置为true
我正在尝试使用WebTestCase应用功能测试Symfony 如果;框架.测试“;配置未设置为true,symfony,phpunit,symfony4,Symfony,Phpunit,Symfony4,我正在尝试使用WebTestCase应用功能测试 class CalculatorControllerTest extends WebTestCase { public function testSumPost() { $client = static::createClient(); $client->request('GET', '/calculator/sum'); $this->assertEquals(20
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
My phpunit.xml:(我还尝试在APP_ENV和Debug 1中测试而不是开发,而不是0)
测试/单元
我查看了所有相关问题,但找不到好的答案,有什么想法吗?在您的
config/packages/test/framework.yaml
中您有test:~
,但我想应该是test:true
。请参阅:谢谢,但当我将hem设置为true并重新启动docker容器时,您可能需要重建缓存。您是否尝试过php bin/console cache:clear--env=test
或者rm-rf var/cache/test*
如果您使用的是相对标准的Symfony安装,请将
替换为phpunit.xml
文件中的
。
<?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>