From 28128b60a40685c19d15ad906ea4dca0b6149b51 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Sat, 11 Nov 2017 12:46:47 +0100 Subject: [PATCH] [Config][4.0] Fix cannotBeEmpty() --- .../Config/Definition/Builder/ArrayNodeDefinition.php | 8 ++------ .../Tests/Definition/Builder/ArrayNodeDefinitionTest.php | 9 +++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php index 7fcefc127e04..ba6937cc51a9 100644 --- a/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php +++ b/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php @@ -424,11 +424,7 @@ protected function createNode() $node->setKeyAttribute($this->key, $this->removeKeyItem); } - if (false === $this->allowEmptyValue) { - @trigger_error(sprintf('Using %s::cannotBeEmpty() at path "%s" has no effect, consider requiresAtLeastOneElement() instead. In 4.0 both methods will behave the same.', __CLASS__, $node->getPath()), E_USER_DEPRECATED); - } - - if (true === $this->atLeastOne) { + if (true === $this->atLeastOne || false === $this->allowEmptyValue) { $node->setMinNumberOfElements(1); } @@ -490,7 +486,7 @@ protected function validateConcreteNode(ArrayNode $node) } if (false === $this->allowEmptyValue) { - @trigger_error(sprintf('->cannotBeEmpty() is not applicable to concrete nodes at path "%s". In 4.0 it will throw an exception.', $path), E_USER_DEPRECATED); + throw new InvalidDefinitionException(sprintf('->cannotBeEmpty() is not applicable to concrete nodes at path "%s"', $path)); } if (true === $this->atLeastOne) { diff --git a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php index dd6a6317e6ff..ad3b511c156d 100644 --- a/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php +++ b/src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php @@ -54,6 +54,7 @@ public function providePrototypeNodeSpecificCalls() array('defaultValue', array(array())), array('addDefaultChildrenIfNoneSet', array()), array('requiresAtLeastOneElement', array()), + array('cannotBeEmpty', array()), array('useAttributeAsKey', array('foo')), ); } @@ -298,8 +299,8 @@ public function testRequiresAtLeastOneElement() } /** - * @group legacy - * @expectedDeprecation Using Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition::cannotBeEmpty() at path "root" has no effect, consider requiresAtLeastOneElement() instead. In 4.0 both methods will behave the same. + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage The path "root" should have at least 1 element(s) defined. */ public function testCannotBeEmpty() { @@ -326,8 +327,8 @@ public function testSetDeprecated() } /** - * @group legacy - * @expectedDeprecation ->cannotBeEmpty() is not applicable to concrete nodes at path "root". In 4.0 it will throw an exception. + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException + * @expectedExceptionMessage ->cannotBeEmpty() is not applicable to concrete nodes at path "root" */ public function testCannotBeEmptyOnConcreteNode() {