bug #17790 [Config] Fix EnumNodeDefinition to allow building enum nodes with one element (ogizanagi)
This PR was merged into the 2.8 branch.
Discussion
----------
[Config] Fix EnumNodeDefinition to allow building enum nodes with one element
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #15433, #17774
| License | MIT
| Doc PR | -
Commits
-------
e9111e4
[Config] Fix EnumNodeDefinition to allow building enum nodes with one element
This commit is contained in:
commit
4688f99ea1
@ -31,8 +31,8 @@ class EnumNodeDefinition extends ScalarNodeDefinition
|
||||
{
|
||||
$values = array_unique($values);
|
||||
|
||||
if (count($values) <= 1) {
|
||||
throw new \InvalidArgumentException('->values() must be called with at least two distinct values.');
|
||||
if (empty($values)) {
|
||||
throw new \InvalidArgumentException('->values() must be called with at least one value.');
|
||||
}
|
||||
|
||||
$this->values = $values;
|
||||
|
@ -15,14 +15,22 @@ use Symfony\Component\Config\Definition\Builder\EnumNodeDefinition;
|
||||
|
||||
class EnumNodeDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage ->values() must be called with at least two distinct values.
|
||||
*/
|
||||
public function testNoDistinctValues()
|
||||
public function testWithOneValue()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->values(array('foo'));
|
||||
|
||||
$node = $def->getNode();
|
||||
$this->assertEquals(array('foo'), $node->getValues());
|
||||
}
|
||||
|
||||
public function testWithOneDistinctValue()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->values(array('foo', 'foo'));
|
||||
|
||||
$node = $def->getNode();
|
||||
$this->assertEquals(array('foo'), $node->getValues());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,6 +43,16 @@ class EnumNodeDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$def->getNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage ->values() must be called with at least one value.
|
||||
*/
|
||||
public function testWithNoValues()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
$def->values(array());
|
||||
}
|
||||
|
||||
public function testGetNode()
|
||||
{
|
||||
$def = new EnumNodeDefinition('foo');
|
||||
|
Reference in New Issue
Block a user