Maybe I missed out on a detail, but I wrote a small test case for a singleton _clone method yet it is not showing up as tested in the code coverage report.
/**
* @covers ErrorHandling::__clone
*/
public function test__cloneNotCloneable(){
$class = new ReflectionClass('ErrorHandling');
$method = $class->getMethod('__clone');
self::assertTrue($method->isFinal(), '__clone method is not final.');
self::assertTrue($method->isPrivate(), '__clone method is not private.');
}
The __clone method is the usual private/final __clone() of a regular (evil) singleton.
/**
* Define __clone as final and private to dissallow cloning.
*/
private final function __clone(){}
I know it's probably overkill testing for this, but the code-coverage report is sort of the graphical representation of a job 'well done'. Is there a way to have this method marked as covered in the code coverage report?
The @covers
tag tells PHPUnit that you intend to test the named method; it does not mark the method as having been tested. Since you cannot call the method, Xdebug won't tell PHPUnit that its code has been executed, and it will never be covered in your report.
Your best bet is to tell PHPUnit to ignore the method in the report by using the @codeCoverageIgnore
docblock tag.
/**
* Define __clone as final and private to dissallow cloning.
*
* @codeCoverageIgnore
*/
private final function __clone() { }
You can ignore any range of lines by enclosing them in a pair of one-line start/stop comments.
// @codeCoverageIgnoreStart
private final function __clone() { }
// @codeCoverageIgnoreEnd
Finally, you can ignore a single line by adding a one-line comment to it.
private final function __clone() { } // @codeCoverageIgnore
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