我正在运行一系列PHPunit测试,并有一个控制器报告100%的覆盖率。但在覆盖报告中,只有其84行代码中的5行被标记为“绿色”。我想知道可能导致这个问题的因素是什么?一个有趣的点是可能会引起它的是“间接调用”。这个特定的控制器是许多其他控制器的父类,由于很多其他对象从中继承,所以代码可能会被其他地方调用...但那么它不会变成绿色吗?目前唯一变成绿色的方法是“__construct”方法。我不知道这是否足够详细,但如果有人对单元测试如何确定覆盖率具有更多了解,我很想听听。根据Gaurav的评论进行编辑:phpunit命令行是“phpunit --configuration admin.xml”,而admin.xml则为:
作为对 jakenoble 的回应:
这个辅助程序正在读取 100% 的覆盖率,但是在内部我们看到一个有时显示绿色但没有红色的方法顶部的一些文本总共有 1099 行。
<phpunit bootstrap="./admin/applications/admin/bootstrap.php" colors="true">
<testsuite name="AdminTestSuite">
<directory suffix=".php">./admin/applications/admin/</directory>
<directory suffix=".php">./admin/applications/shared/</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">../admin/applications/admin/controllers</directory>
<directory suffix=".php">../admin/applications/shared/controllers</directory>
<directory suffix=".php">../admin/applications/shared/helpers</directory>
<directory suffix=".php">../admin/lib/controllers</directory>
<directory suffix=".php">../admin/lib/helpers</directory>
<directory suffix=".php">../admin/lib/models</directory>
<directory suffix=".php">../admin/lib/utils</directory>
</whitelist>
<blacklist>
<file>../dm_admin/applications/shared/controllers/DashboardController.php</file>
<directory suffix=".php">../admin/lib/crons</directory>
</blacklist>
</filter>
<logging>
<log type="coverage-html" target="/projects/ut/admin/" charset="UTF-8"
yui="true" highlight="true"
lowUpperBound="50" highLowerBound="80"/>
<log type="testdox-html" target="/projects/ut/admin/testdox.html" />
</logging>
</phpunit>
作为对 jakenoble 的回应:
这个辅助程序正在读取 100% 的覆盖率,但是在内部我们看到一个有时显示绿色但没有红色的方法顶部的一些文本总共有 1099 行。
![The report reading 100% coverage on the helper](https://istack.dev59.com/QVsEd.webp)
![Some text at the top of one of the methods - 1099 lines in all](https://istack.dev59.com/HNgTK.webp)