Skip to content

[CodeQuality] Verify assert method name exists on Assert class via reflection#720

Merged
TomasVotruba merged 2 commits into
mainfrom
assert-method-reflection-verify
Jul 13, 2026
Merged

[CodeQuality] Verify assert method name exists on Assert class via reflection#720
TomasVotruba merged 2 commits into
mainfrom
assert-method-reflection-verify

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

AssertTrueFalseToSpecificMethodRector mapped file_exists/is_dir to assertFileNotExists()/assertDirectoryNotExists(). These were renamed in newer PHPUnit versions — the produced call no longer exists on the Assert class, breaking the test.

Now the rule verifies the target method exists on PHPUnit\Framework\Assert via reflection, and falls back to the current name when the legacy one is gone.

Before

$this->assertFalse(file_exists($file));

on PHPUnit 12 became:

-$this->assertFalse(file_exists($file));
+$this->assertFileNotExists($file); // method removed → fatal

After

-$this->assertFalse(file_exists($file));
+$this->assertFileDoesNotExist($file);

Renames covered:

legacy current
assertFileNotExists assertFileDoesNotExist
assertDirectoryNotExists assertDirectoryDoesNotExist

When the legacy method still exists (older PHPUnit), it is kept as-is.

@TomasVotruba TomasVotruba merged commit 0629d20 into main Jul 13, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the assert-method-reflection-verify branch July 13, 2026 09:24
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