Skip to content

Commit

Permalink
[Form] ArrayChoiceList can now deal with a null in choices
Browse files Browse the repository at this point in the history
  • Loading branch information
issei-m committed Jan 23, 2016
1 parent 15c37c2 commit 68292bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php
Expand Up @@ -141,7 +141,7 @@ public function getChoicesForValues(array $values)
$choices = array();

foreach ($values as $i => $givenValue) {
if (isset($this->choices[$givenValue])) {
if (array_key_exists($givenValue, $this->choices)) {
$choices[$i] = $this->choices[$givenValue];
}
}
Expand Down
Expand Up @@ -130,4 +130,11 @@ public function testCompareChoicesByIdentityByDefault()
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => $obj2)));
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => (object) array('value' => 'value2'))));
}

public function testGetChoicesForValuesWithContainingNull()
{
$choiceList = new ArrayChoiceList(array('Null' => null));

$this->assertSame(array(0 => null), $choiceList->getChoicesForValues(array('0')));
}
}

0 comments on commit 68292bb

Please sign in to comment.