php - Laravel 不生成代码覆盖率报告
问题描述
我正在使用 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 处于覆盖模式,你可以通过下面的命令来运行它(在运行过程中它会开启)
php -dxdebug.mode=coverage vendor/bin/phpunit --coverage-clover='reports/coverage/coverage.xml' --coverage-html='reports/coverage'
请考虑 Xdebug 不是为生成报告而设计的,因此如果您想为大量测试生成报告,您将面临来自操作系统的进程终止问题,在这种情况下,您应该寻找其他软件包
推荐阅读
- javascript - 在 Jodit 编辑器外部单击时保持选择/光标
- firebase - Firebase 身份验证处理程序 - 如何将 myapp.firebaseapp.com/__/auth/handler 更改为 mydomain.com/__/auth/handler?
- ckeditor - TYPO3 9 CKEditor 添加额外的段落
- firebase - Flutter + firebase:配置应用程序以使用本地 firebase 模拟器
- python - Python Pandas:我需要转换一个 pandas 数据框
- powershell - 修改 SendGoogleForm 脚本 v2
- postgresql - 尝试使用包含等号的路径从 S3 加载到 Postgres RDS 时权限被拒绝
- python - 将字符串值从 JSON 替换为列表
- .htaccess - 下拉菜单在本地主机上工作,但不在服务器上?可能是.htaccess?
- javascript - 在提交表单上显示模式,然后按提交表单