【发布时间】:2021-08-01 14:53:40
【问题描述】:
使用 Symfony 5.2 和 PhpUnit 最新版本,我的功能测试出现此错误
LogicException: You cannot create the client used in functional tests if the "framework.test" config is not set to true.
config/packages/test/framework.yaml的内容:
framework:
test: true
session:
storage_id: session.storage.mock_file
我的phpunit.xml.dist 的PHP 部分:
<php>
<ini name="error_reporting" value="-1"/>
<server name="APP_ENV" value="test" force="true"/>
<server name="SHELL_VERBOSITY" value="-1"/>
<env name="BOOTSTRAP_CLEAR_CACHE_ENV" value="test"/>
</php>
这是我的测试内容:
class JWTTokenAuthenticatorTest extends WebTestCase
{
public function test_authentication_token()
{
$client = static::createClient();
$client->request(
'POST',
'/authentication_token',
[],
[],
['CONTENT_TYPE' => 'application/json'],
'{"email":"api@api.com","password":"api"}'
);
$this->assertResponseIsSuccessful();
$this->assertMatchesRegularExpression('/{"token":"(.*)"}/i', $client->getResponse()->getContent());
}
}
我只有默认的 bootstrap.php 文件,我无法理解这个错误,因为 APP_ENV 设置为“测试”。
我试图清除缓存。
当我转储dd($_ENV['APP_ENV']); 时,我有dev,我不明白为什么。
【问题讨论】:
-
您是否尝试将
<server ... />更改为<env ... />? -
天哪,听起来简单又好听