Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

phpunit clover from some particular directories, not full clover. Is it possible?

Why do I need this? I'm running the tests on symfony project (and using Zend fw) and phpunit generates clover for all affected files. But I don't want see coverage for symfony and Zend libs (and all another third party ones). I wish see coverage for my code only. Or may be this should do clover viewer? I'm using the clover plugin for hudson, but it does not support viewing for particular sources. The clover plugin shows, that my code covered only 20%, that is incorrect because it considered symfony and Zend libs too.

Btw, may be there are another ways to get this?

like image 687
smileua Avatar asked Aug 26 '10 22:08

smileua


1 Answers

You need to create a configuration file for phpunit, inside that configuration file you can exclude specific files or directories from code coverage.

Example file looks like this:

<phpunit stopOnFailure="false">
    <testsuite name="Name">
    </testsuite>

<filter>
    <whitelist>
            <directory suffix=".php">../php</directory>
            <exclude>
                    <file>../php/somefile.php</file>
                    <directory suffix=".php">../php/pdf</directory>
            </exclude>
    </whitelist>
</filter>

<logging>


        <log type="coverage-html" target="target-dir/coverage" charset="UTF-8" yui="true" highlight="true"/>
        <log type="coverage-clover" target="target-dir/build/logs/clover.xml"/>
</logging>

</phpunit>

With the above file everything under ../php (this is relative from the directory where tests are in and phprun is executed from) is included in code coverage, except the file ../php/somefile.php and all files with extension .php from directory ../php/pdf

Name this file phpunit.xml, put it into the same directory where you run the tests from. Them, if you run phpunit, it will pick the conf up.

If you cannot use this particular filename, you can give name from the command line

phpunit --configuration yourconf.xml

More details about phpunit configuration file is available at: http://phpunit.de/manual/3.7/en/appendixes.configuration.html

like image 138
Anti Veeranna Avatar answered Dec 07 '22 07:12

Anti Veeranna