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
-------
28128b60a4
[Config][4.0] Fix cannotBeEmpty()
This commit is contained in:
commit
6a404881ae
@ -424,11 +424,7 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
$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 @@ class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinition
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -54,6 +54,7 @@ class ArrayNodeDefinitionTest extends TestCase
|
||||
array('defaultValue', array(array())),
|
||||
array('addDefaultChildrenIfNoneSet', array()),
|
||||
array('requiresAtLeastOneElement', array()),
|
||||
array('cannotBeEmpty', array()),
|
||||
array('useAttributeAsKey', array('foo')),
|
||||
);
|
||||
}
|
||||
@ -298,8 +299,8 @@ class ArrayNodeDefinitionTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 @@ class ArrayNodeDefinitionTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @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()
|
||||
{
|
||||
|
Reference in New Issue
Block a user