【问题标题】:xdebug : Fatal error with phpunit for code coveragexdebug : phpunit 代码覆盖的致命错误
【发布时间】:2021-03-03 04:55:20
【问题描述】:

我想测试我的代码和覆盖率。我已经安装了 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,所以我不明白系统为什么这么说:/

也许有人可以帮助我?非常感谢您对我的帮助!

【问题讨论】:

    标签: phpunit xdebug


    【解决方案1】:

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

    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

    PS当您使用 Xdebug 3 运行 php -i 时,您应该看到警告 - 如果您的 php.ini 中存在这样一个错误/过时的选项,它应该会抱怨。 ini(除非您已将 PHP 配置为不报告任何启动错误我猜)。

    在任何一种情况下:运行 php -i 并查看 Xdebug 部分的实际实时值:该选项具有什么值。

    【讨论】:

    • 非常感谢,确实使用 php -i 将值设置为 0。根据您的建议,我将 xdebug 降级为 2.9.8,现在可以使用了。
    猜你喜欢
    • 1970-01-01
    • 2012-08-23
    • 2011-07-23
    • 2018-05-29
    • 1970-01-01
    • 2012-05-04
    • 2012-03-07
    • 2013-05-07
    • 2016-09-09
    相关资源
    最近更新 更多