Symfony/PHPUnit 在测试中启用探查器

Symfony/PHPUnit enable profiler in tests

我想为我的测试启用 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'

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