|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
| 16 | +use Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition; |
| 17 | +use Symfony\Component\Config\Definition\Builder\NodeDefinition; |
16 | 18 | use Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition;
|
17 | 19 | use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
|
18 | 20 | use Symfony\Component\Config\Definition\Processor;
|
@@ -357,6 +359,56 @@ public function testCannotBeEmptyOnConcreteNode()
|
357 | 359 | $node->getNode()->finalize([]);
|
358 | 360 | }
|
359 | 361 |
|
| 362 | + public function testFindShouldThrowExceptionIfNodeDoesNotExistInRootNode() |
| 363 | + { |
| 364 | + $this->expectException(\RuntimeException::class); |
| 365 | + $this->expectExceptionMessage('Node with name "child" does not exist in the current node "root"!'); |
| 366 | + |
| 367 | + $rootNode = new ArrayNodeDefinition('root'); |
| 368 | + $rootNode |
| 369 | + ->children() |
| 370 | + ->arrayNode('social_media_channels')->end() |
| 371 | + ->end() |
| 372 | + ; |
| 373 | + |
| 374 | + $rootNode->find('child'); |
| 375 | + } |
| 376 | + |
| 377 | + public function testFindShouldHandleComplexConfigurationProbably() |
| 378 | + { |
| 379 | + $rootNode = new ArrayNodeDefinition('root'); |
| 380 | + $rootNode |
| 381 | + ->children() |
| 382 | + ->arrayNode('social_media_channels') |
| 383 | + ->children() |
| 384 | + ->booleanNode('enable')->end() |
| 385 | + ->arrayNode('twitter')->end() |
| 386 | + ->arrayNode('facebook')->end() |
| 387 | + ->arrayNode('instagram') |
| 388 | + ->children() |
| 389 | + ->booleanNode('enable')->end() |
| 390 | + ->arrayNode('accounts')->end() |
| 391 | + ->end() |
| 392 | + ->end() |
| 393 | + ->end() |
| 394 | + ->end() |
| 395 | + ; |
| 396 | + |
| 397 | + $this->assertNode('social_media_channels', ArrayNodeDefinition::class, $rootNode->find('social_media_channels')); |
| 398 | + $this->assertNode('enable', BooleanNodeDefinition::class, $rootNode->find('social_media_channels.enable')); |
| 399 | + $this->assertNode('twitter', ArrayNodeDefinition::class, $rootNode->find('social_media_channels.twitter')); |
| 400 | + $this->assertNode('facebook', ArrayNodeDefinition::class, $rootNode->find('social_media_channels.facebook')); |
| 401 | + $this->assertNode('instagram', ArrayNodeDefinition::class, $rootNode->find('social_media_channels.instagram')); |
| 402 | + $this->assertNode('enable', BooleanNodeDefinition::class, $rootNode->find('social_media_channels.instagram.enable')); |
| 403 | + $this->assertNode('accounts', ArrayNodeDefinition::class, $rootNode->find('social_media_channels.instagram.accounts')); |
| 404 | + } |
| 405 | + |
| 406 | + protected function assertNode(string $expectedName, string $expectedType, NodeDefinition $actualNode): void |
| 407 | + { |
| 408 | + $this->assertInstanceOf($expectedType, $actualNode); |
| 409 | + $this->assertSame($expectedName, $this->getField($actualNode, 'name')); |
| 410 | + } |
| 411 | + |
360 | 412 | protected function getField($object, $field)
|
361 | 413 | {
|
362 | 414 | $reflection = new \ReflectionProperty($object, $field);
|
|
0 commit comments