Error Identifier: phpunit.coversInterface
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;
interface LoggerInterface
{
public function log(string $message): void;
}
/**
* @covers \LoggerInterface
*/
class LoggerTest extends TestCase
{
public function testLog(): void
{
// ...
}
}
This rule is provided by the phpstan-phpunit extension.
Why is it reported? #
The @covers annotation references an interface. PHPUnit code coverage tracks the execution of concrete code, and interfaces do not contain executable code. Covering an interface is not meaningful because there is no code to measure coverage for.
How to fix it #
Change the @covers annotation to reference the concrete class that implements the interface:
<?php declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
/**
- * @covers \LoggerInterface
+ * @covers \FileLogger
*/
class LoggerTest extends TestCase
{
public function testLog(): void
{
// ...
}
}
How to ignore this error #
You can use the identifier phpunit.coversInterface to ignore this error using a comment:
// @phpstan-ignore phpunit.coversInterface
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.coversInterface