Skip to content

[CodeQuality] Skip nested value compare in CallbackSingleAssertToSimplerRector#718

Merged
TomasVotruba merged 2 commits into
mainfrom
skip-nested-compare-callback-assert
Jul 13, 2026
Merged

[CodeQuality] Skip nested value compare in CallbackSingleAssertToSimplerRector#718
TomasVotruba merged 2 commits into
mainfrom
skip-nested-compare-callback-assert

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

CallbackSingleAssertToSimplerRector converts a callback() closure with a sole assertSame() into an equalTo() matcher. But equalTo() matches against the whole closure argument, so the conversion is only correct when the asserted value is the plain closure parameter.

When the assert compares a nested value (e.g. $args['label']), converting to equalTo() would wrongly match the entire argument. Now skipped.

->with($this->callback(function (array $args): bool {
    $this->assertSame($args['label'], 'Test Label');

    return true;
}));

Stays untouched (previously wrongly collapsed to ->with($this->equalTo('Test Label'))).

Still converts when the actual value is the whole parameter:

-->with($this->callback(function ($type): bool {
-    $this->assertSame(TextType::class, $type);
-
-    return true;
-}));
+->with($this->equalTo(TextType::class));

@TomasVotruba TomasVotruba merged commit 404733e into main Jul 13, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the skip-nested-compare-callback-assert branch July 13, 2026 09:15
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