Skip to content

[CodeQuality] Skip union types in AssertEqualsToSameRector to preserve loose type comparison#717

Merged
TomasVotruba merged 1 commit into
mainfrom
skip-union-assert-equals
Jul 12, 2026
Merged

[CodeQuality] Skip union types in AssertEqualsToSameRector to preserve loose type comparison#717
TomasVotruba merged 1 commit into
mainfrom
skip-union-assert-equals

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

assertEquals() compares loosely, so it accepts values of different types across a union. Converting to strict assertSame() would break such tests.

Now skip when the actual (second) argument resolves to a union type.

#[DataProvider('stringProvider')]
public function testNormalizeStringValue(string|int|bool|\DateTime $input, string|int|bool|\DateTime $expected): void
{
    // union return type - values may differ in type between runs
    $this->assertEquals($expected, $this->formatterHelper->normalizeStringValue($input));
}
-$this->assertEquals($expected, $this->normalizeStringValue($input));
+$this->assertEquals($expected, $this->normalizeStringValue($input)); // unchanged

Before this change the rule wrongly narrowed it to assertSame().

@TomasVotruba TomasVotruba merged commit 9bd2807 into main Jul 12, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the skip-union-assert-equals branch July 12, 2026 11: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.

1 participant