我正在尝试使用 PHPUnit 生成覆盖 html 文件。我收到警告:“未配置过滤器,将不会处理代码覆盖率”并且不会生成覆盖率文件。
这是 phpunit.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./phpUnitTutorial</directory>
</testsuite>
</testsuites>
</phpunit>
有人可以帮忙吗?
我建议您使用配置生成器(
phpunit --generate-configuration
)。它会问您几个问题,然后为您生成正确的配置。
我在 PHPUnit 9.5 配置文件中的
<phpunit>
标签之间添加了以下内容:
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
从 PHPUnit 10.x 开始,它是:
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
bootstrap="bootstrap.php"
colors="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
requireCoverageMetadata="true"
>
...
<source>
<include>
<directory>../../src</directory>
</include>
</source>
</phpunit>
对于像我这样的人:我更改了命名空间,但 PHPStorm 已将 src/ 目录中的所有内容移至项目的根目录。测试仍在运行,但在尝试生成覆盖范围时,我收到了该消息。