Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
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 Harkness Apr 7 '11 at 20:20
    
@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? :) –  edorian Apr 7 '11 at 21:34
    
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. –  jontyc Apr 7 '11 at 22:58
    
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. –  David Harkness Apr 7 '11 at 23:00
    
@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". –  edorian Apr 8 '11 at 8:03
add comment
up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.