Fix to allow null values in labels array

This commit is contained in:
kaywalker 2012-08-30 19:08:45 +03:00 committed by Fabien Potencier
parent a22111b913
commit 4e909bd016
2 changed files with 17 additions and 1 deletions

View File

@ -261,7 +261,7 @@ class ChoiceList implements ChoiceListInterface
{
// Add choices to the nested buckets
foreach ($choices as $group => $choice) {
if (!isset($labels[$group])) {
if (!array_key_exists($group, $labels)) {
throw new \InvalidArgumentException('The structures of the choices and labels array do not match.');
}

View File

@ -184,4 +184,20 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase
array('A')
);
}
/**
* test for pull request: https://github.com/symfony/symfony/pull/5394
*/
public function testLabelsContainingNull()
{
$this->list = new ChoiceList(
array($this->obj1, $this->obj2),
array('A', null)
);
$this->assertEquals(
array(0 => new ChoiceView($this->obj1, '0', 'A'), 1 => new ChoiceView($this->obj2, '1', null)),
$this->list->getRemainingViews()
);
}
}