Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude base directory from PHPUnit Code Coverage

How do I exclude the base directories from PHPUnit's Code Coverage?

This is my phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="include.php"
         stopOnError="false"
         stopOnFailure="false"
         stopOnIncomplete="false"
         stopOnSkipped="false">
    <testsuite name="MyProject">
        <directory>classes/*</directory>
    </testsuite>
    <logging>
        <log type="coverage-html" target="../reports/coverage" charset="UTF-8" yui="true" highlight="false" lowUpperBound="35" highLowerBound="70"/>
        <log type="coverage-xml" target="../reports/coverage.xml"/>
        <log type="test-xml" target="../reports/logfile.xml" logIncompleteSkipped="false"/>
        <log type="testdox-html" target="../reports/testdox.html"/>
        <log type="testdox-text" target="../reports/testdox.txt"/>
    </logging>
</phpunit>

When it output it includes all the base directories like:

c:\work\some\path\MyProject

How can I make it only include the ...\MyProject\* in the Code Coverage output?

like image 424
Petah Avatar asked Dec 13 '12 23:12

Petah


1 Answers

Your answers doesn't really describe your project layout but I assume what you are looking for is:

Including and Excluding Files for Code Coverage

This allows you to specify a whitelist of files that PHPUnit will care about when generating code coverage.

Everything that isn't on that white list will not be shown in the report.

To do so add the following somewhere top level:

<filter>
  <whitelist processUncoveredFilesFromWhitelist="true">
    <directory suffix=".php">.../MyProject/</directory>
  </whitelist>
</filter>
like image 175
edorian Avatar answered Oct 17 '22 23:10

edorian