diff --git a/rules/PHPUnit90/Rector/MethodCall/ReplaceAtMethodWithDesiredMatcherRector.php b/rules/PHPUnit90/Rector/MethodCall/ReplaceAtMethodWithDesiredMatcherRector.php index 39f74c1a..74a2bab1 100644 --- a/rules/PHPUnit90/Rector/MethodCall/ReplaceAtMethodWithDesiredMatcherRector.php +++ b/rules/PHPUnit90/Rector/MethodCall/ReplaceAtMethodWithDesiredMatcherRector.php @@ -19,6 +19,8 @@ */ final class ReplaceAtMethodWithDesiredMatcherRector extends AbstractRector { + private bool $hasChanged = false; + public function __construct( private readonly TestsNodeAnalyzer $testsNodeAnalyzer ) { @@ -59,6 +61,8 @@ public function getNodeTypes(): array */ public function refactor(Node $node): null|MethodCall { + $this->hasChanged = false; + if (! $this->testsNodeAnalyzer->isInTestClass($node)) { return null; } @@ -67,6 +71,10 @@ public function refactor(Node $node): null|MethodCall $this->replaceWithDesiredMatcher($arg); } + if ($this->hasChanged) { + return $node; + } + return null; } @@ -106,10 +114,13 @@ private function replaceWithDesiredMatcher(Arg $arg): void if ($count === 0) { $arg->value = new MethodCall($arg->value->var, 'never'); + $this->hasChanged = true; } elseif ($count === 1) { $arg->value = new MethodCall($arg->value->var, 'once'); + $this->hasChanged = true; } elseif ($count > 1) { $arg->value = new MethodCall($arg->value->var, 'exactly', [new Arg(new Int_($count))]); + $this->hasChanged = true; } } }