My test case looks like this:
class FooTest extends PHPUnit_Framework_TestCase {
/** @covers MyClass::bar */
function testBar()
{
$result = MyClass::bar();
$this->assertSomething($result);
}
}
Now, the test itself works perfectly fine but code coverage complains with:
PHP_CodeCoverage_Exception: Trying to @cover not existing method "MyClass::bar *//**".
Any ideas?
Correction
The issue was not within PHPUnit its self but withing PHP_CodeCoverage. The parsing logic is somewhat duplicated there and the PHPUnit fix (see below) didn’t help in that case.
The patch to fix this for 3.6 is:
I’ve opened a ticket for this at
https://github.com/sebastianbergmann/php-code-coverage/issues/121.Until this fix is released (and chances are that only happens for PHPUnit 3.7) you need to use the three liner.
Old Answer:
Old versions of PHPUnit didn’t work with one line annotations.
PHPUnit tried to find a class/method combination named:
"MyClass::bar *//**"Using a three line annotation works with all versions
I fixed this
PHPUnit 3.6.4.See
Issue 328.From
PHPUnit >= 3.6.4your code should work just fine.