Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Cruorzy's avatar

Pest - Targeted multiple times by the same Cover attribute

Not sure exactly with what version this came with, but upgraded to v4 of pest and run my test.

Getting quite some warnings.

  Class App\Http\Controllers\ProfileController is targeted multiple times by the same "Covers" attribute```

Can't find much about it, any ideas?


ProfileTest.php
0 likes
2 replies
LaryAI's avatar
Level 58

Certainly! This warning in Pest v4:

Class App\Http\Controllers\ProfileController is targeted multiple times by the same "Covers" attribute

means that the #[Covers(...)] attribute is being applied more than once for the same class or method in your tests. Pest (and PHPUnit) uses the #[Covers] attribute to indicate which classes or methods are being tested for code coverage reporting. If you annotate multiple tests or test classes with the same #[Covers] for the same target, Pest will emit this warning.

How to Fix:

  1. Check for Duplicate Covers Attributes

    Open your ProfileTest.php and look for multiple usages of the same #[Covers(App\Http\Controllers\ProfileController::class)] attribute, either at the class level or on individual test methods.

    For example, you might have:

    #[Covers(App\Http\Controllers\ProfileController::class)]
    class ProfileTest extends TestCase
    {
        #[Covers(App\Http\Controllers\ProfileController::class)]
        public function test_profile_update()
        {
            // ...
        }
    }
    

    Here, the #[Covers] attribute is applied both to the class and the method, which is redundant.

  2. Remove Redundant Attributes

    Only apply the #[Covers] attribute once per target. If you want all tests in the class to cover the controller, put it on the class. If only specific methods cover it, put it only on those methods.

    Example:

    #[Covers(App\Http\Controllers\ProfileController::class)]
    class ProfileTest extends TestCase
    {
        public function test_profile_update()
        {
            // ...
        }
    }
    

    Or, if only some methods cover it:

    class ProfileTest extends TestCase
    {
        #[Covers(App\Http\Controllers\ProfileController::class)]
        public function test_profile_update()
        {
            // ...
        }
    }
    
  3. Check for Multiple Test Files

    If you have multiple test files all using the same #[Covers] for the same class, Pest will warn you. Consider if you need the attribute in all those files, or if you can organize your tests differently.

Summary:
Remove duplicate #[Covers] attributes targeting the same class or method in your test files. Apply them only where necessary.

References:

Let me know if you need help reviewing your specific test file!

Cruorzy's avatar

ProfileTest.php

Please or to participate in this conversation.