From 7a0278d63adaa16a4d14abe6c48af6766b5d6ec6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 22 Aug 2025 19:34:13 +0700 Subject: [PATCH] [CodeQuality] Skip assertEquals() on integer to numeric string on MatchAssertSameExpectedTypeRector --- .../MatchAssertSameExpectedTypeRector.php | 8 +++- .../assert_equals_numeric_string.php.inc | 45 ------------------- ...ip_assert_equals_integer_to_string.php.inc | 20 +++++++++ 3 files changed, 26 insertions(+), 47 deletions(-) delete mode 100644 tests/Issues/AssertEqualsSame/Fixture/assert_equals_numeric_string.php.inc create mode 100644 tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals_integer_to_string.php.inc diff --git a/rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php b/rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php index 575ce818..8b553f4b 100644 --- a/rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php +++ b/rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php @@ -36,7 +36,7 @@ public function getRuleDefinition(): RuleDefinition class SomeTest extends TestCase { - public function run() + public function test() { $this->assertSame('123', $this->getOrderId()); } @@ -53,7 +53,7 @@ private function getOrderId(): int class SomeTest extends TestCase { - public function run() + public function test() { $this->assertSame(123, $this->getOrderId()); } @@ -115,6 +115,10 @@ public function refactor(Node $node): ?Node } if ($expectedType->isInteger()->yes() && $directVariableType->isString()->yes()) { + if ($this->isName($node->name, 'assertEquals')) { + return null; + } + // update expected type to provided type $expectedArg->value = new String_((string) $expectedArg->value->value); diff --git a/tests/Issues/AssertEqualsSame/Fixture/assert_equals_numeric_string.php.inc b/tests/Issues/AssertEqualsSame/Fixture/assert_equals_numeric_string.php.inc deleted file mode 100644 index f2a77583..00000000 --- a/tests/Issues/AssertEqualsSame/Fixture/assert_equals_numeric_string.php.inc +++ /dev/null @@ -1,45 +0,0 @@ -assertEquals(123, $this->getOrderId()); - } - - private function getOrderId(): string - { - return '0000000000000000000123'; - } -} - -?> ------ -assertEquals('123', $this->getOrderId()); - } - - private function getOrderId(): string - { - return '0000000000000000000123'; - } -} - -?> \ No newline at end of file diff --git a/tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals_integer_to_string.php.inc b/tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals_integer_to_string.php.inc new file mode 100644 index 00000000..37100eb8 --- /dev/null +++ b/tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals_integer_to_string.php.inc @@ -0,0 +1,20 @@ +assertEquals(123, $this->getOrderId()); + } + + private function getOrderId(): string + { + return '0000000000000000000123'; + } +}