Skip to content

[PHPUnit90] Skip non-literal expected value in AssertRegExpRector - #819

Merged
samsonasik merged 2 commits into
rectorphp:mainfrom
alies-dev:fix-assert-regexp-non-literal-expected
Nov 3, 2026
Merged

samsonasik merged 2 commits into
rectorphp:mainfrom
alies-dev:fix-assert-regexp-non-literal-expected

Conversation

@alies-dev

Copy link
Copy Markdown
Contributor

AssertRegExpRector crashes with ShouldNotHappenException when the expected value of assertSame()/assertEquals() is not an int literal or a constant, for example in a data-provider test:

$this->assertSame($expectMatch ? 1 : 0, preg_match('/.../', $string));
System error: "Look at "Rector\PHPUnit\PHPUnit90\Rector\MethodCall\AssertRegExpRector::resolveOldCondition()"

The rule now skips these calls. It also skips int literals other than 0 and 1: assertSame(2, preg_match(...)) matched neither rename branch, so the rule moved the preg_match() arguments up and left an assertSame() with the regex as its expected value.

@alies-dev
alies-dev marked this pull request as ready for review November 3, 2026 18:52
@samsonasik
samsonasik merged commit d32a17a into rectorphp:main Nov 3, 2026
8 checks passed
@samsonasik

Copy link
Copy Markdown
Member

Thank you @alies-dev

@alies-dev
alies-dev deleted the fix-assert-regexp-non-literal-expected branch November 3, 2026 22:51
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.

2 participants