Force Exclude files from PHPUnit Code Coverage

The correct way to exclude certain files from the coverage report in more or less recent versions of PHPUnit is to use <exclude> directive instead of <blacklist>. E.g.:

  <filter>
    <whitelist>
      <directory suffix=".php">src/</directory>
        <exclude>
           <directory suffix=".php">src/Legacy/</directory>
           <file>src/example.php</file>
        </exclude>
    </whitelist>
  </filter>

For more recent PHPUnit using newest schema this will be:

  <coverage>
    <include>
      <directory suffix=".php">src/</directory>
    </include>
    <exclude>
      <directory suffix=".php">src/Legacy/</directory>
      <file>src/example.php</file>
    </exclude>
  </coverage>

Ok, so I thought that you can have either the blacklist section OR the whitelist section, turns out you can have both, so I blacklisted those folders and it worked:

    <filter>
        <blacklist>
              <directory>./lib/vendor</directory>
              <directory>./lib/helper</directory>
        </blacklist>
    </filter>

Observation: whitelisting (the directories you want to be included in the code coverage) makes the phpunit execution of the entire test suite quicker, compared to blacklisting.

<filter>
    <whitelist>
          <directory>/my/project/directory/to/be/covered</directory>
          ....
    </whitelist>
</filter>

Tested with: PHPUnit 4.5.0 and PHP 5.5.9