Menu

← Back to phpunit.*

Error Identifier: phpunit.coversDuplicate

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;

/**
 * @covers \App\UserService
 */
class UserServiceTest extends TestCase
{
	/**
	 * @covers \App\UserService
	 */
	public function testCreate(): void
	{
		// ...
	}
}

Why is it reported? #

There are two cases where this identifier is reported:

  1. A method-level @covers annotation references the same class or method that is already covered by a class-level @covers annotation. The method-level annotation is redundant because the class-level annotation already covers it.
  2. The @coversDefaultClass annotation is defined multiple times on the same class.

This rule is provided by the phpstan-phpunit package.

In the example above, both the class and the method have @covers \App\UserService, making the method-level annotation redundant.

How to fix it #

Remove the redundant method-level @covers annotation:

 /**
  * @covers \App\UserService
  */
 class UserServiceTest extends TestCase
 {
-	/**
-	 * @covers \App\UserService
-	 */
 	public function testCreate(): void
 	{
 		// ...
 	}
 }

If the method is intended to cover a specific method rather than the whole class, be more specific:

 	/**
-	 * @covers \App\UserService
+	 * @covers \App\UserService::create
 	 */
 	public function testCreate(): void
 	{
 		// ...
 	}

How to ignore this error #

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

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

Rules that report this error #

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.