[Form] ArrayChoiceList can now deal with a null in choices

This commit is contained in:
Issei.M 2016-01-23 17:56:23 +09:00
parent 15c37c2442
commit 68292bb52b
2 changed files with 8 additions and 1 deletions

View File

@ -141,7 +141,7 @@ class ArrayChoiceList implements ChoiceListInterface
$choices = array();
foreach ($values as $i => $givenValue) {
if (isset($this->choices[$givenValue])) {
if (array_key_exists($givenValue, $this->choices)) {
$choices[$i] = $this->choices[$givenValue];
}
}

View File

@ -130,4 +130,11 @@ class ArrayChoiceListTest extends AbstractChoiceListTest
$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')));
}
}