Menu

← Back to phpunit.*

Error Identifier: phpunit.coversClass

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);

use PHPUnit\Framework\TestCase;

/**
 * @coversDefaultClass App\NonExistentService
 */
class MyTest extends TestCase // ERROR: @coversDefaultClass references an invalid class App\NonExistentService.
{
	public function testSomething(): void
	{
		$this->assertTrue(true);
	}
}

Why is it reported? #

This rule is provided by the phpstan-phpunit extension.

The @coversDefaultClass annotation on the test class references a class that does not exist. This annotation is used by PHPUnit to track code coverage. When the referenced class cannot be found, the coverage data will be incorrect and PHPUnit may produce warnings or errors when generating coverage reports.

This typically happens when the class has been renamed, moved to a different namespace, or deleted without updating the test annotations.

How to fix it #

Update the annotation to reference the correct class:

 <?php declare(strict_types = 1);
 
 use PHPUnit\Framework\TestCase;

 /**
- * @coversDefaultClass App\NonExistentService
+ * @coversDefaultClass App\UserService
  */
 class MyTest extends TestCase
 {
 	public function testSomething(): void
 	{
 		$this->assertTrue(true);
 	}
 }

Make sure to use the fully qualified class name (including the namespace) in the @coversDefaultClass annotation.

How to ignore this error #

You can use the identifier phpunit.coversClass to ignore this error using a comment:

// @phpstan-ignore phpunit.coversClass
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.coversClass

Rules that report this error #

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.