website/errors/phpunit.coversDuplicate.md
<?php declare(strict_types = 1);
use PHPUnit\Framework\TestCase;
/**
* @covers \App\UserService
*/
class UserServiceTest extends TestCase
{
/**
* @covers \App\UserService
*/
public function testCreate(): void
{
// ...
}
}
There are two cases where this identifier is reported:
@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.@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.
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
{
// ...
}