I'm trying to run composer test
, the tests seems working well, but after tests done, I got a warning below.
Tests: 236 passed
Time: 6.77s
WARN Unable to get coverage using Xdebug. Did you set Xdebug's coverage mode?
I've tried set WORKSPACE_INSTALL_XDEBUG=true
in my laradock .env
, also add xdebug.mode=coverage
line to my xdebug.ini
file in the workspace folder.
After done these, I ran docker compose build workspace
and recreated the workspace container, but still got the same warning and can't saw the coverage shows.
I can't find any info on laradock document, how can I supposed to enable the coverage mode correctly?
This is my xdebug.ini
under workspace folder.
; NOTE: The actual debug.so extention is NOT SET HERE but rather (/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini)
xdebug.mode=coverage
xdebug.remote_host="host.docker.internal"
xdebug.remote_connect_back=0
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=0
xdebug.remote_enable=0
xdebug.cli_color=0
xdebug.profiler_enable=0
xdebug.profiler_output_dir="~/xdebug/phpstorm/tmp/profiling"
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
xdebug.var_display_max_depth=-1
I've traced the execution of each line in workspace dockerfile, there's a replace line at here which replace my xdebug.ini
to final like below:
; NOTE: The actual debug.so extention is NOT SET HERE but rather (/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini)
xdebug.mode=coverage,debug # My settings here.
xdebug.client_host="host.docker.internal"
xdebug.discover_client_host=false
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
xdebug.start_with_request=yes
xdebug.mode=debug # This line overwrite my setting.
xdebug.cli_color=1
; xdebug.profiler_enable=0
xdebug.output_dir="~/xdebug/phpstorm/tmp/profiling"
xdebug.remote_handler=dbgp
; xdebug.remote_mode=req
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
xdebug.var_display_max_depth=-1
The replace line overwrite my xdebug.mode
so the coverage mode is not enabled, I quick fixed by change the line position to below:
; NOTE: The actual debug.so extention is NOT SET HERE but rather (/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini)
xdebug.remote_host="host.docker.internal"
xdebug.remote_connect_back=0
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=0
xdebug.remote_enable=0
xdebug.cli_color=0
xdebug.profiler_enable=0
xdebug.profiler_output_dir="~/xdebug/phpstorm/tmp/profiling"
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.var_display_max_children=-1
xdebug.var_display_max_data=-1
xdebug.var_display_max_depth=-1
xdebug.mode=coverage,debug // Move setting to below
Conclusion by traced the command of workspace dockerfile, there is no official optional can setting the xdebug coverage mode, but you can work around by modify the xdebig.ini
in workspace folder.
Just notice that your xdebug.mode
line must be after the line xdebug.remote_enable=0
or it will be overwrite by default.
In my case, I'm testing the composer packages which by composer test
, if you are testing with php artisan test
and need coverage mode, you'll need to modify the xdebug.ini
in php-fpm folder.