8000 [Form] ArrayChoiceList can now deal with a null in choices · symfony/symfony@68292bb · GitHub
[go: up one dir, main page]

Skip to content

Commit 68292bb

Browse files
committed
[Form] ArrayChoiceList can now deal with a null in choices
1 parent 15c37c2 commit 68292bb

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function getChoicesForValues(array $values)
141141
$choices = array();
142142

143143
foreach ($values as $i => $givenValue) {
144-
if (isset($this->choices[$givenValue])) {
144+
if (array_key_exists($givenValue, $this->choices)) {
145145
$choices[$i] = $this->choices[$givenValue];
146146
}
147147
}

src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,11 @@ public function testCompareChoicesByIdentityByDefault()
130130
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => $obj2)));
131131
$this->assertSame(array(2 => 'value2'), $choiceList->getValuesForChoices(array(2 => (object) array('value' => 'value2'))));
132132
}
133+
134+
public function testGetChoicesForValuesWithContainingNull()
135+
{
136+
$choiceList = new ArrayChoiceList(array('Null' => null));
137+
138+
$this->assertSame(array(0 => null), $choiceList->getChoicesForValues(array('0')));
139+
}
133140
}

0 commit comments

Comments
 (0)
0