【发布时间】:2021-06-26 18:53:29
【问题描述】:
我正在使用 Laravel 8 来测试我的应用,我正在运行
php artisan test --coverage-html reports
测试运行成功。问题是没有生成覆盖率报告。我已经在这里完成了关于 SO 的答案,据说解决方案将以下内容添加到我的 phpunit.xml
<logging>
<log type="coverage-html" target="tests/coverage" showUncoveredFiles="true"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
这行不通。我也试过了
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./app</directory>
</include>
<report>
<html outputDirectory="tests/reports/coverage"/>
</report>
</coverage>
还是什么都没有;以下是我的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">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
<directory suffix="Test.php">./packages/okotieno</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="tests/coverage" showUncoveredFiles="true"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="MAIL_DRIVER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<env name="DB_DATABASE" value="testing_db"/>
</php>
</phpunit>
我还运行php artisan test --help 来查看有效标志,--coverage-html 不在列表中,但它运行。我该如何解决这个问题?
【问题讨论】:
-
很抱歉现在可以给你一个明确的答案,但我不确定你是否需要
xdebug或不这样做。几年前我在尝试生成覆盖率报告时也遇到了问题,所以我最终使用了xDebug覆盖率(使用 PHPStorm)。
标签: php laravel phpunit laravel-testing