【问题标题】:No whitelist is configured, no code coverage will be generated error没有配置白名单,没有代码覆盖会产生错误
【发布时间】:2018-12-01 17:58:27
【问题描述】:

我正在尝试使用 PhpStorm 中的功能进行代码覆盖,但它向我显示此错误提示

“没有配置白名单,不会产生代码覆盖率。”

我在本地 Mac 机器上运行 PHP 7.2。

编辑:我已经为白名单和登录添加了 phpunit 设置

这就是我的 phpunit.xml 文件的样子:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer"
         backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>

        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <logging>
        <log type="coverage-html" target="./report" charset="UTF-8"
             yui="true" highlight="true"
             lowUpperBound="50" highLowerBound="80" />
    </logging>
    <php>
    </php>
</phpunit>

我也试过设置

processUncoveredFilesFromWhitelist

而不是

addUncoveredFilesFromWhitelist

但还是同样的错误

【问题讨论】:

    标签: laravel phpunit phpstorm code-coverage


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。这可能会有所帮助。

      首先,确保您可以在命令行上运行代码覆盖率。

      然后,看看 Phpstorm 试图运行什么命令。它在测试输出中给出,第二行:

      Testing started at 16:44 ...
      C:\...\php.exe -dxdebug.coverage_enable=1 C:/.../vendor/phpunit/phpunit/phpunit --coverage-clover C:\.\XXX.xml --no-configuration --filter "/(::XXX)( .*)?$/" App\XxxTest C:\XXX.php --teamcity
      PHPUnit 7.3.3 by Sebastian Bergmann and contributors.
      Error:         No whitelist is configured, no code coverage will be generated.
      

      我尝试自己在命令行上运行它,更改了路径。

      我注意到的是“--no-configuration”。这意味着它甚至没有读取我的 phpunit.xml 文件。要解决此问题,请设置 设置 -> 语言和框架 -> Php -> 测试框架 -> "默认配置文件" 到你的 phpunit.xml 文件中。

      您可能有不同的问题,但这可能会为您指明正确的方向。

      【讨论】:

        【解决方案3】:

        运行下面的命令。它对我有用。我正在使用 PHP 7.1、Symfony(1.x)PHPUnit(5.7) 旧版本。所以目录结构可能会因版本而异。

        symfony/lib> vendor/bin/phpunit --whitelist ../[valid dir name]/ 
        --coverage-clover test.xml UnitTest ../[dir]/[file_name]
        
        symfony/lib> vendor/bin/phpunit --whitelist ../plugins/ 
        --coverage-clover test.xml UnitTest ../test/PluginAllTests.php
        

        symfony/lib> vendor/bin/phpunit --whitelist ../tests/ 
        --coverage-clover test.xml UnitTest ../test/PluginAllTests.php
        

        【讨论】:

          猜你喜欢
          • 2012-10-06
          • 1970-01-01
          • 1970-01-01
          • 2012-01-14
          • 2020-12-26
          • 2019-01-29
          • 2011-07-07
          • 2016-03-09
          • 1970-01-01
          相关资源
          最近更新 更多