From ed211e9c74e50ec4eb3d7a78718563c06b59b17e Mon Sep 17 00:00:00 2001 From: Fred Cox Date: Thu, 9 Mar 2017 22:37:49 +0200 Subject: [PATCH] [Form] Choice type int values (BC Fix) --- .../Form/Extension/Core/Type/ChoiceType.php | 4 ++-- .../Tests/Extension/Core/Type/ChoiceTypeTest.php | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index b4b820ef26..1392c81a59 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -171,8 +171,8 @@ class ChoiceType extends AbstractType } foreach ($data as $v) { - if (null !== $v && !is_string($v)) { - throw new TransformationFailedException('All choices submitted must be NULL or strings.'); + if (null !== $v && !is_string($v) && !is_int($v)) { + throw new TransformationFailedException('All choices submitted must be NULL, strings or ints.'); } } }, 256); diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index b9097afdb6..983397b09d 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -1689,6 +1689,19 @@ class ChoiceTypeTest extends BaseTypeTest $this->assertNull($form[4]->getViewData()); } + public function testSubmitMultipleChoicesInts() + { + $form = $this->factory->create(static::TESTED_TYPE, null, array( + 'multiple' => true, + 'choices' => array_flip($this->numericChoicesFlipped), + 'choices_as_values' => true, + )); + + $form->submit(array(1, 2)); + + $this->assertTrue($form->isSynchronized()); + } + public function testSingleSelectedObjectChoices() { $view = $this->factory->create(static::TESTED_TYPE, $this->objectChoices[3], array( @@ -2306,7 +2319,7 @@ class ChoiceTypeTest extends BaseTypeTest $form->submit($submissionData); $this->assertFalse($form->isSynchronized()); - $this->assertEquals('All choices submitted must be NULL or strings.', $form->getTransformationFailure()->getMessage()); + $this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage()); } public function invalidNestedValueTestMatrix()