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

Alfred picture Alfred · Jul 8, 2010 · Viewed 17.5k times · Source

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.

Answer

bnp887 picture bnp887 · Feb 9, 2014

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.