Search code examples
unit-testingsymfonyenvironmentprofilerfunctional-testing

Symfony 3 - Open profiler generated by test environment (functional tests) in the browser


I am trying to access to a profiler generated by a functional test with the method

$client->enableProfiler() 

and by recovering the token with

$client->getProfile()->getToken()

but when I go to the page "/_profiler/{TOKEN}" I get the message

Token not found Token "{TOKEN}" was not found in the database.


Solution

  • When the profiler is generated, it is placed in a cache folder corresponding to the current environment. The environment of the functional test is "test" and that of the browser is "dev".

    To overcome the problem, it is possible to place the profilers generated by the test environment in the "/var/cache/dev" folder by adding in the configuration of the test environment (config_test.yml):

    framework:
        profiler:
            dsn: 'file:%kernel.root_dir%/../var/cache/dev/profiler'