8000 bug #16897 [Form] Fix constraints could be null if not set (DZunke) · symfony/symfony@07d99c2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 07d99c2

Browse files
committed
bug #16897 [Form] Fix constraints could be null if not set (DZunke)
This PR was squashed before being merged into the 2.3 branch (closes #16897). Discussion ---------- [Form] Fix constraints could be null if not set | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - If the form options has no key for constraints the default should be an empty array to be ignored by the loop in the FormValidator. The default without this fix is ```null``` and foreach will throw an error. The "Bug" also still exists in master-Branch. Commits ------- f80e0eb [Form] Fix constraints could be null if not set
2 parents 414365d + f80e0eb commit 07d99c2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function validate($form, Constraint $constraint)
4545

4646
// Validate the data against the constraints defined
4747
// in the form
48-
$constraints = $config->getOption('constraints');
48+
$constraints = $config->getOption('constraints', array());
4949
foreach ($constraints as $constraint) {
5050
foreach ($groups as $group) {
5151
if (in_array($group, $constraint->groups)) {

src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ public function testDontValidateIfParentWithoutCascadeValidation()
123123
$this->assertNoViolation();
124124
}
125125

126+
public function testNotExistingConstraintIndex()
127+
{
128+
$object = new \stdClass();
129+
$form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory);
130+
$form = $form->setData($object)->getForm();
131+
132+
$this->validator->validate($form, new Form());
133+
134+
$this->assertNoViolation();
135+
}
136+
126137
public function testValidateConstraintsEvenIfNoCascadeValidation()
127138
{
128139
$object = $this->getMock('\stdClass');

0 commit comments

Comments
 (0)
0