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
This commit is contained in:
commit
07d99c2b6f
@ -45,7 +45,7 @@ class FormValidator extends ConstraintValidator
|
||||
|
||||
// Validate the data against the constraints defined
|
||||
// in the form
|
||||
$constraints = $config->getOption('constraints');
|
||||
$constraints = $config->getOption('constraints', array());
|
||||
foreach ($constraints as $constraint) {
|
||||
foreach ($groups as $group) {
|
||||
if (in_array($group, $constraint->groups)) {
|
||||
|
@ -123,6 +123,17 @@ class FormValidatorTest extends AbstractConstraintValidatorTest
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testNotExistingConstraintIndex()
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory);
|
||||
$form = $form->setData($object)->getForm();
|
||||
|
||||
$this->validator->validate($form, new Form());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testValidateConstraintsEvenIfNoCascadeValidation()
|
||||
{
|
||||
$object = $this->getMock('\stdClass');
|
||||
|
Reference in New Issue
Block a user