8

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?

2
  • 3
    Did you ever solve this? I'd like to know how to do this too but the person who wrote the answer misunderstood your question unfortunately. Commented Dec 10, 2013 at 18:48
  • 1
    @Julian yea I did, but it was a while ago so I will have to dig it up. Commented Dec 10, 2013 at 19:59

1 Answer 1

5

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry if I was not clear. I do not want to exclude anything. I only want to remove the base directory from the code coverage report. So for example right now if I run my tests, and I open the CC report, I have to click at least 5 links to get to anything meaning full. C:\ -> work -> projects -> websites -> MyProject -> classes. I just want to have at the top level MyProject so I can click MyProject -> classes.
The <filter> in question should do that for you as far as I'm aware. Might be an issue with pathes on windows or something strange but in general telling phpunit "this is the root folder for coverage" is done that way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.