From f6cca42adff6d3377e4868fc4435a23d6787e4f7 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Wed, 4 Jan 2017 10:26:34 -0500 Subject: [PATCH] Fix cast null choice to string --- src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php | 2 +- .../Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php index 4a2588ef1d475..66b1d6ea79de2 100644 --- a/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php +++ b/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php @@ -234,7 +234,7 @@ private function castableToString(array $choices, array &$cache = array()) } continue; - } elseif (!is_scalar($choice)) { + } elseif (null !== $choice && !is_scalar($choice)) { return false; } diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php index 3b041eab293d1..019ea76fddb10 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/ArrayChoiceListTest.php @@ -135,14 +135,14 @@ public function testGetChoicesForValuesWithContainingNull() { $choiceList = new ArrayChoiceList(array('Null' => null)); - $this->assertSame(array(0 => null), $choiceList->getChoicesForValues(array('0'))); + $this->assertSame(array(0 => null), $choiceList->getChoicesForValues(array(''))); } public function testGetChoicesForValuesWithContainingFalseAndNull() { $choiceList = new ArrayChoiceList(array('False' => false, 'Null' => null)); - $this->assertSame(array(0 => null), $choiceList->getChoicesForValues(array('1'))); + $this->assertSame(array(0 => null), $choiceList->getChoicesForValues(array(''))); $this->assertSame(array(0 => false), $choiceList->getChoicesForValues(array('0'))); }