Search code examples
phpphpunitjenkinscode-coverageclover

Clover PHPUnit coverage report is including coverage for unwanted file


I have just set up CloverPHP into my Jenkins job.

I am using PHPUnit to generate the clover report and it seems to all be working apart from the coverage report which is showing the file

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

as part of the report. I'm not sure where this is coming from, my guess is that PHPUnit or XDebug is including it. Obviously this is not part of my own code base so I am not interested in it. It is affecting the overall metrics produced by my project. Is there a way of excluding this file from the report?

Many thanks, ns

Edit

The answer is to use a phpunit xml configuration file which can contain a filter blacklist. I will answer my question properly in 6 hours (stackoverflow is making me wait 8 hours before answering my question!)


Solution

  • After some googling I found that the answer is to create a configuration file for phpunit, where you can exclude specific files or directories from the code coverage report.

    "The < filter > element and its children can be used to configure the blacklist and whitelist for the code coverage reporting."

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

    Then call PHPUnit using the flag:

    phpunit -c config.xml
    

    More information on the configuration file can be found here:

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