【发布时间】:2021-07-05 04:15:08
【问题描述】:
我正在尝试使用 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 中使用 test 而不是 dev & Debug 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>
我查看了所有相关问题,但找不到好的答案,请问有什么想法吗?
【问题讨论】:
-
在您的
config/packages/test/framework.yaml中有test: ~,但我想应该是test: true。见:github.com/symfony/recipes/blob/master/symfony/framework-bundle/… -
谢谢,但当我将 hem 设置为 true 并重新启动 docker 容器不工作时
-
您可能需要重建缓存。你试过
php bin/console cache:clear --env=test或者rm -rf var/cache/test* -
假设您使用的是相对标准的 Symfony 安装,请将您的
phpunit.xml文件中的<env name="APP_ENV" value="dev" />替换为<env name="APP_ENV" value="test" />。