Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c37037

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: [Form] Choice type int values (BC Fix)
2 parents d1cadf0 + 641092f commit 3c37037

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
171171
}
172172

173173
foreach ($data as $v) {
174-
if (null !== $v && !is_string($v)) {
175-
throw new TransformationFailedException('All choices submitted must be NULL or strings.');
174+
if (null !== $v && !is_string($v) && !is_int($v)) {
175+
throw new TransformationFailedException('All choices submitted must be NULL, strings or ints.');
176176
}
177177
}
178178
}, 256);

src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,6 +1698,19 @@ public function testSubmitMultipleExpandedNumericChoices()
16981698
$this->assertNull($form[4]->getViewData());
16991699
}
17001700

1701+
public function testSubmitMultipleChoicesInts()
1702+
{
1703+
$form = $this->factory->create(static::TESTED_TYPE, null, array(
1704+
'multiple' => true,
1705+
'choices' => array_flip($this->numericChoicesFlipped),
1706+
'choices_as_values' => true,
1707+
));
1708+
1709+
$form->submit(array(1, 2));
1710+
1711+
$this->assertTrue($form->isSynchronized());
1712+
}
1713+
17011714
public function testSingleSelectedObjectChoices()
17021715
{
17031716
$view = $this->factory->create(static::TESTED_TYPE, $this->objectChoices[3], array(
@@ -2315,7 +2328,7 @@ public function testSubmitInvalidNestedValue($multiple, $expanded, $submissionDa
23152328

23162329
$form->submit($submissionData);
23172330
$this->assertFalse($form->isSynchronized());
2318-
$this->assertEquals('All choices submitted must be NULL or strings.', $form->getTransformationFailure()->getMessage());
2331+
$this->assertEquals('All choices submitted must be NULL, strings or ints.', $form->getTransformationFailure()->getMessage());
23192332
}
23202333

23212334
public function invalidNestedValueTestMatrix()

0 commit comments

Comments
 (0)