Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit - exclude some directories from code coverage in command line

I am working on project that based on Yii framework, and we have many tests that we added programatically to test suite, so we are not using phpunit.xml file to configure tests.

The question is, how I would exclude some directories from code coverage reports(for example Yii folder). The most solutions I found are based on blacklist/whitelists configuration option in xml file.

I also found that there is --filter option for phpunit command, but I couldn't find any example how I could use it to exclude complete directory(or few of them).

like image 984
Ivica Avatar asked Feb 23 '12 11:02

Ivica


1 Answers

--filter is used to filter the tests that are execute in the current run of phpunit.

You can use it so say "only execute --filter MyTestClass or --filter testStuffThatBrokeAndIOnlyWantToRunThatOneSingleTest but is has nothing to do with code coverage.

The --filter has nothing to do with the <filter> in the xml configuration even so they have the same name :)


The only way to exclude files from the code coverage report is to use a whitelist/blacklist.

If you use whitelist on your own source folder that should do the job in most of the cases.

Whitelist docs:

http://phpunit.de/manual/current/en/phpunit-book.html#appendixes.configuration.blacklist-whitelist

Sample:

  <filter>
    <whitelist addUncoveredFilesFromWhitelist="true">
      <directory suffix=".php">src</directory>
    </whitelist>
  </filter>
like image 129
edorian Avatar answered Oct 03 '22 10:10

edorian