0

enter image description here

My 'test project' contains only the Application.php and the ApplicationTest.php but the phpunit collect the coverage information about composer autoloader files also, which is wrong. How can I exclude the autoloader files from the coverage report?

2 Answers 2

5

When creating the configuration for code coverage, you'll almost always set the 'whitelist' in the phpunit.xml file to only cover your main source files - this also speeds up the test-run, as it's not having to also run code-coverage of all the library files in the vendor/ directory (because that can take a long time).

<filter>
  <whitelist processUncoveredFilesFromWhitelist="true"
             addUncoveredFilesFromWhitelist="false">
    <!-- only collect code coverage in src/**/*.php files -->
    <directory suffix=".php">./src</directory>
    <exclude>
       <!-- directories/files to not cover (within src/) -->
       <directory suffix=".php">./src/*/*Bundle/Resources</directory>
       <directory suffix=".php">./src/*Bundle/Resources</directory>
       <directory suffix=".php">./src/tests/</directory>
    </exclude>
  </whitelist>
</filter>
Sign up to request clarification or add additional context in comments.

Comments

3

Configure a whitelist and do not add the autoloader to it.

Comments

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.