Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a40488

Browse files
committed
minor #24919 [Config][4.0] Fix cannotBeEmpty() (ro0NL)
This PR was squashed before being merged into the 4.0-dev branch (closes #24919). Discussion ---------- [Config][4.0] Fix cannotBeEmpty() | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> Commits ------- 28128b6 [Config][4.0] Fix cannotBeEmpty()
2 parents 44b2f97 + 28128b6 commit 6a40488

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,7 @@ protected function createNode()
424424
$node->setKeyAttribute($this->key, $this->removeKeyItem);
425425
}
426426

427-
if (false === $this->allowEmptyValue) {
428-
@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);
429-
}
430-
431-
if (true === $this->atLeastOne) {
427+
if (true === $this->atLeastOne || false === $this->allowEmptyValue) {
432428
$node->setMinNumberOfElements(1);
433429
}
434430

@@ -490,7 +486,7 @@ protected function validateConcreteNode(ArrayNode $node)
490486
}
491487

492488
if (false === $this->allowEmptyValue) {
493-
@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);
489+
throw new InvalidDefinitionException(sprintf('->cannotBeEmpty() is not applicable to concrete nodes at path "%s"', $path));
494490
}
495491

496492
if (true === $this->atLeastOne) {

src/Symfony/Component/Config/Tests/Definition/Builder/ArrayNodeDefinitionTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function providePrototypeNodeSpecificCalls()
5454
array('defaultValue', array(array())),
5555
array('addDefaultChildrenIfNoneSet', array()),
5656
array('requiresAtLeastOneElement', array()),
57+
array('cannotBeEmpty', array()),
5758
array('useAttributeAsKey', array('foo')),
5859
);
5960
}
@@ -298,8 +299,8 @@ public function testRequiresAtLeastOneElement()
298299
}
299300

300301
/**
301-
* @group legacy
302-
* @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.
302+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
303+
* @expectedExceptionMessage The path "root" should have at least 1 element(s) defined.
303304
*/
304305
public function testCannotBeEmpty()
305306
{
@@ -326,8 +327,8 @@ public function testSetDeprecated()
326327
}
327328

328329
/**
329-
* @group legacy
330-
* @expectedDeprecation ->cannotBeEmpty() is not applicable to concrete nodes at path "root". In 4.0 it will throw an exception.
330+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidDefinitionException
331+
* @expectedExceptionMessage ->cannotBeEmpty() is not applicable to concrete nodes at path "root"
331332
*/
332333
public function testCannotBeEmptyOnConcreteNode()
333334
{

0 commit comments

Comments
 (0)