首页 > 解决方案 > Phpunit coverage-text 未显示所有测试的类文件

问题描述

我在我的项目中运行 phpunit,但覆盖文本没有在白名单中显示文件夹内的所有类。

我尝试过使用 PHPUnit 7.5.12 和 PHPUnit 8.2.1。

我尝试过使用 PHP 7.2 和 7.3(我现在正在使用 7.3)

Xdebug 版本为 v2.7.2

我的 phpunit.xml:

<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Api Connector">
            <directory suffix="Test.php">tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">src</directory>
        </whitelist>
    </filter>
</phpunit>

phpunit 覆盖文本结果

这是我项目中的文件列表

如您所见,并非我的项目中的所有文件都显示在覆盖结果中,我不知道为什么。

事实上,tests 目录中的所有文件都经过了测试,因为测试的 114 个函数中有一些是覆盖结果中未显示的文件中的函数。

编辑:Entity 文件夹中的所有文件都扩展了 ApiRest.php,这是一个抽象类。覆盖摘要中未显示的文件是那些没有自定义功能的文件。例如,如果我覆盖 ApiCompany.php 中的函数,则 ApiCompany 会显示在覆盖范围摘要中。

标签: phpunit-testing

解决方案


推荐阅读