diff --git a/rules-tests/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector/Fixture/skip_already_filled.php.inc b/rules-tests/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector/Fixture/skip_already_filled.php.inc new file mode 100644 index 00000000..4f0cb435 --- /dev/null +++ b/rules-tests/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector/Fixture/skip_already_filled.php.inc @@ -0,0 +1,15 @@ +createMock(\stdClass::class); + + $someClass->expects($this->once())->method('some'); + } +} diff --git a/rules-tests/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector/Fixture/skip_setup_as_can_be_any.php.inc b/rules-tests/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector/Fixture/skip_setup_as_can_be_any.php.inc new file mode 100644 index 00000000..c2aee4ef --- /dev/null +++ b/rules-tests/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector/Fixture/skip_setup_as_can_be_any.php.inc @@ -0,0 +1,15 @@ +createMock(\stdClass::class); + + $someClass->method('some'); + } +} diff --git a/rules/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector.php b/rules/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector.php index 6133cf80..7ae04e76 100644 --- a/rules/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector.php +++ b/rules/PHPUnit120/Rector/MethodCall/ExplicitMockExpectsCallRector.php @@ -10,9 +10,11 @@ use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\Variable; use PHPStan\Type\ObjectType; +use Rector\PHPStan\ScopeFetcher; use Rector\PHPUnit\Enum\PHPUnitClassName; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; +use Rector\ValueObject\MethodName; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -80,6 +82,11 @@ public function refactor(Node $node): Node|null return null; } + $scope = ScopeFetcher::fetch($node); + if ($scope->getFunctionName() === MethodName::SET_UP) { + return null; + } + if (! $node->var instanceof Variable && ! $node->var instanceof PropertyFetch) { return null; }