From 4e909bd016b549b7b2a368e48c4f34200e62c89d Mon Sep 17 00:00:00 2001 From: kaywalker Date: Thu, 30 Aug 2012 19:08:45 +0300 Subject: [PATCH] Fix to allow null values in labels array --- .../Extension/Core/ChoiceList/ChoiceList.php | 2 +- .../Extension/Core/ChoiceList/ChoiceListTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php index fcccfdd0bd..4fbca4b451 100644 --- a/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php +++ b/src/Symfony/Component/Form/Extension/Core/ChoiceList/ChoiceList.php @@ -261,7 +261,7 @@ class ChoiceList implements ChoiceListInterface { // Add choices to the nested buckets foreach ($choices as $group => $choice) { - if (!isset($labels[$group])) { + if (!array_key_exists($group, $labels)) { throw new \InvalidArgumentException('The structures of the choices and labels array do not match.'); } diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php index 86533e8af8..7e967924d3 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/ChoiceList/ChoiceListTest.php @@ -184,4 +184,20 @@ class ChoiceListTest extends \PHPUnit_Framework_TestCase array('A') ); } + + /** + * test for pull request: https://github.com/symfony/symfony/pull/5394 + */ + public function testLabelsContainingNull() + { + $this->list = new ChoiceList( + array($this->obj1, $this->obj2), + array('A', null) + ); + + $this->assertEquals( + array(0 => new ChoiceView($this->obj1, '0', 'A'), 1 => new ChoiceView($this->obj2, '1', null)), + $this->list->getRemainingViews() + ); + } }