From 3563b7daa062a4d76f48270985c7487473c4f65a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 19 Jan 2025 18:00:35 +0000 Subject: [PATCH 1/2] include assert not same not equals --- .../AssertEqualsToSameRector/Fixture/skip.php | 19 ++++++++++++ .../FlipAssertRector/Fixture/not_same.php.inc | 29 +++++++++++++++++++ .../Rector/MethodCall/FlipAssertRector.php | 9 +++++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip.php create mode 100644 rules-tests/CodeQuality/Rector/MethodCall/FlipAssertRector/Fixture/not_same.php.inc diff --git a/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip.php b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip.php new file mode 100644 index 00000000..1a7b0b71 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/AssertEqualsToSameRector/Fixture/skip.php @@ -0,0 +1,19 @@ +assertEquals($expectedNull, $null); + + $bool = true; + $expectedBool = true; + $this->assertEquals($expectedBool, $bool); + } +} diff --git a/rules-tests/CodeQuality/Rector/MethodCall/FlipAssertRector/Fixture/not_same.php.inc b/rules-tests/CodeQuality/Rector/MethodCall/FlipAssertRector/Fixture/not_same.php.inc new file mode 100644 index 00000000..82e419bc --- /dev/null +++ b/rules-tests/CodeQuality/Rector/MethodCall/FlipAssertRector/Fixture/not_same.php.inc @@ -0,0 +1,29 @@ +assertNotSame($result, 'expected'); + } +} + +?> +----- +assertNotSame('expected', $result); + } +} + +?> diff --git a/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php b/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php index bd1c2a1c..b3f7bf9a 100644 --- a/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php +++ b/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php @@ -20,6 +20,13 @@ */ final class FlipAssertRector extends AbstractRector { + /** + * @var string[] + */ + private const METHOD_NAMES = [ + 'assertSame', 'assertNotSame', 'assertNotEquals', 'assertEquals', 'assertStringContainsString' + ]; + public function __construct( private readonly TestsNodeAnalyzer $testsNodeAnalyzer ) { @@ -80,7 +87,7 @@ public function refactor(Node $node): ?Node { if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames( $node, - ['assertSame', 'assertEquals', 'assertStringContainsString'] + self::METHOD_NAMES )) { return null; } From 58f0916de437a117ea06d78660a92fa83340f173 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 19 Jan 2025 18:02:23 +0000 Subject: [PATCH 2/2] [ci-review] Rector Rectify --- rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php b/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php index b3f7bf9a..64a2e303 100644 --- a/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php +++ b/rules/CodeQuality/Rector/MethodCall/FlipAssertRector.php @@ -24,7 +24,7 @@ final class FlipAssertRector extends AbstractRector * @var string[] */ private const METHOD_NAMES = [ - 'assertSame', 'assertNotSame', 'assertNotEquals', 'assertEquals', 'assertStringContainsString' + 'assertSame', 'assertNotSame', 'assertNotEquals', 'assertEquals', 'assertStringContainsString', ]; public function __construct( @@ -85,10 +85,7 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames( - $node, - self::METHOD_NAMES - )) { + if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, self::METHOD_NAMES)) { return null; }