[Form] Fix show float values as choices values in ChoiceType
This commit is contained in:
parent
620ea20f49
commit
35642288fa
|
@ -236,7 +236,11 @@ class ArrayChoiceList implements ChoiceListInterface
|
|||
continue;
|
||||
} elseif (!is_scalar($choice)) {
|
||||
return false;
|
||||
} elseif (isset($cache[$choice])) {
|
||||
}
|
||||
|
||||
$choice = false === $choice ? '0' : (string) $choice;
|
||||
|
||||
if (isset($cache[$choice])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,12 +34,12 @@ class ArrayChoiceListTest extends AbstractChoiceListTest
|
|||
|
||||
protected function getChoices()
|
||||
{
|
||||
return array(0, 1, '1', 'a', false, true, $this->object, null);
|
||||
return array(0, 1, 1.5, '1', 'a', false, true, $this->object, null);
|
||||
}
|
||||
|
||||
protected function getValues()
|
||||
{
|
||||
return array('0', '1', '2', '3', '4', '5', '6', '7');
|
||||
return array('0', '1', '2', '3', '4', '5', '6', '7', '8');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -162,4 +162,13 @@ class ArrayChoiceListTest extends AbstractChoiceListTest
|
|||
$this->assertSame(array(0 => true), $choiceList->getChoicesForValues(array('1')));
|
||||
$this->assertSame(array(0 => false), $choiceList->getChoicesForValues(array('0')));
|
||||
}
|
||||
|
||||
public function testGetChoicesForValuesWithContainingEmptyStringAndFloats()
|
||||
{
|
||||
$choiceList = new ArrayChoiceList(array('Empty String' => '', '1/3' => 0.3, '1/2' => 0.5));
|
||||
|
||||
$this->assertSame(array(0 => ''), $choiceList->getChoicesForValues(array('')));
|
||||
$this->assertSame(array(0 => 0.3), $choiceList->getChoicesForValues(array('0.3')));
|
||||
$this->assertSame(array(0 => 0.5), $choiceList->getChoicesForValues(array('0.5')));
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue