Menu

← Back to phpunit.*

Error Identifier: phpunit.coversMethod

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\Calculator::nonExistentMethod
 */
class CalculatorTest extends TestCase
{
	public function testAdd(): void
	{
		$calc = new \App\Calculator();
		$this->assertSame(3, $calc->add(1, 2));
	}
}

Why is it reported? #

This error is reported by the phpstan-phpunit extension.

The @covers annotation references a method that does not exist on the specified class. This means the code coverage report will not correctly attribute coverage, and the annotation may indicate a typo or an outdated reference to a method that has been renamed or removed.

How to fix it #

Fix the method name in the @covers annotation to reference an existing method:

 <?php declare(strict_types = 1);
 
 /**
- * @covers \App\Calculator::nonExistentMethod
+ * @covers \App\Calculator::add
  */
 class CalculatorTest extends TestCase
 {
 	public function testAdd(): void
 	{
 		$calc = new \App\Calculator();
 		$this->assertSame(3, $calc->add(1, 2));
 	}
 }

If the @covers annotation references a class or function that cannot be found, make sure to use a fully qualified name (starting with \).

How to ignore this error #

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

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

Rules that report this error #

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

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.