11

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

1 Answer 1

11

--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>
Sign up to request clarification or add additional context in comments.

3 Comments

For better or worse, phpunit.xml is becoming the only real method for handling test groupings.
This answer is all about how to include directories (whitelist), but how would you exclude directories? The opposite (blacklist) does not work.
both absolute and relative paths work for the <filter> directives. there's also a <blacklist> available if that's more your style.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.