From b44e67d2662226f36bce29463400a3d63f7171e1 Mon Sep 17 00:00:00 2001 From: DZunke Date: Tue, 8 Dec 2015 09:03:22 +0100 Subject: [PATCH 1/4] [Form] Fix constraints could be null if not set If the form options has no key for constraints the default should be an empty array to be ignored by the loop. --- .../Form/Extension/Validator/Constraints/FormValidator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php index f862970a7fd81..5792aa40828c7 100644 --- a/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php +++ b/src/Symfony/Component/Form/Extension/Validator/Constraints/FormValidator.php @@ -45,7 +45,7 @@ public function validate($form, Constraint $constraint) // 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)) { From 54f527e82bdadaa13fff9dc13d7f0643d8a88eb3 Mon Sep 17 00:00:00 2001 From: DZunke Date: Thu, 10 Dec 2015 17:18:29 +0100 Subject: [PATCH 2/4] [Form] Add test for non existing constraints option --- .../Validator/Constraints/FormValidatorTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index c440a0470abbe..9109a22284e36 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -123,6 +123,19 @@ public function testDontValidateIfParentWithoutCascadeValidation() $this->assertNoViolation(); } + public function testNotExistingConstraintIndex() + { + $object = $this->getMock('\stdClass'); + $options = array(); + + $form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory, $options); + $form = $form->setData($object)->getForm(); + + $this->validator->validate($form, new Form()); + + $this->assertNoViolation(); + } + public function testValidateConstraintsEvenIfNoCascadeValidation() { $object = $this->getMock('\stdClass'); From bc33787153a391338371c82d6de974c7a96ec0f7 Mon Sep 17 00:00:00 2001 From: DZunke Date: Wed, 23 Dec 2015 09:52:57 +0100 Subject: [PATCH 3/4] [Form] Optimize testNotExistingConstraintIndex --- .../Extension/Validator/Constraints/FormValidatorTest.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index 9109a22284e36..a2357cd5ffff2 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -125,10 +125,8 @@ public function testDontValidateIfParentWithoutCascadeValidation() public function testNotExistingConstraintIndex() { - $object = $this->getMock('\stdClass'); - $options = array(); - - $form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory, $options); + $object = new \stdClass; + $form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory); $form = $form->setData($object)->getForm(); $this->validator->validate($form, new Form()); From 6fc2ed2ffc0dad5cfdd94ed9ae950cf4395857ef Mon Sep 17 00:00:00 2001 From: DZunke Date: Wed, 23 Dec 2015 09:55:19 +0100 Subject: [PATCH 4/4] [Form] Fix coding standard in testNotExistingConstraintIndex --- .../Tests/Extension/Validator/Constraints/FormValidatorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index a2357cd5ffff2..1e30f237a5632 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -125,7 +125,7 @@ public function testDontValidateIfParentWithoutCascadeValidation() public function testNotExistingConstraintIndex() { - $object = new \stdClass; + $object = new \stdClass(); $form = new FormBuilder('name', '\stdClass', $this->dispatcher, $this->factory); $form = $form->setData($object)->getForm();