From 5752b9cafd501335057b23545b59c4c74399d745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Fejfar?= Date: Fri, 16 Aug 2019 17:31:39 +0200 Subject: [PATCH 1/2] Add test and dummy Extension --- ...onfigurationDynamicReturnTypeExtension.php | 53 +++++++++++++++++++ ...gurationDynamicReturnTypeExtensionTest.php | 32 +++++++++++ tests/Type/Symfony/ExampleConfiguration.php | 47 ++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 src/Type/Symfony/ConfigurationDynamicReturnTypeExtension.php create mode 100644 tests/Type/Symfony/ConfigurationDynamicReturnTypeExtensionTest.php create mode 100644 tests/Type/Symfony/ExampleConfiguration.php diff --git a/src/Type/Symfony/ConfigurationDynamicReturnTypeExtension.php b/src/Type/Symfony/ConfigurationDynamicReturnTypeExtension.php new file mode 100644 index 00000000..7060b0d9 --- /dev/null +++ b/src/Type/Symfony/ConfigurationDynamicReturnTypeExtension.php @@ -0,0 +1,53 @@ +className = $className; + } + + public function getClass(): string + { + return $this->className; + } + + public function isMethodSupported(MethodReflection $methodReflection): bool + { + return in_array($methodReflection->getName(), ['end'], true); + } + + public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type + { + return $this->getGetTypeFromMethodCall($methodReflection, $methodCall, $scope); + } + + private function getGetTypeFromMethodCall( + MethodReflection $methodReflection, + MethodCall $methodCall, + Scope $scope + ): Type + { + return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType(); + } + + +} diff --git a/tests/Type/Symfony/ConfigurationDynamicReturnTypeExtensionTest.php b/tests/Type/Symfony/ConfigurationDynamicReturnTypeExtensionTest.php new file mode 100644 index 00000000..dd3ffbe0 --- /dev/null +++ b/tests/Type/Symfony/ConfigurationDynamicReturnTypeExtensionTest.php @@ -0,0 +1,32 @@ +processFile( + __DIR__ . '/ExampleConfiguration.php', + $expression, + $type, + new ConfigurationDynamicReturnTypeExtension(ExampleConfiguration::class) + ); + } + + public function servicesProvider(): Iterator + { + yield ['$dataDirResult', NodeBuilder::class]; + yield ['$arrayDbResult', ArrayNodeDefinition::class]; + yield ['$childrenResult', ArrayNodeDefinition::class]; + } + +} diff --git a/tests/Type/Symfony/ExampleConfiguration.php b/tests/Type/Symfony/ExampleConfiguration.php new file mode 100644 index 00000000..01d7f4d5 --- /dev/null +++ b/tests/Type/Symfony/ExampleConfiguration.php @@ -0,0 +1,47 @@ +root('parameters'); + // @formatter:off + $rootNode->ignoreExtraKeys(true); + $children = $rootNode->children(); + $dataDirResult = $children->scalarNode('data_dir') + ->isRequired() + ->cannotBeEmpty() + ->end(); + $dataDirResult->scalarNode('extractor_class') + ->isRequired() + ->cannotBeEmpty() + ->end(); + $arrayDbResult = $dataDirResult->arrayNode('db') + ->children() + ->scalarNode('driver')->end() + ->scalarNode('host')->end() + ->scalarNode('port')->end() + ->scalarNode('database') + ->cannotBeEmpty() + ->end() + ->scalarNode('user') + ->isRequired() + ->end() + ->scalarNode('#password') + ->isRequired() + ->end() + ->end(); + + $childrenResult = $arrayDbResult->end()->end(); + // @formatter:on + return $treeBuilder; + } + +} From 8941637c5efd009f3a7b4c0e0771fff5b440e13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Fejfar?= Date: Fri, 16 Aug 2019 17:31:55 +0200 Subject: [PATCH 2/2] DUMMY FIX MAYBE? --- tests/Type/Symfony/ExtensionTestCase.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Type/Symfony/ExtensionTestCase.php b/tests/Type/Symfony/ExtensionTestCase.php index a1cef2bf..af398de0 100644 --- a/tests/Type/Symfony/ExtensionTestCase.php +++ b/tests/Type/Symfony/ExtensionTestCase.php @@ -52,7 +52,8 @@ protected function processFile( true, true, true, - [] + [], + false ); $resolver->setAnalysedFiles([$fileHelper->normalizePath($file)]); @@ -65,7 +66,7 @@ function (Node $node, Scope $scope) use ($expression, $type, &$run): void { return; } if ((new Standard())->prettyPrint([$node]) !== 'die') { - return; + //return; } /** @var \PhpParser\Node\Stmt\Expression $expNode */ $expNode = $this->getParser()->parseString(sprintf('