From 6d82de49ec3e22b1727be513f8f6f67b79e8f8bc Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Aug 2025 15:47:03 +0700 Subject: [PATCH 1/4] Revert "Drop MatchAssertEqualsExpectedTypeRector (#517)" This reverts commit a5fc6898bf1ad41c0d62e6f9fdf83f6aeef943c7. --- config/sets/phpunit-code-quality.php | 2 + .../Fixture/match_assert_type.php.inc | 41 ++++++ .../Fixture/match_integer_to_string.php.inc | 41 ++++++ .../nullable_match_assert_type.php.inc | 41 ++++++ .../Fixture/skip_argument_less.php.inc | 13 ++ .../Fixture/skip_docblock_type.php.inc | 21 +++ .../Fixture/skip_first_class_callable.php.inc | 13 ++ ...atchAssertEqualsExpectedTypeRectorTest.php | 28 ++++ .../config/configured_rule.php | 10 ++ .../MatchAssertEqualsExpectedTypeRector.php | 126 ++++++++++++++++++ 10 files changed, 336 insertions(+) create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_assert_type.php.inc create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_integer_to_string.php.inc create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_argument_less.php.inc create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_docblock_type.php.inc create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_first_class_callable.php.inc create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/MatchAssertEqualsExpectedTypeRectorTest.php create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php create mode 100644 rules/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector.php diff --git a/config/sets/phpunit-code-quality.php b/config/sets/phpunit-code-quality.php index ccc90e79..9d9dec95 100644 --- a/config/sets/phpunit-code-quality.php +++ b/config/sets/phpunit-code-quality.php @@ -31,6 +31,7 @@ use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameTrueFalseToAssertTrueFalseRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\FlipAssertRector; +use Rector\PHPUnit\CodeQuality\Rector\MethodCall\MatchAssertEqualsExpectedTypeRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\NarrowIdenticalWithConsecutiveRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\NarrowSingleWillReturnCallbackRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\RemoveExpectAnyFromMockRector; @@ -45,6 +46,7 @@ ConstructClassMethodToSetUpTestCaseRector::class, AssertSameTrueFalseToAssertTrueFalseRector::class, + MatchAssertEqualsExpectedTypeRector::class, AssertEqualsToSameRector::class, PreferPHPUnitThisCallRector::class, diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_assert_type.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_assert_type.php.inc new file mode 100644 index 00000000..0ad61056 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_assert_type.php.inc @@ -0,0 +1,41 @@ +assertEquals('123', $this->getOrderId()); + } + + private function getOrderId(): int + { + return 123; + } +} + +?> +----- +assertEquals(123, $this->getOrderId()); + } + + private function getOrderId(): int + { + return 123; + } +} + +?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_integer_to_string.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_integer_to_string.php.inc new file mode 100644 index 00000000..7ffa0666 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_integer_to_string.php.inc @@ -0,0 +1,41 @@ +assertEquals(123, $this->getOrderId()); + } + + private function getOrderId(): string + { + return '123'; + } +} + +?> +----- +assertEquals('123', $this->getOrderId()); + } + + private function getOrderId(): string + { + return '123'; + } +} + +?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc new file mode 100644 index 00000000..3a4718d1 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc @@ -0,0 +1,41 @@ +assertEquals('123', $this->getOrderId()); + } + + private function getOrderId(): ?int + { + return 123; + } +} + +?> +----- +assertEquals(123, $this->getOrderId()); + } + + private function getOrderId(): ?int + { + return 123; + } +} + +?> diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_argument_less.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_argument_less.php.inc new file mode 100644 index 00000000..a468892d --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_argument_less.php.inc @@ -0,0 +1,13 @@ +assertSame(1); + } +} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_docblock_type.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_docblock_type.php.inc new file mode 100644 index 00000000..24b7a7eb --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_docblock_type.php.inc @@ -0,0 +1,21 @@ +assertSame('123', $this->getOrderId()); + } + + /** + * @return int + */ + private function getOrderId() + { + return '123'; + } +} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_first_class_callable.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_first_class_callable.php.inc new file mode 100644 index 00000000..e623f13e --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_first_class_callable.php.inc @@ -0,0 +1,13 @@ +assertSame(...); + } +} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/MatchAssertEqualsExpectedTypeRectorTest.php b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/MatchAssertEqualsExpectedTypeRectorTest.php new file mode 100644 index 00000000..6ab2c505 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/MatchAssertEqualsExpectedTypeRectorTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php new file mode 100644 index 00000000..fa18b840 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(MatchAssertEqualsExpectedTypeRector::class); +}; diff --git a/rules/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector.php b/rules/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector.php new file mode 100644 index 00000000..2807ee3f --- /dev/null +++ b/rules/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector.php @@ -0,0 +1,126 @@ +assertEquals('123', $this->getOrderId()); + } + + private function getOrderId(): int + { + return 123; + } +} +CODE_SAMPLE + , + <<<'CODE_SAMPLE' +use PHPUnit\Framework\TestCase; + +class SomeTest extends TestCase +{ + public function run() + { + $this->assertEquals(123, $this->getOrderId()); + } + + private function getOrderId(): int + { + return 123; + } +} +CODE_SAMPLE + ), + ] + ); + } + + /** + * @return array> + */ + public function getNodeTypes(): array + { + return [MethodCall::class, StaticCall::class]; + } + + /** + * @param MethodCall|StaticCall $node + */ + public function refactor(Node $node): ?Node + { + if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertEquals'])) { + return null; + } + + if ($node->isFirstClassCallable()) { + return null; + } + + if (count($node->getArgs()) < 2) { + return null; + } + + $expectedArg = $node->getArgs()[0]; + if (! $expectedArg->value instanceof String_ && ! $expectedArg->value instanceof Int_) { + return null; + } + + $expectedType = $this->getType($expectedArg->value); + + $variableExpr = $node->getArgs()[1] + ->value; + $variableType = $this->nodeTypeResolver->getNativeType($variableExpr); + + $directVariableType = TypeCombinator::removeNull($variableType); + + if ($expectedType->isLiteralString()->yes() && $directVariableType->isInteger()->yes()) { + // update expected type to provided type + $expectedArg->value = new Int_((int) $expectedArg->value->value); + + return $node; + } + + if ($expectedType->isInteger()->yes() && $directVariableType->isString()->yes()) { + // update expected type to provided type + $expectedArg->value = new String_((string) $expectedArg->value->value); + + return $node; + } + + return null; + } +} From d49f3d459908af433e56104c5b428e73773625cf Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Aug 2025 15:47:16 +0700 Subject: [PATCH 2/4] Revert "[CodeQuality] Rename MatchAssertSameExpectedTypeRector to MatchAssertEqualsExpectedTypeRector to only apply on assertEquals (#514)" This reverts commit 84fe73acafa580fd8b313b2d87548721e1cfe8d1. --- config/sets/phpunit-code-quality.php | 4 ++-- .../config/configured_rule.php | 10 ---------- .../Fixture/match_assert_type.php.inc | 8 ++++---- .../Fixture/match_integer_to_string.php.inc | 8 ++++---- .../Fixture/nullable_match_assert_type.php.inc | 8 ++++---- .../Fixture/skip_argument_less.php.inc | 2 +- .../Fixture/skip_docblock_type.php.inc | 2 +- .../Fixture/skip_first_class_callable.php.inc | 2 +- .../MatchAssertSameExpectedTypeRectorTest.php} | 4 ++-- .../config/configured_rule.php | 10 ++++++++++ ...tor.php => MatchAssertSameExpectedTypeRector.php} | 12 ++++++------ 11 files changed, 35 insertions(+), 35 deletions(-) delete mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php rename rules-tests/CodeQuality/Rector/MethodCall/{MatchAssertEqualsExpectedTypeRector => MatchAssertSameExpectedTypeRector}/Fixture/match_assert_type.php.inc (73%) rename rules-tests/CodeQuality/Rector/MethodCall/{MatchAssertEqualsExpectedTypeRector => MatchAssertSameExpectedTypeRector}/Fixture/match_integer_to_string.php.inc (74%) rename rules-tests/CodeQuality/Rector/MethodCall/{MatchAssertEqualsExpectedTypeRector => MatchAssertSameExpectedTypeRector}/Fixture/nullable_match_assert_type.php.inc (74%) rename rules-tests/CodeQuality/Rector/MethodCall/{MatchAssertEqualsExpectedTypeRector => MatchAssertSameExpectedTypeRector}/Fixture/skip_argument_less.php.inc (84%) rename rules-tests/CodeQuality/Rector/MethodCall/{MatchAssertEqualsExpectedTypeRector => MatchAssertSameExpectedTypeRector}/Fixture/skip_docblock_type.php.inc (89%) rename rules-tests/CodeQuality/Rector/MethodCall/{MatchAssertEqualsExpectedTypeRector => MatchAssertSameExpectedTypeRector}/Fixture/skip_first_class_callable.php.inc (84%) rename rules-tests/CodeQuality/Rector/MethodCall/{MatchAssertEqualsExpectedTypeRector/MatchAssertEqualsExpectedTypeRectorTest.php => MatchAssertSameExpectedTypeRector/MatchAssertSameExpectedTypeRectorTest.php} (83%) create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/config/configured_rule.php rename rules/CodeQuality/Rector/MethodCall/{MatchAssertEqualsExpectedTypeRector.php => MatchAssertSameExpectedTypeRector.php} (88%) diff --git a/config/sets/phpunit-code-quality.php b/config/sets/phpunit-code-quality.php index 9d9dec95..9ac2ba9f 100644 --- a/config/sets/phpunit-code-quality.php +++ b/config/sets/phpunit-code-quality.php @@ -31,7 +31,7 @@ use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertSameTrueFalseToAssertTrueFalseRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertTrueFalseToSpecificMethodRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\FlipAssertRector; -use Rector\PHPUnit\CodeQuality\Rector\MethodCall\MatchAssertEqualsExpectedTypeRector; +use Rector\PHPUnit\CodeQuality\Rector\MethodCall\MatchAssertSameExpectedTypeRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\NarrowIdenticalWithConsecutiveRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\NarrowSingleWillReturnCallbackRector; use Rector\PHPUnit\CodeQuality\Rector\MethodCall\RemoveExpectAnyFromMockRector; @@ -46,7 +46,7 @@ ConstructClassMethodToSetUpTestCaseRector::class, AssertSameTrueFalseToAssertTrueFalseRector::class, - MatchAssertEqualsExpectedTypeRector::class, + MatchAssertSameExpectedTypeRector::class, AssertEqualsToSameRector::class, PreferPHPUnitThisCallRector::class, diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php deleted file mode 100644 index fa18b840..00000000 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(MatchAssertEqualsExpectedTypeRector::class); -}; diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_assert_type.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/match_assert_type.php.inc similarity index 73% rename from rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_assert_type.php.inc rename to rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/match_assert_type.php.inc index 0ad61056..1c537c53 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_assert_type.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/match_assert_type.php.inc @@ -1,6 +1,6 @@ assertEquals('123', $this->getOrderId()); + $this->assertSame('123', $this->getOrderId()); } private function getOrderId(): int @@ -21,7 +21,7 @@ final class MatchAssertType extends TestCase ----- assertEquals(123, $this->getOrderId()); + $this->assertSame(123, $this->getOrderId()); } private function getOrderId(): int diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_integer_to_string.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/match_integer_to_string.php.inc similarity index 74% rename from rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_integer_to_string.php.inc rename to rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/match_integer_to_string.php.inc index 7ffa0666..4f0d419e 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/match_integer_to_string.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/match_integer_to_string.php.inc @@ -1,6 +1,6 @@ assertEquals(123, $this->getOrderId()); + $this->assertSame(123, $this->getOrderId()); } private function getOrderId(): string @@ -21,7 +21,7 @@ final class MatchIntegerToString extends TestCase ----- assertEquals('123', $this->getOrderId()); + $this->assertSame('123', $this->getOrderId()); } private function getOrderId(): string diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc similarity index 74% rename from rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc rename to rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc index 3a4718d1..db905973 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/nullable_match_assert_type.php.inc @@ -1,6 +1,6 @@ assertEquals('123', $this->getOrderId()); + $this->assertSame('123', $this->getOrderId()); } private function getOrderId(): ?int @@ -21,7 +21,7 @@ final class NullableMatchAssertType extends TestCase ----- assertEquals(123, $this->getOrderId()); + $this->assertSame(123, $this->getOrderId()); } private function getOrderId(): ?int diff --git a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_argument_less.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_argument_less.php.inc similarity index 84% rename from rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_argument_less.php.inc rename to rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_argument_less.php.inc index a468892d..1bbaceb1 100644 --- a/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector/Fixture/skip_argument_less.php.inc +++ b/rules-tests/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector/Fixture/skip_argument_less.php.inc @@ -1,6 +1,6 @@ rule(MatchAssertSameExpectedTypeRector::class); +}; diff --git a/rules/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector.php b/rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php similarity index 88% rename from rules/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector.php rename to rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php index 2807ee3f..575ce818 100644 --- a/rules/CodeQuality/Rector/MethodCall/MatchAssertEqualsExpectedTypeRector.php +++ b/rules/CodeQuality/Rector/MethodCall/MatchAssertSameExpectedTypeRector.php @@ -16,9 +16,9 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * @see \Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\MatchAssertEqualsExpectedTypeRector\MatchAssertEqualsExpectedTypeRectorTest + * @see \Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\MatchAssertSameExpectedTypeRector\MatchAssertSameExpectedTypeRectorTest */ -final class MatchAssertEqualsExpectedTypeRector extends AbstractRector +final class MatchAssertSameExpectedTypeRector extends AbstractRector { public function __construct( private readonly TestsNodeAnalyzer $testsNodeAnalyzer @@ -28,7 +28,7 @@ public function __construct( public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( - 'Correct expected type in assertEquals() method to match strict type of passed variable', + 'Correct expected type in assertSame() method to match strict type of passed variable', [ new CodeSample( <<<'CODE_SAMPLE' @@ -38,7 +38,7 @@ class SomeTest extends TestCase { public function run() { - $this->assertEquals('123', $this->getOrderId()); + $this->assertSame('123', $this->getOrderId()); } private function getOrderId(): int @@ -55,7 +55,7 @@ class SomeTest extends TestCase { public function run() { - $this->assertEquals(123, $this->getOrderId()); + $this->assertSame(123, $this->getOrderId()); } private function getOrderId(): int @@ -82,7 +82,7 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertEquals'])) { + if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, ['assertSame', 'assertEquals'])) { return null; } From a59c74644fa61ce6babbef02277abd92a076e4ae Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 21 Aug 2025 15:59:46 +0700 Subject: [PATCH 3/4] add test --- .../AssertEqualsSame/AssertEqualsSameTest.php | 28 +++++++++++++++++++ .../Fixture/skip_assert_equals.php.inc | 20 +++++++++++++ .../config/configured_rule.php | 14 ++++++++++ 3 files changed, 62 insertions(+) create mode 100644 tests/Issues/AssertEqualsSame/AssertEqualsSameTest.php create mode 100644 tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals.php.inc create mode 100644 tests/Issues/AssertEqualsSame/config/configured_rule.php diff --git a/tests/Issues/AssertEqualsSame/AssertEqualsSameTest.php b/tests/Issues/AssertEqualsSame/AssertEqualsSameTest.php new file mode 100644 index 00000000..b0315b6f --- /dev/null +++ b/tests/Issues/AssertEqualsSame/AssertEqualsSameTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals.php.inc b/tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals.php.inc new file mode 100644 index 00000000..bda8d757 --- /dev/null +++ b/tests/Issues/AssertEqualsSame/Fixture/skip_assert_equals.php.inc @@ -0,0 +1,20 @@ +assertEquals(123, $this->getOrderId()); + } + + private function getOrderId(): string + { + return '0000000000000000000123'; + } +} diff --git a/tests/Issues/AssertEqualsSame/config/configured_rule.php b/tests/Issues/AssertEqualsSame/config/configured_rule.php new file mode 100644 index 00000000..7301a362 --- /dev/null +++ b/tests/Issues/AssertEqualsSame/config/configured_rule.php @@ -0,0 +1,14 @@ +rules([ + MatchAssertSameExpectedTypeRector::class, + AssertEqualsToSameRector::class, + ]); +}; From 11fa3dc90c3df102c181aad74c02022ca3c83616 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 21 Aug 2025 09:00:35 +0000 Subject: [PATCH 4/4] [ci-review] Rector Rectify --- tests/Issues/AssertEqualsSame/config/configured_rule.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/Issues/AssertEqualsSame/config/configured_rule.php b/tests/Issues/AssertEqualsSame/config/configured_rule.php index 7301a362..c47b46fb 100644 --- a/tests/Issues/AssertEqualsSame/config/configured_rule.php +++ b/tests/Issues/AssertEqualsSame/config/configured_rule.php @@ -7,8 +7,5 @@ use Rector\PHPUnit\CodeQuality\Rector\MethodCall\MatchAssertSameExpectedTypeRector; return static function (RectorConfig $rectorConfig): void { - $rectorConfig->rules([ - MatchAssertSameExpectedTypeRector::class, - AssertEqualsToSameRector::class, - ]); + $rectorConfig->rules([MatchAssertSameExpectedTypeRector::class, AssertEqualsToSameRector::class]); };