Clover PHPUnit 覆盖率报告包括对不需要的文件的覆盖率


Clover PHPUnit coverage report is including coverage for unwanted file

我刚刚将CloverPHP设置为我的Jenkins工作。

我正在使用 PHPUnit 生成三叶草报告,除了显示文件的覆盖率报告之外,它似乎都在工作

/usr/share/php/SymfonyComponents/YAML/sfYamlInline.php 

作为报告的一部分。我不确定这是从哪里来的,我的猜测是PHPUnit或XDebug包含它。显然这不是我自己的代码库的一部分,所以我对它不感兴趣。它正在影响我的项目产生的整体指标。有没有办法从报告中排除此文件?

非常感谢,

编辑

答案是使用可以包含过滤器黑名单的 phpunit xml 配置文件。我将在 6 小时内正确回答我的问题(stackoverflow 让我等待 8 小时才能回答我的问题!

经过一番谷歌搜索,我发现答案是为phpunit创建一个配置文件,您可以在其中从代码覆盖率报告中排除特定文件或目录。

"<过滤器>元素及其子元素可用于配置代码覆盖率报告的黑名单和白名单。"

<filter>
  <blacklist>
    <directory suffix=".php">/path/to/files</directory>
    <file>/path/to/file</file>
    <exclude>
      <directory suffix=".php">/path/to/files</directory>
      <file>/path/to/file</file>
    </exclude>
      </blacklist>
  <whitelist addUncoveredFilesFromWhitelist="true">
    <directory suffix=".php">/path/to/files</directory>
    <file>/path/to/file</file>
    <exclude>
      <directory suffix=".php">/path/to/files</directory>
      <file>/path/to/file</file>
    </exclude>
  </whitelist>
</filter>

然后使用以下标志调用 PHPUnit:

phpunit -c config.xml

有关配置文件的更多信息,请参见此处:

http://www.phpunit.de/manual/current/en/appendixes.configuration.html