简体   繁体   English

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

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

There is an answer for similar question Laravel 5: PHPUnit and no code coverage driver available that works, but i have xdebug installed.有类似问题的答案Laravel 5: PHPUnit and no code coverage driver available that 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. "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 和贡献者编写。

Error: No code coverage driver is available错误:没有可用的代码覆盖率驱动程序

.II 3 / 3 (100%) .II 3 / 3 (100%)

Time: 1.13 seconds, Memory: 4.00MB时间:1.13 秒,内存:4.00MB

OK, but incomplete, skipped, or risky tests!好的,但不完整、跳过或有风险的测试! Tests: 3, Assertions: 1, Incomplete: 2. Done.](url)测试: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加载扩展哇。加载扩展

(I have netbeans and project directory in same Windows partition) (我在同一个 Windows 分区中有 netbeans 和项目目录)

There are 2 php.ini files in most Apache/PHP installations and definitely in WAMPServer大多数 Apache/PHP 安装中有 2 个php.ini文件,当然在 WAMPServer 中有

To amend the correct php.ini used by PHP in Apache use the menus要修改 Apache 中 PHP 使用的正确php.ini ,请使用菜单

wampmanager->PHP->php.ini

But for the php.ini file used by the PHP CLI you have to manually edit但是对于 PHP CLI 使用的php.ini文件,您必须手动编辑

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

the result of a php -v should look like this if XDEBUG is configured in the CLI如果在 CLI 中配置了 XDEBUG,则php -v的结果应该如下所示

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.4 ADDON upgrades can be found on SourceForge当前的 WAMPServer 3 是3.0.4 ADDON 升级可以在 SourceForge 上找到

The latest ADDON PHP Version is PHP7.0.6 also available on SourceForge最新的 ADDON PHP 版本是 PHP7.0.6 也可在 SourceForge 上获得

See The WampServer Forum to 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 parameters in the php.ini to suit your specific needs您可能会发现,你必须tweek的Xdebug的配置参数php.ini ,以满足您的特定需求

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

$ php -i | grep xdebug $ php -i | grep xdebug // to check if xdebug was installed $ php -i | grep xdebug // 检查是否安装了 xdebug

$ 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 等。

With the same problem on Debian:在 Debian 上遇到同样的问题:

Error: No code coverage driver is available错误:没有可用的代码覆盖率驱动程序

I fixed it with installing php-xdebug: sudo apt install php-xdebug我通过安装 php-xdebug 修复了它: sudo apt install php-xdebug

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM