Code coverage and libraries

January 15, 2014
By

Phpstorm defaults to computing code coverage reports for unit tests, bbut this can become an issue if you use big third party libraries.

The solution is simple and is to blacklist library files in phpunit configuration

You need to pay attention to a detail though: whitelist block (if present) overrides the blacklist one in phpunit conf, so if you happen to have one like the following (taken from Symfony 2 default config)

<filter>
  <whitelist>
   <directory>../src</directory>
   <exclude>
    <directory>../src/*/*Bundle/MyLibrary</directory>
    <directory>../src/*/*Bundle/Resources</directory>
    <directory>../src/*/*Bundle/Tests</directory>
    <directory>../src/*/Bundle/*Bundle/Resources</directory>
    <directory>../src/*/Bundle/*Bundle/Tests</directory>
   </exclude>
  </whitelist>
 </filter>

you need to add the path to the “exclude” block ¬†, i.e. if you keep the library somewhere under the src/* folder

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.