Requirements:
How to:
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.
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With