diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index d9ae4291824..03ac98c62fa 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 514 Rules Overview +# 512 Rules Overview
@@ -42,8 +42,6 @@ - [EarlyReturn](#earlyreturn) (11) -- [MockeryToProphecy](#mockerytoprophecy) (2) - - [MysqlToMysqli](#mysqltomysqli) (4) - [Naming](#naming) (6) @@ -6236,40 +6234,6 @@ Changes Single return of || to early returns
-## MockeryToProphecy - -### MockeryCloseRemoveRector - -Removes mockery close from test classes - -- class: [`Rector\MockeryToProphecy\Rector\StaticCall\MockeryCloseRemoveRector`](../rules/MockeryToProphecy/Rector/StaticCall/MockeryCloseRemoveRector.php) - -```diff - public function tearDown() : void - { -- \Mockery::close(); - } -``` - -
- -### MockeryCreateMockToProphizeRector - -Changes mockery mock creation to Prophesize - -- class: [`Rector\MockeryToProphecy\Rector\ClassMethod\MockeryCreateMockToProphizeRector`](../rules/MockeryToProphecy/Rector/ClassMethod/MockeryCreateMockToProphizeRector.php) - -```diff --$mock = \Mockery::mock('MyClass'); -+$mock = $this->prophesize('MyClass'); -+ - $service = new Service(); --$service->injectDependency($mock); -+$service->injectDependency($mock->reveal()); -``` - -
- ## MysqlToMysqli ### MysqlAssignToMysqliRector diff --git a/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/Fixture/MockCreation.php.inc b/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/Fixture/MockCreation.php.inc deleted file mode 100644 index 6d3c0cf8d24..00000000000 --- a/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/Fixture/MockCreation.php.inc +++ /dev/null @@ -1,37 +0,0 @@ -injectDependency($mock); - } -} - -?> ------ -prophesize('MyClass'); - - $service = new Service(); - $service->injectDependency($mock->reveal()); - } -} - -?> diff --git a/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/Fixture/MockCreationParameter.php.inc b/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/Fixture/MockCreationParameter.php.inc deleted file mode 100644 index 1c64968867f..00000000000 --- a/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/Fixture/MockCreationParameter.php.inc +++ /dev/null @@ -1,33 +0,0 @@ -injectDependency(\Mockery::mock('MyClass')); - } -} - -?> ------ -injectDependency($this->prophesize('MyClass')->reveal()); - } -} - -?> diff --git a/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/MockeryToProphecyRectorTest.php b/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/MockeryToProphecyRectorTest.php deleted file mode 100644 index f31fe3899ed..00000000000 --- a/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/MockeryToProphecyRectorTest.php +++ /dev/null @@ -1,33 +0,0 @@ -doTestFileInfo($file); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/config/configured_rule.php b/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/config/configured_rule.php deleted file mode 100644 index 8b4e3385c54..00000000000 --- a/rules-tests/MockeryToProphecy/Rector/ClassMethod/MockeryToProphecyRector/config/configured_rule.php +++ /dev/null @@ -1,11 +0,0 @@ -services(); - $services->set(MockeryCreateMockToProphizeRector::class); -}; diff --git a/rules-tests/MockeryToProphecy/Rector/StaticCall/MockeryToProphecyRector/Fixture/MockeryClose.php.inc b/rules-tests/MockeryToProphecy/Rector/StaticCall/MockeryToProphecyRector/Fixture/MockeryClose.php.inc deleted file mode 100644 index 3fad95c6d92..00000000000 --- a/rules-tests/MockeryToProphecy/Rector/StaticCall/MockeryToProphecyRector/Fixture/MockeryClose.php.inc +++ /dev/null @@ -1,30 +0,0 @@ - ------ - diff --git a/rules-tests/MockeryToProphecy/Rector/StaticCall/MockeryToProphecyRector/MockeryToProphecyRectorTest.php b/rules-tests/MockeryToProphecy/Rector/StaticCall/MockeryToProphecyRector/MockeryToProphecyRectorTest.php deleted file mode 100644 index 1dace651cf2..00000000000 --- a/rules-tests/MockeryToProphecy/Rector/StaticCall/MockeryToProphecyRector/MockeryToProphecyRectorTest.php +++ /dev/null @@ -1,33 +0,0 @@ -doTestFileInfo($file); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/MockeryToProphecy/Rector/StaticCall/MockeryToProphecyRector/config/configured_rule.php b/rules-tests/MockeryToProphecy/Rector/StaticCall/MockeryToProphecyRector/config/configured_rule.php deleted file mode 100644 index 92fbbea3047..00000000000 --- a/rules-tests/MockeryToProphecy/Rector/StaticCall/MockeryToProphecyRector/config/configured_rule.php +++ /dev/null @@ -1,11 +0,0 @@ -services(); - $services->set(MockeryCloseRemoveRector::class); -}; diff --git a/rules/MockeryToProphecy/Collector/MockVariableCollector.php b/rules/MockeryToProphecy/Collector/MockVariableCollector.php deleted file mode 100644 index 3c2e7535305..00000000000 --- a/rules/MockeryToProphecy/Collector/MockVariableCollector.php +++ /dev/null @@ -1,61 +0,0 @@ - - */ - public function collectMockVariableName(FuncCall | StaticCall $node): array - { - $mockVariableTypesByNames = []; - - $parentNode = $node->getAttribute(AttributeKey::PARENT_NODE); - if (! $parentNode instanceof Assign) { - return []; - } - - if (! $parentNode->var instanceof Variable) { - return []; - } - - /** @var Variable $variable */ - $variable = $parentNode->var; - - /** @var string $variableName */ - $variableName = $this->nodeNameResolver->getName($variable); - - if (! isset($node->args[0])) { - return []; - } - - if (! $node->args[0] instanceof Arg) { - return []; - } - - $type = $node->args[0]->value; - - $mockedType = $this->valueResolver->getValue($type); - $mockVariableTypesByNames[$variableName] = $mockedType; - - return $mockVariableTypesByNames; - } -} diff --git a/rules/MockeryToProphecy/Rector/ClassMethod/MockeryCreateMockToProphizeRector.php b/rules/MockeryToProphecy/Rector/ClassMethod/MockeryCreateMockToProphizeRector.php deleted file mode 100644 index 418ebbc2e17..00000000000 --- a/rules/MockeryToProphecy/Rector/ClassMethod/MockeryCreateMockToProphizeRector.php +++ /dev/null @@ -1,151 +0,0 @@ - - */ - private array $mockVariableTypesByNames = []; - - public function __construct( - private readonly MockVariableCollector $mockVariableCollector, - private readonly TestsNodeAnalyzer $testsNodeAnalyzer - ) { - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [ClassMethod::class]; - } - - /** - * @param ClassMethod $node - */ - public function refactor(Node $node): ?Node - { - if (! $this->testsNodeAnalyzer->isInTestClass($node)) { - return null; - } - - $this->replaceMockCreationsAndCollectVariableNames($node); - $this->revealMockArguments($node); - - return $node; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition( - 'Changes mockery mock creation to Prophesize', - [ - new CodeSample( - <<<'CODE_SAMPLE' -$mock = \Mockery::mock('MyClass'); -$service = new Service(); -$service->injectDependency($mock); -CODE_SAMPLE -, - <<<'CODE_SAMPLE' - $mock = $this->prophesize('MyClass'); - -$service = new Service(); -$service->injectDependency($mock->reveal()); -CODE_SAMPLE - ), - ] - ); - } - - private function replaceMockCreationsAndCollectVariableNames(ClassMethod $classMethod): void - { - if ($classMethod->stmts === null) { - return; - } - - $this->traverseNodesWithCallable($classMethod->stmts, function (Node $node): ?MethodCall { - if (! $node instanceof StaticCall) { - return null; - } - - $callerType = $this->nodeTypeResolver->getType($node->class); - if (! $callerType->isSuperTypeOf(new ObjectType('Mockery'))->yes()) { - return null; - } - - if (! $this->isName($node->name, 'mock')) { - return null; - } - - $collectedVariableTypesByNames = $this->mockVariableCollector->collectMockVariableName($node); - - /** @var array $result */ - $result = [...$this->mockVariableTypesByNames, ...$collectedVariableTypesByNames]; - $this->mockVariableTypesByNames = $result; - - $parentNode = $node->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode instanceof Arg) { - $prophesizeMethodCall = $this->createProphesizeMethodCall($node); - return $this->nodeFactory->createMethodCall($prophesizeMethodCall, 'reveal'); - } - - return $this->createProphesizeMethodCall($node); - }); - } - - private function revealMockArguments(ClassMethod $classMethod): void - { - if ($classMethod->stmts === null) { - return; - } - - $this->traverseNodesWithCallable($classMethod->stmts, function (Node $node): ?Arg { - if (! $node instanceof Arg) { - return null; - } - - if (! $node->value instanceof Variable) { - return null; - } - - /** @var string $variableName */ - $variableName = $this->getName($node->value); - - if (! isset($this->mockVariableTypesByNames[$variableName])) { - return null; - } - - $methodCall = $this->nodeFactory->createMethodCall($node->value, 'reveal'); - $node->value = $methodCall; - return $node; - }); - } - - private function createProphesizeMethodCall(StaticCall $staticCall): MethodCall - { - return $this->nodeFactory->createLocalMethodCall('prophesize', [$staticCall->args[0]]); - } -} diff --git a/rules/MockeryToProphecy/Rector/StaticCall/MockeryCloseRemoveRector.php b/rules/MockeryToProphecy/Rector/StaticCall/MockeryCloseRemoveRector.php deleted file mode 100644 index 4833e5845e9..00000000000 --- a/rules/MockeryToProphecy/Rector/StaticCall/MockeryCloseRemoveRector.php +++ /dev/null @@ -1,78 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [StaticCall::class]; - } - - /** - * @param StaticCall $node - */ - public function refactor(Node $node): ?Node - { - if (! $this->testsNodeAnalyzer->isInTestClass($node)) { - return null; - } - - $callerType = $this->nodeTypeResolver->getType($node->class); - if (! $callerType->isSuperTypeOf(new ObjectType('Mockery'))->yes()) { - return null; - } - - if (! $this->isName($node->name, 'close')) { - return null; - } - - $this->removeNode($node); - - return null; - } - - public function getRuleDefinition(): RuleDefinition - { - return new RuleDefinition( - 'Removes mockery close from test classes', - [ - new CodeSample( - <<<'CODE_SAMPLE' -public function tearDown() : void -{ - \Mockery::close(); -} -CODE_SAMPLE -, - <<<'CODE_SAMPLE' -public function tearDown() : void -{ -} -CODE_SAMPLE - ), - ] - ); - } -} diff --git a/stubs/Mockista/mock_function.php b/stubs/Mockista/mock_function.php deleted file mode 100644 index e2ea464302c..00000000000 --- a/stubs/Mockista/mock_function.php +++ /dev/null @@ -1,10 +0,0 @@ -