Skip to content

Commit

Permalink
Fix beforeNormalization
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Feb 15, 2021
1 parent cc9d9ac commit d986994
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ services:
tags: [phpstan.broker.dynamicMethodReturnTypeExtension]
arguments:
className: Symfony\Component\Config\Definition\Builder\NodeDefinition
methods: [children, validate]
methods: [children, validate, beforeNormalization]

# NodeDefinition::end() return type
-
Expand Down
74 changes: 37 additions & 37 deletions tests/Type/Symfony/Config/TreeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Iterator;
use PHPStan\Type\Symfony\ExtensionTestCase;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;

final class TreeBuilderTest extends ExtensionTestCase
{
Expand All @@ -14,20 +13,6 @@ final class TreeBuilderTest extends ExtensionTestCase
*/
public function testGet(string $expression, string $type): void
{
$arrayTreeBuilder = new TreeBuilder('my_tree', 'array');
$arrayRootNode = $arrayTreeBuilder->getRootNode();
$r = $arrayRootNode
->children()
->arrayNode('methods')
->prototype('scalar')
->validate()
->ifNotInArray(['one', 'two'])
->thenInvalid('%s is not a valid method.')
->end()
->end()
->end()
->end();

$this->processFile(
__DIR__ . '/tree_builder.php',
$expression,
Expand All @@ -38,7 +23,7 @@ public function testGet(string $expression, string $type): void
new ReturnParentDynamicReturnTypeExtension('Symfony\Component\Config\Definition\Builder\NodeBuilder', ['end']),
new ReturnParentDynamicReturnTypeExtension('Symfony\Component\Config\Definition\Builder\NodeDefinition', ['end']),
new PassParentObjectDynamicReturnTypeExtension('Symfony\Component\Config\Definition\Builder\NodeBuilder', ['arrayNode', 'scalarNode', 'booleanNode', 'integerNode', 'floatNode', 'enumNode', 'variableNode']),
new PassParentObjectDynamicReturnTypeExtension('Symfony\Component\Config\Definition\Builder\NodeDefinition', ['children', 'validate']),
new PassParentObjectDynamicReturnTypeExtension('Symfony\Component\Config\Definition\Builder\NodeDefinition', ['children', 'validate', 'beforeNormalization']),
new TreeBuilderGetRootNodeDynamicReturnTypeExtension(),
],
[new TreeBuilderDynamicReturnTypeExtension()]
Expand Down Expand Up @@ -153,35 +138,50 @@ public function getProvider(): Iterator
yield ['
$arrayRootNode
->children()
->arrayNode("methods")
->prototype("scalar")
->defaultNull()
->end()
->end()
->end()
->arrayNode("methods")
->prototype("scalar")
->defaultNull()
->end()
->end()
->end()
', 'Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition'];
yield ['
$arrayRootNode
->children()
->arrayNode("methods")
->scalarPrototype()
->defaultNull()
->end()
->end()
->end()
->arrayNode("methods")
->scalarPrototype()
->defaultNull()
->end()
->end()
->end()
', 'Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition'];
yield ['
$arrayRootNode
->children()
->arrayNode("methods")
->prototype("scalar")
->validate()
->ifNotInArray(["one", "two"])
->thenInvalid("%s is not a valid method.")
->end()
->end()
->end()
->end()
->arrayNode("methods")
->prototype("scalar")
->validate()
->ifNotInArray(["one", "two"])
->thenInvalid("%s is not a valid method.")
->end()
->end()
->end()
->end()
', 'Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition'];
yield ['
$arrayRootNode
->children()
->arrayNode("methods")
->prototype("array")
->beforeNormalization()
->ifString()
->then(static function ($v) {
return [$v];
})
->end()
->end()
->end()
->end()
', 'Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition'];

yield ['$variableRootNode', 'Symfony\Component\Config\Definition\Builder\VariableNodeDefinition'];
Expand Down

0 comments on commit d986994

Please sign in to comment.