Skip to content

Commit 3b017a6

Browse files
committed
[Config] Fix EnumNodeDefinition to allow building enum nodes with one element
1 parent e258bb4 commit 3b017a6

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

Definition/Builder/EnumNodeDefinition.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function values(array $values)
3131
{
3232
$values = array_unique($values);
3333

34-
if (count($values) <= 1) {
35-
throw new \InvalidArgumentException('->values() must be called with at least two distinct values.');
34+
if (empty($values)) {
35+
throw new \InvalidArgumentException('->values() must be called with at least one value.');
3636
}
3737

3838
$this->values = $values;

Tests/Definition/Builder/EnumNodeDefinitionTest.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@
1515

1616
class EnumNodeDefinitionTest extends \PHPUnit_Framework_TestCase
1717
{
18-
/**
19-
* @expectedException \InvalidArgumentException
20-
* @expectedExceptionMessage ->values() must be called with at least two distinct values.
21-
*/
22-
public function testNoDistinctValues()
18+
public function testWithOneValue()
19+
{
20+
$def = new EnumNodeDefinition('foo');
21+
$def->values(array('foo'));
22+
23+
$node = $def->getNode();
24+
$this->assertEquals(array('foo'), $node->getValues());
25+
}
26+
27+
public function testWithOneDistinctValue()
2328
{
2429
$def = new EnumNodeDefinition('foo');
2530
$def->values(array('foo', 'foo'));
31+
32+
$node = $def->getNode();
33+
$this->assertEquals(array('foo'), $node->getValues());
2634
}
2735

2836
/**
@@ -35,6 +43,16 @@ public function testNoValuesPassed()
3543
$def->getNode();
3644
}
3745

46+
/**
47+
* @expectedException \InvalidArgumentException
48+
* @expectedExceptionMessage ->values() must be called with at least one value.
49+
*/
50+
public function testWithNoValues()
51+
{
52+
$def = new EnumNodeDefinition('foo');
53+
$def->values(array());
54+
}
55+
3856
public function testGetNode()
3957
{
4058
$def = new EnumNodeDefinition('foo');

0 commit comments

Comments
 (0)