PHP 单元。错误:没有可用的代码覆盖率驱动程序。(安装了 xdebug)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37270837/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:08:18  来源:igfitidea点击:

PHPUnit. Error: No code coverage driver is available. (having xdebug installed)

phpphpunitwamp

提问by Sruj_2ndAccountForStupidQtions

There is an answer for similar question Laravel 5: PHPUnit and no code coverage driver availablethat works, but i have xdebug installed.

有类似问题的答案Laravel 5: PHPUnit and no code coverage driver availablethat works,但我安装了 xdebug。

(if this matter I'm using: windows7, netbeans8.1, php7, wamp3)

(如果这件事我正在使用:windows7、netbeans8.1、php7、wamp3)

Displaying code coverage in Netbeans result in:

在 Netbeans 中显示代码覆盖率会导致:

Error: No code coverage driver is available

错误:没有可用的代码覆盖率驱动程序

, and the output is below:

,输出如下:

"C:\wamp\www\treningPHPUnitSymfony2.8\bin\phpunit.bat" "--colors" "--log-junit" "C:\Users\chiny\AppData\Local\Temp\nb-phpunit-log.xml" "--coverage-clover" "C:\Users\chiny\AppData\Local\Temp\nb-phpunit-coverage.xml" "C:\Program Files\NetBeans 8.1\php\phpunit\NetBeansSuite.php" "--" "--run=C:\wamp\www\treningPHPUnitSymfony2.8\src\TreningBundle\Tests\Controller\RabarbarControllerTest.php" PHPUnit 5.3.4 by Sebastian Bergmann and contributors.

Error: No code coverage driver is available

.II 3 / 3 (100%)

Time: 1.13 seconds, Memory: 4.00MB

OK, but incomplete, skipped, or risky tests! Tests: 3, Assertions: 1, Incomplete: 2. Done.](url)

"C:\wamp\www\treningPHPUnitSymfony2.8\bin\phpunit.bat" "--colors" "--log-junit" "C:\Users\chiny\AppData\Local\Temp\nb-phpunit-log. xml" "--coverage-clover" "C:\Users\chiny\AppData\Local\Temp\nb-phpunit-coverage.xml" "C:\Program Files\NetBeans 8.1\php\phpunit\NetBeansSuite.php" " --" "--run=C:\wamp\www\treningPHPUnitSymfony2.8\src\TreningBundle\Tests\Controller\RabarbarControllerTest.php" PHPUnit 5.3.4 由 Sebastian Bergmann 和贡献者编写。

错误:没有可用的代码覆盖率驱动程序

.II 3 / 3 (100%)

时间:1.13 秒,内存:4.00MB

好的,但不完整、跳过或有风险的测试!测试:3,断言:1,不完整:2。完成。](url)

xdebug conf (C:\wamp\bin\apache\apache2.4.17\bin\php.ini):

xdebug conf (C:\wamp\bin\apache\apache2.4.17\bin\php.ini):

[xdebug]
zend_extension ="C:/wamp/bin/php/php7.0.1/zend_ext/php_xdebug-2.4.0rc3-7.0-vc14.dll"

xdebug.remote_enable = off
xdebug.profiler_enable = off
xdebug.profiler_enable_trigger = Off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="C:/wamp/tmp"
xdebug.show_local_vars=0

loaded extensions wamp. loaded extension

加载扩展 哇。 加载扩展

(I have netbeans and project directory in same Windows partition)

(我在同一个 Windows 分区中有 netbeans 和项目目录)

采纳答案by RiggsFolly

There are 2 php.inifiles in most Apache/PHP installations and definitely in WAMPServer

php.ini大多数 Apache/PHP 安装中有 2 个文件,并且肯定在 WAMPServer 中

To amend the correct php.iniused by PHP in Apache use the menus

修改php.iniApache 中 PHP 使用的正确使用菜单

wampmanager->PHP->php.ini

But for the php.inifile used by the PHP CLI you have to manually edit

但是对于php.iniPHP CLI 使用的文件,您必须手动编辑

\wamp\bin\php\php{version}\php.ini

the result of a php -vshould look like this if XDEBUG is configured in the CLI

php -v如果在 CLI 中配置了 XDEBUG ,a 的结果应该如下所示

php -v
PHP 7.0.6 (cli) (built: Apr 27 2016 14:00:40) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans

NOTE

笔记

The current WAMPServer 3 is 3.0.4ADDON upgrades can be found on SourceForge

当前的 WAMPServer 3 是3.0.4ADDON 升级,可以在 SourceForge 上找到

The latest ADDON PHP Version is PHP7.0.6 also available on SourceForge

最新的 ADDON PHP 版本是 PHP7.0.6 也可在 SourceForge 上获得

See The WampServer Forumto keep up to date with the latest releases of PHP / MYSQL / Apache ADDONS for WAMPServer 3

请参阅WampServer 论坛以了解 WAMPServer 3 的 PHP/MYSQL/Apache 插件的最新版本

Also :

还 :

You may find that you have to tweek the XDEBUG config parametersin the php.inito suit your specific needs

您可能会发现,你必须tweek的Xdebug的配置参数php.ini,以满足您的特定需求

回答by Robert

I've faced this problem with a new installation of PHP 7.1 and this is what I've done to make it work

我在新安装 PHP 7.1 时遇到了这个问题,这就是我为使其工作所做的工作

$ brew install php71-xdebug

$ brew install php71-xdebug

$ php -i | grep xdebug// to check if xdebug was installed

$ php -i | grep xdebug// 检查是否安装了 xdebug

$ phpunit

$ phpunit

After that it worked. Additionally this is how my phpunit.xml looks like I've needed to whitelist whole structure because it's shared component

在那之后它起作用了。另外这就是我的 phpunit.xml 看起来像我需要将整个结构列入白名单,因为它是共享组件

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false"
         syntaxCheck="false">
    <testsuites>
        <testsuite name="Tests">
            <directory suffix=".php">./Tests/</directory>
        </testsuite>
    </testsuites>
    <logging>
        <log type="coverage-clover" target="./build/logs/clover.xml"/>
    </logging>
    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory>./</directory>
        </whitelist>
    </filter>
</phpunit>

This solution will work on MacOS only, if you want to make it work on Linux then you need to use applicable package manager like apt-get etc.

此解决方案仅适用于 MacOS,如果您想使其在 Linux 上工作,则需要使用适用的包管理器,如 apt-get 等。