php - 带有 Clover 代码覆盖率报告的 PHPUnit:测试未执行且命令退出
问题描述
我“继承”了一个非常古老的 PHP 项目,仅与 PHP 5.6 兼容,并且没有任何框架编写,我正在尝试为 PHP 7.x “现代化”它,并添加一些单元测试和一些代码检查工具,如带有 Jenkins 的 SonarQube。
该项目有一些可执行脚本,需要一些参数才能正确执行,当我执行 phpunit 并启用 Clover 覆盖的生成时,它会尝试执行它们,但由于缺少所需的参数而失败:
⋊> ~/P/myproject on mybranch ⨯ ./phpunit tests/
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
Runtime: PHP 7.4.5 with Xdebug 2.9.5
Configuration: /Users/me/Projects/myproject/phpunit.xml
You must specify a source (--source)!
这是files-index.php
项目根文件夹中命令的输出,需要一个--source
参数才能运行:
[...]
if (!$args['source']) {
exit("You must specify a source (--source)!\n");
}
[...]
我不明白的是为什么如果我在没有启用覆盖率报告的情况下执行 PHPUnit,项目中存在的(少数)测试执行时没有错误(无论如何文件files-index.php
目前没有测试):
⋊> ~/P/myproject on mybranch ⨯ ./phpunit --no-config tests/
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
........ 8 / 8 (100%)
Time: 194 ms, Memory: 4.00MB
OK (8 tests, 8 assertions)
这是我的phpunit.xml
文件:
⋊> ~/P/myproject on mybranch ⨯ cat phpunit.xml 22:10:25
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
backupGlobals="false"
verbose="true">
<testsuites>
<testsuite name="My Project">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">.</directory>
<exclude>
<directory suffix=".php">./vendor</directory>
<directory suffix=".php">./_classes</directory>
</exclude>
</whitelist>
</filter>
<logging>
<log type="junit" target="./reports/logfile.xml"/>
<log type="coverage-clover" target="./reports/coverage.xml"/>
</logging>
<php>
<const name="PHPUNIT_TESTSUITE" value="true"/>
</php>
</phpunit>
我哪里错了?
解决方案
推荐阅读
- dynamics-crm - ParentId in CustomerAddress Entity in Dynamics 365
- ubuntu - 使用 RAW 图像流式传输 raspicam_node
- r - 尝试根据列中的值生成一个分离数据帧的函数,然后从分离的数据中生成新的数据帧
- javascript - 我们应该关心 JS 非原始值的可变性吗?
- swift - SwiftUI navigationLink error - not accepting parameter on linked view
- ios - 未加载库:@rpath/FBSDKCoreKit_Basics.framework/FBSDKCoreKit_Basics
- python - 如何使用美汤查找功能提取html元素
- xml - MS Access VBA XML POST 使用 HTTP 使用 msxml2.DOMDocument.6.0
- flutter - 与 ARKit 和 ARCore 共享面部网格
- java - 我应该怎么做才能使我的 do-while 循环语句起作用?