Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude a pattern from code coverage?

As far as I understand one can exclude files and directories from code coverage by name but is it possible to exclude by matching a pattern ?

I ask this because I don't want to mention the path to all my view sub-folders one by one in my phpunit.xml. Something like <exclude>*/view</exclude> perhaps ? By this I mean "exclude all view folders wherever you reach them".

like image 846
Ashkan Kh. Nazary Avatar asked Mar 23 '23 07:03

Ashkan Kh. Nazary


1 Answers

Yes, you can specify file patterns to exclude from Code Coverage. Here is a sample of one of my PHPUnit.xml.dist files.

<!-- Add files not covered with tests into Code Coverage Analysis -->
<filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
        <directory suffix=".class">.</directory>
        <directory suffix=".fn">.</directory>
        <directory suffix=".php">.</directory>
        <exclude>
            <directory>ExternalLibraries</directory>
        </exclude>
    </whitelist>
</filter>

The PHPUnit Manual for Code Coverage and then the Including/Excluding files for Code Coverage sections of the manual will show you additional options to specify the file patterns by directory or name.

like image 169
Steven Scott Avatar answered Apr 01 '23 01:04

Steven Scott