Menu
Error Identifier: phpunit.covers
Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.
Code example #
<?php declare(strict_types = 1);
/**
* @covers \App\NonExistentClass
*/
class MyTest extends \PHPUnit\Framework\TestCase
{
public function testSomething(): void
{
// ...
}
}
Why is it reported? #
The @covers or @coversDefaultClass annotation references an invalid class, function, or method. This can happen when:
- The referenced class or function does not exist
- The annotation value is empty
- The class name is not fully qualified (missing leading backslash)
- A
@coversDefaultClassis used on a method instead of a class
This rule is provided by the phpstan-phpunit extension.
How to fix it #
Ensure the @covers annotation references an existing, fully qualified class or function:
<?php declare(strict_types = 1);
/**
- * @covers \App\NonExistentClass
+ * @covers \App\ExistingClass
*/
class MyTest extends \PHPUnit\Framework\TestCase
{
public function testSomething(): void
{
// ...
}
}
If the class name is not fully qualified, add the leading backslash:
<?php declare(strict_types = 1);
/**
- * @covers MyClass
+ * @covers \App\MyClass
*/
class MyTest extends \PHPUnit\Framework\TestCase
{
}
How to ignore this error #
You can use the identifier phpunit.covers to ignore this error using a comment:
// @phpstan-ignore phpunit.covers
codeThatProducesTheError();
You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:
parameters:
ignoreErrors:
-
identifier: phpunit.covers