[Form] Fix constraints could be null if not set

This commit is contained in:
DZunke 2015-12-08 09:03:22 +01:00 committed by Fabien Potencier
parent e5dda019ae
commit f80e0eb143
2 changed files with 12 additions and 1 deletions

View File

@ -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)) {

View File

@ -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');