升级到PHPUnit 5.5.4后,代码覆盖率报告不正确

时间:2016-09-20 09:59:45

标签: php phpunit code-coverage

我使用PHP 5.6.24和PHPUnit 5.5.4以及XDebug 2.4.1,我的代码覆盖率达到了0.83%。 但是,在我使用PHP 5.6.0与PHPUnit 4.7.7和XDebug 2.3.3之前,代码覆盖率达到了84%以上。

我发现自PHP 5.5.x起,您需要配置一个配置了白名单的phpunit.xml。这对我来说是新的,所以我添加了以下文件:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./</directory>
            <file></file>
        </whitelist>
    </filter>
    <logging>
        <log type="coverage-html" target="../results/report" lowUpperBound="35" highLowerBound="70"/>
    </logging>
    <testsuites>
        <testsuite name="DTS">
            <directory>./</directory>
        </testsuite>
    </testsuites>
</phpunit>

单元测试仍然有效。当我通过命令行运行它时,我仍然看到所有测试都成功执行,但它只是具有如此奇怪结果的代码覆盖率报告。

1 个答案:

答案 0 :(得分:0)

我正在运行5.5.4,这是最新的稳定版本,5.6是测试版。我将日志记录添加到我的日志中以查看它是否可行,并且确实如此。它生成了一个HTML报告,该报告位于报告目录中,可以正确显示百分比。这是我的phpunit.xml文件

tizen.application.getCurrentApplication().exit();

所以它可能是测试版,但你至少可以看到我的xml文件并知道它适用于5.5.4。祝你好运!