Menu

← Back to phpunit.*

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 @coversDefaultClass is 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

Rules that report this error #

  • PHPStan\Rules\PHPUnit\ClassCoversExistsRule [1] [2] phpstan/phpstan-phpunit
  • PHPStan\Rules\PHPUnit\ClassMethodCoversExistsRule [1] [2] [3] phpstan/phpstan-phpunit

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.