Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4688f99

Browse filesBrowse files
committed
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
2 parents 5cf36ad + e9111e4 commit 4688f99
Copy full SHA for 4688f99

File tree

2 files changed

+25
-7
lines changed
Filter options

2 files changed

+25
-7
lines changed

‎src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php
+2-2Lines 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;

‎src/Symfony/Component/Config/Tests/Definition/Builder/EnumNodeDefinitionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Config/Tests/Definition/Builder/EnumNodeDefinitionTest.php
+23-5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.