Skip to content

[Config] Fix EnumNodeDefinition to allow building enum nodes with one element #17790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function values(array $values)
{
$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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@

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());
}

/**
Expand All @@ -35,6 +43,16 @@ public function testNoValuesPassed()
$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');
Expand Down