Skip to content

Commit da82449

Browse files
committed
Merge branch '2.8' into 3.0
* 2.8: [DependencyInjection] fix dumped YAML snytax Remove InputOption::VALUE_REQUIRED mode from $default parameter description as InputOption::setDefault() throws an exception only when called in InputOption::VALUE_NONE mode. In practice the $default value could still be accessed in InputOption::VALUE_REQUIRED mode in case InputOption was never set but accessed from InputDefinition::getOption() method [Form] Fixed violation mapping if multiple forms are using the same (or part of the same) property path fix FQCN in tests added by #17694 Fix locale and written standard inconsistencies for Norwegian translations [Form] [Validator] Fix locale inconsistencies in Norwegian translations [TwigBridge] Symfony 3.1 forward compatibility fixed CS [DependencyInjection] fixed exceptions thrown by get method of ContainerBuilder [Yaml] properly parse lists in object maps [FrameworkBundle] Remove unused private method. [Form] remove useless code in ResizeFormListener [Config] Fix EnumNodeDefinition to allow building enum nodes with one element fix choice_value option in EntityType and add some tests
2 parents f92caa5 + 3b017a6 commit da82449

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)