Skip to content

[PHPUnit60] Add DoesNotPerformAssertions attribute directly and skip traits - #765

Merged
TomasVotruba merged 1 commit into
mainfrom
add-does-not-perform-assertions-attribute
Aug 9, 2026
Merged

[PHPUnit60] Add DoesNotPerformAssertions attribute directly and skip traits#765
TomasVotruba merged 1 commit into
mainfrom
add-does-not-perform-assertions-attribute

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Two changes to AddDoesNotPerformAssertionToNonAssertingTestRector:

1) Add the attribute directly, when it exists

If PHPUnit\Framework\Attributes\DoesNotPerformAssertions is available (PHPUnit 10+), the attribute is added instead of the annotation. Projects on older PHPUnit keep getting the docblock annotation.

 final class SomeTest extends TestCase
 {
-    public function test()
+    #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
+    public function test()
     {
         $nothing = 5;
     }
 }

Previously this always produced:

    /**
     * @doesNotPerformAssertions
     */

2) Skip traits

A trait method has no owning class, so there is no way to tell whether the class using it asserts elsewhere. Adding the attribute there can silence a real assertion check.

trait SomeNonAssertingTrait
{
    // left as is
    public function testSomething()
    {
        $nothing = 5;
    }
}

…traits in AddDoesNotPerformAssertionToNonAssertingTestRector
@TomasVotruba
TomasVotruba merged commit 547b419 into main Aug 9, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the add-does-not-perform-assertions-attribute branch August 9, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant