Skip to content

[PHPUnit60] Skip imported PHPUnit assert functions in AddDoesNotPerformAssertionToNonAssertingTestRector - #767

Merged
TomasVotruba merged 1 commit into
mainfrom
skip-imported-assert-functions
Aug 12, 2026
Merged

[PHPUnit60] Skip imported PHPUnit assert functions in AddDoesNotPerformAssertionToNonAssertingTestRector#767
TomasVotruba merged 1 commit into
mainfrom
skip-imported-assert-functions

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9848

AddDoesNotPerformAssertionToNonAssertingTestRector only looked for $this->assert*() method calls and self::assert*() static calls. Assertions called as standalone functions from the PHPUnit\Framework namespace were invisible to it, so tests using them were wrongly marked as non-asserting.

 use PHPUnit\Framework\TestCase;

 use function PHPUnit\Framework\assertNotNull;

 final class SomeTest extends TestCase
 {
-    #[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
     public function testSomething(): void
     {
         assertNotNull(true);
     }
 }

AssertCallAnalyzer now also treats a FuncCall resolved to PHPUnit\Framework\assert* (and the other known assert prefixes) as an assertion, whether imported via use function or fully qualified.

@TomasVotruba
TomasVotruba merged commit aa61352 into main Aug 12, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the skip-imported-assert-functions branch August 12, 2026 10:05
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.

AddDoesNotPerformAssertionToNonAssertingTestRector falsely detected in v2.6.2

1 participant