PHPUnit 警告 - 未配置过滤器,代码覆盖率将不会被处理

问题描述 投票:0回答:4

我正在尝试使用 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>

有人可以帮忙吗?

php unit-testing phpunit warnings
4个回答
39
投票

我建议您使用配置生成器(

phpunit --generate-configuration
)。它会问您几个问题,然后为您生成正确的配置。


19
投票

我在 PHPUnit 9.5 配置文件中的

<phpunit>
标签之间添加了以下内容:

<coverage>
    <include>
        <directory suffix=".php">src</directory>
    </include>
</coverage>

5
投票

从 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>

0
投票

对于像我这样的人:我更改了命名空间,但 PHPStorm 已将 src/ 目录中的所有内容移至项目的根目录。测试仍在运行,但在尝试生成覆盖范围时,我收到了该消息。

© www.soinside.com 2019 - 2024. All rights reserved.