From 48970626ff91449e09c9c67b2ce8edd3c25ff2c1 Mon Sep 17 00:00:00 2001 From: Mateusz Sip Date: Sat, 13 Jan 2018 04:34:06 +0100 Subject: [PATCH 1/4] Tests --- .../Builder/ArrayNodeDefinitionTest.php | 31 +++++++++++++++++++ .../Definition/Builder/TreeBuilderTest.php | 19 ++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php index 16a38c30b0f9d..b81f96de4a7be 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php @@ -207,6 +207,37 @@ public function testCanBeDisabled() $this->assertTrue($this->getField($enabledNode, 'defaultValue')); } + public function testNodeThatCanBeEnabledIsDisabledByDefault() + { + $node = new ArrayNodeDefinition('root'); + $node->canBeEnabled(); + + $this->assertTrue($this->getField($node, 'addDefaults')); + $this->assertEquals(array('enabled' => false), $this->getField($node, 'falseEquivalent')); + $this->assertEquals(array('enabled' => true), $this->getField($node, 'trueEquivalent')); + $this->assertEquals(array('enabled' => true), $this->getField($node, 'nullEquivalent')); + + $nodeChildren = $this->getField($node, 'children'); + $this->assertArrayHasKey('enabled', $nodeChildren); + + $enabledNode = $nodeChildren['enabled']; + $this->assertTrue($this->getField($enabledNode, 'default')); + $this->assertFalse($this->getField($enabledNode, 'defaultValue')); + } + + public function testEnableableNodeIsDisabledForEmptyConfiguration() + { + $processor = new Processor(); + $node = new ArrayNodeDefinition('root'); + $node->canBeEnabled(); + + $this->assertEquals( + array('enabled' => false), + $processor->process($node->getNode(), array()), + 'An enableable node is disabled by default' + ); + } + public function testIgnoreExtraKeys() { $node = new ArrayNodeDefinition('root'); diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php index 0a9312346e989..354a0a4ca325e 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Config\Tests\Definition\Builder; use PHPUnit\Framework\TestCase; +use Symfony\Component\Config\Definition\Processor; use Symfony\Component\Config\Tests\Fixtures\Builder\NodeBuilder as CustomNodeBuilder; use Symfony\Component\Config\Definition\Builder\TreeBuilder; @@ -131,4 +132,22 @@ public function testDefinitionExampleGetsTransferredToNode() $this->assertInternalType('array', $tree->getExample()); $this->assertEquals('example', $children['child']->getExample()); } + + public function testRootNodeThatCanBeEnabledIsDisabledByDefault() + { + $builder = new TreeBuilder(); + + $builder->root('test') + ->canBeEnabled(); + + $tree = $builder->buildTree(); + $children = $tree->getChildren(); + + $this->assertFalse($children['enabled']->getDefaultValue()); + + $processor = new Processor(); + $result = $processor->process($tree, []); + + $this->assertEquals(array('enabled' => false), $result); + } } From a7c429ae494817f5f50d3b99522f144955f0d5d8 Mon Sep 17 00:00:00 2001 From: Mateusz Sip Date: Mon, 15 Jan 2018 01:47:02 +0100 Subject: [PATCH 2/4] Enableable ArrayNodeDefinition is disabled for empty configuration --- .../Builder/ArrayNodeDefinition.php | 4 ++- .../Builder/ArrayNodeDefinitionTest.php | 26 ++++--------------- .../Definition/Builder/TreeBuilderTest.php | 2 +- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php index a0ad77edd0796..607f1d1fe743d 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php @@ -226,7 +226,9 @@ public function canBeEnabled() ->beforeNormalization() ->ifArray() ->then(function ($v) { - $v['enabled'] = isset($v['enabled']) ? $v['enabled'] : true; + if (!isset($v['enabled'])) { + $v['enabled'] = !empty($v); + } return $v; }) diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php index b81f96de4a7be..4b6f4d7fd1013 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php @@ -207,34 +207,17 @@ public function testCanBeDisabled() $this->assertTrue($this->getField($enabledNode, 'defaultValue')); } - public function testNodeThatCanBeEnabledIsDisabledByDefault() + public function testEnableableNodeIsDisabledForEmptyConfigurationWhenNormalized() { - $node = new ArrayNodeDefinition('root'); - $node->canBeEnabled(); - - $this->assertTrue($this->getField($node, 'addDefaults')); - $this->assertEquals(array('enabled' => false), $this->getField($node, 'falseEquivalent')); - $this->assertEquals(array('enabled' => true), $this->getField($node, 'trueEquivalent')); - $this->assertEquals(array('enabled' => true), $this->getField($node, 'nullEquivalent')); - - $nodeChildren = $this->getField($node, 'children'); - $this->assertArrayHasKey('enabled', $nodeChildren); - - $enabledNode = $nodeChildren['enabled']; - $this->assertTrue($this->getField($enabledNode, 'default')); - $this->assertFalse($this->getField($enabledNode, 'defaultValue')); - } + $config = array(); - public function testEnableableNodeIsDisabledForEmptyConfiguration() - { - $processor = new Processor(); $node = new ArrayNodeDefinition('root'); $node->canBeEnabled(); $this->assertEquals( array('enabled' => false), - $processor->process($node->getNode(), array()), - 'An enableable node is disabled by default' + $node->getNode()->normalize($config), + 'An enableable node is disabled by default' ); } @@ -271,6 +254,7 @@ public function getEnableableNodeFixtures() array(array('enabled' => true, 'foo' => 'baz'), array(array('foo' => 'baz')), 'any configuration enables an enableable node'), array(array('enabled' => false, 'foo' => 'baz'), array(array('foo' => 'baz', 'enabled' => false)), 'An enableable node can be disabled'), array(array('enabled' => false, 'foo' => 'bar'), array(false), 'false disables an enableable node'), + array(array('enabled' => false, 'foo' => 'bar'), array(), 'enableable node is disabled by default'), ); } diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php index 354a0a4ca325e..6e99469a4e48c 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/TreeBuilderTest.php @@ -146,7 +146,7 @@ public function testRootNodeThatCanBeEnabledIsDisabledByDefault() $this->assertFalse($children['enabled']->getDefaultValue()); $processor = new Processor(); - $result = $processor->process($tree, []); + $result = $processor->process($tree, array()); $this->assertEquals(array('enabled' => false), $result); } From 8669a2114cae6d9dfc6c3a57ad641490f54ec324 Mon Sep 17 00:00:00 2001 From: Mateusz Sip Date: Sun, 21 Jan 2018 16:05:21 +0100 Subject: [PATCH 3/4] Test for enabling extension using yaml tilde syntax --- .../Fixtures/includes/FooConfiguration.php | 15 +++++++++++++++ .../Tests/Fixtures/includes/FooExtension.php | 19 +++++++++++++++++++ .../Fixtures/yaml/extension_nullable.yml | 1 + .../Tests/Loader/YamlFileLoaderTest.php | 15 +++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooConfiguration.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooExtension.php create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/extension_nullable.yml diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooConfiguration.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooConfiguration.php new file mode 100644 index 0000000000000..e37bef3e15640 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooConfiguration.php @@ -0,0 +1,15 @@ +root('foo'); + $rootNode->canBeEnabled(); + + return $builder; + } +} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooExtension.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooExtension.php new file mode 100644 index 0000000000000..e4ff380416f38 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/FooExtension.php @@ -0,0 +1,19 @@ +processConfiguration(new \FooConfiguration(), $configs); + + $container->setParameter('foo_extension_enabled', $config['enabled']); + } + + public function getAlias() + { + return 'foo'; + } +} diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/extension_nullable.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/extension_nullable.yml new file mode 100644 index 0000000000000..b5051d957328d --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/extension_nullable.yml @@ -0,0 +1 @@ +foo: ~ diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php index 85c74b572d080..fdc3ffab7e412 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php @@ -31,6 +31,8 @@ public static function setUpBeforeClass() self::$fixturesPath = realpath(__DIR__.'/../Fixtures/'); require_once self::$fixturesPath.'/includes/foo.php'; require_once self::$fixturesPath.'/includes/ProjectExtension.php'; + require_once self::$fixturesPath.'/includes/FooExtension.php'; + require_once self::$fixturesPath.'/includes/FooConfiguration.php'; } /** @@ -207,6 +209,19 @@ public function testExtensions() } } + public function testNullableExtension() + { + $container = new ContainerBuilder(); + $container->registerExtension(new \FooExtension()); + $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml')); + $loader->load('extension_nullable.yml'); + $container->compile(); + + $isEnabled = $container->getParameter('foo_extension_enabled'); + + $this->assertTrue($isEnabled); + } + public function testSupports() { $loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator()); From 73ee9a13c7d0a3131988e820a26b55780546734c Mon Sep 17 00:00:00 2001 From: Mateusz Sip Date: Sun, 21 Jan 2018 16:24:52 +0100 Subject: [PATCH 4/4] convert yaml's null to enabled => null array in extension config --- .../Component/DependencyInjection/Loader/YamlFileLoader.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php index b6b9e93a86ca3..c548ed459c0c7 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php @@ -425,6 +425,10 @@ private function loadFromExtensions(array $content) continue; } + if (null === $values) { + $values = array('enabled' => null); + } + if (!is_array($values)) { $values = array(); } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy