在PHPunit的命令行上设置xdebug.coverage_enable = On

时间:2012-08-06 14:07:56

标签: phpunit

我不想为所有脚本打开xdebug代码覆盖率,但我确实希望能够为每天生成代码覆盖率的jenkins构建打开它。

我尝试了以下

phpunit -d xdebug.coverage_enable=1 -c phpunit-coverage.xml.dist

但是我总是收到以下错误

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

关于如何让它工作的任何想法,而不必每次都更改php.ini?

3 个答案:

答案 0 :(得分:1)

最后我发现你不能做我原本想要的事情。

相反,答案是添加第二个启用了xdebug和coverage的php.ini文件。然后 在我的build.xml中,我使用以下命令来运行它。

php -c /usr/local/lib/php-coverage.ini /usr/bin/phpunit -c app/

答案 1 :(得分:0)

使用 php 7.4 我必须使用 -d xdebug.mode=coverage

因为我使用了 php -n,所以我的全行是 -d zend_extension=xdebug.so -d xdebug.mode=coverage

答案 2 :(得分:0)

是的,它可以,但只能像这样运行:

php -dxdebug.mode=coverage bin/phpunit --coverage-clover='reports/coverage/coverage.xml' --coverage-html='reports/coverage'

注意:“..Xdebug:[Config] 设置‘xdebug.coverage_enable’已重命名,..”

相关问题