1

I'm just unit testing a single file and although it's the only one to get unit tested (good), code coverage is done on more than just this single file (bad). It covers some files in my PEAR directory for some reason I can't understand yet, so all my coverage stats are distorted.

So I'm trying to eliminate these extra files, but can't get the format right for an absolute directory:

<phpunit>

<testsuites>
  <testsuite name="My Test Suite">
    <file>AntProxyTest.php</file>
  </testsuite>
</testsuites>

<logging>
  <log type="coverage-html" target="/tmp/report" charset="UTF-8"
       yui="true" highlight="false"
       lowUpperBound="35" highLowerBound="70"/>
</logging>

<filter>
  <blacklist>
     <directory suffix=".php">c:\php\pear</directory>
   </blacklist>
</filter>

</phpunit>

is not excluding as I wish, either are forward slashes or file://c:/php/pear.

2 Answers 2

4

I assume phpunit has an issue with getting that path right on windows since i couldn't reproduce that on linux. (Using an absolute and an relative path worked fine).

Also i've heard people talk about that issue with filtering and pathes on windows.

So my first suggestion would be to just use a whitelist. I've created a small project that includes code from different folders (and all showed up in the code coverage).

But after setting this whitelist:

<filter>
  <whitelist>
     <directory suffix=".php">.</directory>
  </whitelist>
</filter>

only the code from that folder (or your file if you really one have one) show up in the coverage report.

Sign up to request clarification or add additional context in comments.

5 Comments

We use a whitelist as well, specified programmatically in each project's bootstrap.php. Note that a whitelist overrides a blacklist; they cannot be combined.
@David I'd be interested in hearing/reading more about the approach you are using and your reasons behind it. Maybe in the chat if we happen to meet? :)
I'll give whitelisting a go, but my understanding of it was not to restrict but selectively override the blacklist. Another thing, the phpunit manual says the filter tag in the xml file is for filtering files for code coverage, yet it says the --filter command line option is for choosing which files to test. Ideally I'd rather use the command line option to whitelist/blacklist but it seems for a different purpose.
The only reason we do it that way is that it was the first thing that worked. ;) I was more comfortable doing the configuration in PHP rather than XML and it allows us to use the same phpunit.xml across all projects.
@stebbo You can't white&blacklist over the commandline, you can do it programmatically using those funcitons but they will go away in future versions of phpunit. So going with the xml is your best bet. And as far as I've understood it the "whitelist" means "use all code listed in the whitelist and ONLY that code".
1

I managed to catch Sebastian on IRC, co-incidentally someone else was also having problems with blacklisting. Sebastian indicated that these PEAR files I'm seeing included is a known issue and will be fixed next version.

As edorian above indicated, Sebastian also said it's a best practice to whitelist what you want anyway, and in doing so, this problem will disappear.

Comments

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.