I am trying for quite some time now to disable the profiler in the test-environment. The only way it works is manually setting APP_ENV=test
in file .env
but I want to do this through the command line, not by editing a file.
Here's everything I tried:
I tried editing bin/console
like described in Chris Brown's answer in this thread: Load different .env file with a Symfony 4 command (I also added the file .env.test
, and according to xdebug it loads the appropriate file and runs through the appropriate code and also the variables $env
and $debug
get the appropriate value when I run the server with --env=test --no-debug
)
I tried setting profiler: enabled: false
like described in flu's answer in this thread: How to disable profiler in Symfony2 in production? (in config/packages/test/framework.yaml)
I tried setting the profiler line in bundles.php to
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true],
and to
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => false, 'test_cached' => false],
I tried those solutions separately and also all together, still the profiler keeps popping up. Does anybody have an idea?
EDIT: After applying Alister Bulman's answer the command gives me this:
#php 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'
EDIT 2:
Thanks to Jared Farrish I just found out the browser is receiving the website in "dev" mode although the server is started in test environment on cli. Obviously editing bin/console
and public/index.php
is not enough, they're not called when the server receives a request from the browser.
EDIT 3:
So I found out the http request goes first to public/index.php
, but whatever I do, I cannot seem to make anything available there which was defined in bin/console
although the whole server is started there in the first place. Anyone an idea how this can be done?
I found it myself. What I did was use a functionality of php.ini which is called "auto_prepend_file" where you can specify a PHP file which gets executed automatically before the actual PHP content is executed. So in there I put a path to a file with following content:
<?php
$_ENV['APP_ENV'] = 'test';
$_ENV['APP_DEBUG'] = 0;