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..64a2e303 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 ) { @@ -78,10 +85,7 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames( - $node, - ['assertSame', 'assertEquals', 'assertStringContainsString'] - )) { + if (! $this->testsNodeAnalyzer->isPHPUnitMethodCallNames($node, self::METHOD_NAMES)) { return null; }