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

2

6

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?

Raquel answered 26/8, 2010 at 22:16 Comment(0)
U
10

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

Unbound answered 7/9, 2010 at 17:14 Comment(0)
C
0

I think the filter note of the configuration xml file must be wrapped by the loggin node:

Like this:

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

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

        <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>

Charlenecharleroi answered 5/10, 2012 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.