Skip to content

Commit 03e2418

Browse files
authored
[PHPUnit90] Ensure return node on has changed on ReplaceAtMethodWithDesiredMatcherRector (#455)
1 parent e991afe commit 03e2418

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

rules/PHPUnit90/Rector/MethodCall/ReplaceAtMethodWithDesiredMatcherRector.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
final class ReplaceAtMethodWithDesiredMatcherRector extends AbstractRector
2121
{
22+
private bool $hasChanged = false;
23+
2224
public function __construct(
2325
private readonly TestsNodeAnalyzer $testsNodeAnalyzer
2426
) {
@@ -59,6 +61,8 @@ public function getNodeTypes(): array
5961
*/
6062
public function refactor(Node $node): null|MethodCall
6163
{
64+
$this->hasChanged = false;
65+
6266
if (! $this->testsNodeAnalyzer->isInTestClass($node)) {
6367
return null;
6468
}
@@ -67,6 +71,10 @@ public function refactor(Node $node): null|MethodCall
6771
$this->replaceWithDesiredMatcher($arg);
6872
}
6973

74+
if ($this->hasChanged) {
75+
return $node;
76+
}
77+
7078
return null;
7179
}
7280

@@ -106,10 +114,13 @@ private function replaceWithDesiredMatcher(Arg $arg): void
106114

107115
if ($count === 0) {
108116
$arg->value = new MethodCall($arg->value->var, 'never');
117+
$this->hasChanged = true;
109118
} elseif ($count === 1) {
110119
$arg->value = new MethodCall($arg->value->var, 'once');
120+
$this->hasChanged = true;
111121
} elseif ($count > 1) {
112122
$arg->value = new MethodCall($arg->value->var, 'exactly', [new Arg(new Int_($count))]);
123+
$this->hasChanged = true;
113124
}
114125
}
115126
}

0 commit comments

Comments
 (0)