Reputation: 595
I don't want to turn on xdebug code coverage for all scripts but I do want to be able to turn it on for a daily jenkins build which produces the code coverage.
I tried the following
phpunit -d xdebug.coverage_enable=1 -c phpunit-coverage.xml.dist
However I always get the following error
Configuration read from phpunit-coverage.xml.dist
Fatal error: Uncaught exception 'PHP_CodeCoverage_Exception' with message 'You need to set xdebug.coverage_enable=On in your php.ini.' in /usr/local/lib/php/PHP/CodeCoverage/Driver/Xdebug.php on line 72
PHP_CodeCoverage_Exception: You need to set xdebug.coverage_enable=On in your php.ini. in /usr/local/lib/php/PHP/CodeCoverage/Driver/Xdebug.php on line 72
Call Stack:
0.0002 627488 1. {main}() /usr/local/bin/phpunit:0
0.0050 1095880 2. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:46
0.0050 1096608 3. PHPUnit_TextUI_Command->run() /usr/local/lib/php/PHPUnit/TextUI/Command.php:130
0.6419 39830848 4. PHPUnit_TextUI_TestRunner->doRun() /usr/local/lib/php/PHPUnit/TextUI/Command.php:192
0.9760 40345400 5. PHP_CodeCoverage->__construct() /usr/local/lib/php/PHPUnit/TextUI/TestRunner.php:258
0.9764 40358504 6. PHP_CodeCoverage_Driver_Xdebug->__construct() /usr/local/lib/php/PHP/CodeCoverage.php:119
Any ideas as to how I can get this to work, without having to change php.ini each time?
Upvotes: 18
Views: 30302
Reputation: 2691
Yes it can, but you have to pass the command-line .ini args to php first:
php -d xdebug.mode=coverage bin/phpunit --coverage-clover='reports/coverage/coverage.xml' --coverage-html='reports/coverage'
Note: "..Xdebug: [Config] The setting 'xdebug.coverage_enable' has been renamed,.."
Upvotes: 18
Reputation: 274
With php 7.4 and phpunit 9, it's possible set options with env
XDEBUG_MODE=coverage /usr/bin/phpunit
Upvotes: 12
Reputation: 1711
Using php 7.4 I has to use -d xdebug.mode=coverage
Because I use php -n
my full line was -d zend_extension=xdebug.so -d xdebug.mode=coverage
Upvotes: 3
Reputation: 595
In the end I discovered you cannot do what I originially wanted.
Instead the answer is to add second php.ini file which has xdebug and coverage enabled. Then in my build.xml I used the following to run it.
php -c /usr/local/lib/php-coverage.ini /usr/bin/phpunit -c app/
Upvotes: 1