Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude files / code blocks from code coverage with Netbeans / PHPStorm / PHPUnit integration

Requirements:

  • Netbeans with PHPUnit(6.9)
  • EDIT: Same applies, for example, to PHPStorm

How to:

  • Exclude lines from code coverage.
  • Exclude code blocks (lines) from code coverage.
like image 324
Alfred Avatar asked Jul 08 '10 01:07

Alfred


People also ask

How do I ignore code blocks in the code coverage report?

More information can by found in the PHPUnit Documentation under the Ignoring code blocks heading. If you are trying to achieve 100% code coverage but have one or more lines that you cannot test, you can surround them with special annotations. They will be ignored in the code coverage report.

How do I reduce the crap Index in PHPUnit?

The CRAP index can be lowered by writing tests and by refactoring the code to lower its complexity. It is mandatory to configure a filter for telling PHPUnit which sourcecode files to include in the code coverage report.

How do I exclude a class from code coverage?

Excluding Code From Code Coverage. The easiest way to exclude code from code coverage analysis is to use the ExcludeFromCodeCoverage attribute. This attribute tells tooling that a class or some of its members are not planned to be covered with the tests.

Why is there no code coverage driver available in PHPUnit?

If you see a warning while running tests that no code coverage driver is available, it means that you are using the PHP CLI binary (php) and do not have Xdebug or PCOV loaded. PHPUnit can generate an HTML-based code coverage report as well as XML-based logfiles with code coverage information in various formats (Clover, Crap4J, PHPUnit).


1 Answers

To ignore method code blocks:

/**  * @codeCoverageIgnore  */ function functionToBeIgnored() {     // function implementation } 

To ignore class code blocks:

/**  * @codeCoverageIgnore  */ class Foo {     // class implementation } 

And as @david-harkness said, to ignore individual lines:

// @codeCoverageIgnoreStart print 'this line ignored for code coverage'; // @codeCoverageIgnoreEnd 

More information can by found in the PHPUnit Documentation under the Ignoring code blocks heading.

like image 84
bnp887 Avatar answered Sep 20 '22 19:09

bnp887