Skip to content

[CodeQuality] Use static Assert:: call for assert() inside anonymous class#684

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-func
Jun 26, 2026
Merged

[CodeQuality] Use static Assert:: call for assert() inside anonymous class#684
TomasVotruba merged 1 commit into
mainfrom
tv-func

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Improves AssertFuncCallToPHPUnitAssertRector.

assert() inside an anonymous class has no test-case $this, so converting to $this->assertTrue() would call the method on the anonymous class instead of the TestCase. This now emits a static \PHPUnit\Framework\Assert::assertTrue() call instead, mirroring the existing static-closure handling.

Before

public function some($response)
{
    return new class($response) {
        public function __construct($response)
        {
            assert((bool) $response);
        }
    };
}

After

public function some($response)
{
    return new class($response) {
        public function __construct($response)
        {
            \PHPUnit\Framework\Assert::assertTrue((bool) $response);
        }
    };
}

Added fixture assert_inside_anonymous_class.php.inc.

…class in AssertFuncCallToPHPUnitAssertRector
@TomasVotruba TomasVotruba enabled auto-merge (squash) June 26, 2026 16:12
@TomasVotruba TomasVotruba merged commit b1f6d13 into main Jun 26, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the tv-func branch June 26, 2026 16:13
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