Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can PHPUnit code coverage ignore my autoloader?

I have a bootstrap in my phpunit config that runs the Zend\Loader\StandardAutoloader.php. I can get PHPUnit code coverage to ignore it when I add

<filter>
   <blacklist>
       <directory suffix=".php">/absolute/path/to/zf</directory>
   </blacklist>
</filter>

to the PHPUnit config XML file. But I have to specify an absolute path. I want it to be a relative path but PHPUnit is not ignoring the Zend folder in the code coverage. I don't want to add different location for when I'm working at home and I don't want other developers adding their own paths. The Zend Framework is in the php.ini include_path setting but this does not work:

<filter>
   <blacklist>
       <directory suffix=".php">./Zend</directory>
   </blacklist>
</filter>

Any suggestions?

like image 326
Jeebs24 Avatar asked Dec 21 '22 19:12

Jeebs24


2 Answers

You can exclude paths from the code coverage with the <exclude>...</exclude> directive within your <filter><whitelist>:

<filter>
    <whitelist>
        <directory suffix=".php">../src/library/</directory>
        <!-- add more directories -->
        <exclude>
            <directory suffix=".phtml">./src/application/</directory>
            <directory suffix=".php">./Zend/</directory>
            <!-- add more directories with relative or absolute path -->
        </exclude>
    </whitelist>
</filter>    
like image 190
ByteNudger Avatar answered Dec 28 '22 08:12

ByteNudger


Actually this can be done with a blacklist as well. The path needs to be relative to your tests directory.

This did the trick in my project:

<filter>
    <blacklist>
        <directory suffix=".php">../../../cache</directory>
    </blacklist>
</filter>
like image 33
Michael Thessel Avatar answered Dec 28 '22 10:12

Michael Thessel