我正在使用 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
不在列表中,但它运行。我怎样才能解决这个问题?
最佳答案
我有同样的问题。是php.ini文件中xdebug的配置引起的。
就我而言,我有 xdebug 3.0.4。您可以使用 php -v 进行检查。
您必须在 php.ini 文件中包含以下几行:
[XDebug]
zend_extension = "c:\xampp8\php\ext\php_xdebug-3.0.4-7.4-vc15-x86_64.dll"
xdebug.mode=debug,coverage
xdebug.client_host=127.0.0.1
xdebug.client_port=9000
关于php - Laravel 不生成代码覆盖率报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66876314/