Vin*_*aux 8 php phpunit symfony
使用 Symfony 5.2 和 PhpUnit 最新版本,我的功能测试出现此错误
LogicException: You cannot create the client used in functional tests if the "framework.test" config is not set to true.
Run Code Online (Sandbox Code Playgroud)
内容config/packages/test/framework.yaml:
framework:
test: true
session:
storage_id: session.storage.mock_file
Run Code Online (Sandbox Code Playgroud)
我的 PHP 部分phpunit.xml.dist:
<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>
Run Code Online (Sandbox Code Playgroud)
这是我的测试内容:
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());
}
}
Run Code Online (Sandbox Code Playgroud)
我只有默认的 bootstrap.php 文件,我无法理解此错误,因为 APP_ENV 已设置为“测试”。
我尝试清除缓存。
当我倾倒时dd($_ENV['APP_ENV']);,我有dev,我不明白为什么。
| 归档时间: |
|
| 查看次数: |
2675 次 |
| 最近记录: |