Symfony/PHPUnit 在测试中启用分析器

标签 symfony testing phpunit profiler

我想为我的测试启用 symfony 分析器,我遵循了这个 documentation但我的探查器保持空白。我正在使用 PHPUnit 7.5.16 和 Symfony 4.3.4 以及 PHP 7.2.19。 我应该添加什么?

#web_profiler:
#    toolbar: false
#    intercept_redirects: false
#
#framework:
#    profiler: { collect: false }

web_profiler:
  toolbar: true
  intercept_redirects: false

framework:
#  profiler: { only_exceptions: false }
  # make tests slowest, but it s usefull in local,watch this doc: https://symfony.com/doc/current/testing/profiling.html
  profiler: { enabled: true, collect: true }

在我的 setUp() 方法中

parent::setUp();
$client = static::createClient();
$client->enableProfiler();

最佳答案

您可能还需要:

framework:
    test: true

由于您在测试中启用了配置文件,因此您不需要这样做

framework:
   profiler: { enabled: true, ... # can be 'enabled: false', if you enable it in a test

我自己的测试环境配置是:

> bin/console -e test debug:config framework profiler

Current configuration for "framework.profiler"
==============================================

enabled: true
collect: false
only_exceptions: false
only_master_requests: false
dsn: 'file:%kernel.cache_dir%/profiler'

框架:测试:真。有了这个配置,我就有了一个启用配置文件的测试环境,并检查其中的结果。

关于Symfony/PHPUnit 在测试中启用分析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58415436/

相关文章:

doctrine-orm - JMS 序列化程序无法使用 FOSRest 处理自定义存储库方法

testing - 是否可以在测试脚本中使用元数据?

java - 使用 robotium 检查对话框提示 - 如果没有则需要 if 语句

python - 使用 Python 和模拟器测试 VHDL/FPGA

php - 如何将 laravel 测试设置为转到站点名称而不是本地主机

javascript - Symfony3 - 未定义索引(解码 JSON->对象->数组)

php - Symfony 5.1.3 清除缓存时出现问题 : Attempted to load class "MappingDriverChain" from namespace

symfony - 获取自定义奏鸣曲 block 中的容器实例

php - Laravel 按需测试通知

PHPUnit:如何模拟 HTTP 请求?