Xdebug: PHPUnit代码覆盖率出现致命错误

3

我想要测试我的代码和覆盖率。我已经安装了Xdebug扩展程序,当我使用php -v命令进行验证时,一切都很好,像这样:

PHP 7.4.12 (cli) (built: Oct 27 2020 17:18:47) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Xdebug v3.0.0RC1, Copyright (c) 2002-2020, by Derick Rethans
    with Zend OPcache v7.4.12, Copyright (c), by Zend Technologies 

然而,如果我运行phpunit,会出现致命错误:
Sebastian Bergmann及其贡献者的PHPUnit 7.5.20。
Fatal error: Uncaught SebastianBergmann\CodeCoverage\RuntimeException: xdebug.coverage_enable=On has to be set in php.ini in C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\.phpunit\phpunit-7.5-0\vendor\phpunit\php-code-coverage\src\Driver\Xdebug.php on line 42

SebastianBergmann\CodeCoverage\RuntimeException: xdebug.coverage_enable=On has to be set in php.ini in C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\.phpunit\phpunit-7.5-0\vendor\phpunit\php-code-coverage\src\Driver\Xdebug.php on line 42

Call Stack:
    0.0005     402112   1. {main}() C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\phpunit:0
    0.0027     477240   2. require('C:\Users\quent\Desktop\Github\quentingeeraert-website\vendor\symfony\phpunit-bridge\bin\simple-phpunit.php') C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\phpunit:13
    0.2824     501760   3. include('C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\.phpunit\phpunit-7.5-0\phpunit') C:\Users\quent\Desktop\Github\quentingeeraert-website\vendor\symfony\phpunit-bridge\bin\simple-phpunit.php:405
    0.2989    1149952   4. PHPUnit\TextUI\Command::main($exit = ???) C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\.phpunit\phpunit-7.5-0\phpunit:22
    0.2989    1150064   5. Symfony\Bridge\PhpUnit\Legacy\CommandForV6->run($argv = [0 => 'bin\\phpunit', 1 => '--colors=always', 2 => '--stop-on-failure'], $exit = TRUE) C:\Users\quent\Desktop\Github\quentingeeraert-website\bin\.phpunit\phpunit-7.5-0\src\TextUI\Command.php:162

我已经在我的php.ini文件中添加了xdebug.coverage_enable = On,所以我不明白为什么系统会这样说 :/

也许有人可以帮助我吗?非常感谢帮助我!

1个回答

3
我已经在我的php.ini文件中添加了,所以我不明白为什么系统会这样说 :/
Xdebug v3.0.0RC1 PHPUnit 7.5.20
要么将PHPUnit升级到知道Xdebug 3的版本... 要么将Xdebug降级到2.x(2.9.8是最新版本)。
事实是:xdebug.coverage_enable 是 Xdebug 2 的选项。Xdebug 3 中该选项已无效,您应该使用 xdebug.mode = coverage 代替。

Xdebug 3 使用与 v2 不同的配置选项,您的 PHPUnit 版本并不知道这一点。Xdebug 3 将仅报告不再使用的 Xdebug 2 选项的空值/0。

https://3.xdebug.org/docs/upgrade_guide#Changed-Configuration-Settings

P.S. 当您使用Xdebug 3运行php -i时,应该会看到一个警告--如果您的php.ini中存在错误/过时的选项,它应该会发出投诉(除非您已将PHP配置为不报告任何启动错误我猜)。
在任一情况下:运行php -i并查看来自Xdebug部分的实际实时值:该选项具有什么值。

1
非常感谢,确实通过 php -i 命令,该值被设置为 0。根据您的建议,我将 xdebug 降级到了 2.9.8 版本,现在它可以正常工作了。 - Quentin Geeraert

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接