From 682ca1ac1bb5d7639ec128deef414c5ed9dee657 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sun, 9 Dec 2018 10:06:15 +0100 Subject: [PATCH 1/2] Apply NotBlank only to the whole array --- Controller/Annotations/AbstractScalarParam.php | 11 ++++------- .../Annotations/AbstractScalarParamTest.php | 1 - 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Controller/Annotations/AbstractScalarParam.php b/Controller/Annotations/AbstractScalarParam.php index abffe0121..21f05254d 100644 --- a/Controller/Annotations/AbstractScalarParam.php +++ b/Controller/Annotations/AbstractScalarParam.php @@ -56,10 +56,6 @@ public function getConstraints() )); } - if (false === $this->allowBlank) { - $constraints[] = new NotBlank(); - } - // If the user wants to map the value, apply all constraints to every // value of the map if ($this->map) { @@ -69,9 +65,10 @@ public function getConstraints() if (false === $this->nullable) { $constraints[] = new NotNull(); } - if (false === $this->allowBlank) { - $constraints[] = new NotBlank(); - } + } + + if (false === $this->allowBlank) { + $constraints[] = new NotBlank(); } return $constraints; diff --git a/Tests/Controller/Annotations/AbstractScalarParamTest.php b/Tests/Controller/Annotations/AbstractScalarParamTest.php index 8e65172ea..8f5cc71b4 100644 --- a/Tests/Controller/Annotations/AbstractScalarParamTest.php +++ b/Tests/Controller/Annotations/AbstractScalarParamTest.php @@ -106,7 +106,6 @@ public function testArrayWithBlankConstraintsWhenParamIsAnArray() $this->param->allowBlank = false; $this->assertEquals(array(new Constraints\All(array( new Constraints\NotNull(), - new Constraints\NotBlank(), )), new Constraints\NotNull(), new Constraints\NotBlank()), $this->param->getConstraints()); } From 193161debe9d2a37b695cf8ec418c1abaabe8615 Mon Sep 17 00:00:00 2001 From: Guilhem Niot Date: Sat, 15 Dec 2018 14:37:31 +0100 Subject: [PATCH 2/2] Fix --- Controller/Annotations/AbstractScalarParam.php | 8 ++++---- Tests/Controller/Annotations/AbstractScalarParamTest.php | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Controller/Annotations/AbstractScalarParam.php b/Controller/Annotations/AbstractScalarParam.php index 21f05254d..dd67c1741 100644 --- a/Controller/Annotations/AbstractScalarParam.php +++ b/Controller/Annotations/AbstractScalarParam.php @@ -56,6 +56,10 @@ public function getConstraints() )); } + if (false === $this->allowBlank) { + $constraints[] = new NotBlank(); + } + // If the user wants to map the value, apply all constraints to every // value of the map if ($this->map) { @@ -67,10 +71,6 @@ public function getConstraints() } } - if (false === $this->allowBlank) { - $constraints[] = new NotBlank(); - } - return $constraints; } } diff --git a/Tests/Controller/Annotations/AbstractScalarParamTest.php b/Tests/Controller/Annotations/AbstractScalarParamTest.php index 8f5cc71b4..a8499ab73 100644 --- a/Tests/Controller/Annotations/AbstractScalarParamTest.php +++ b/Tests/Controller/Annotations/AbstractScalarParamTest.php @@ -106,7 +106,8 @@ public function testArrayWithBlankConstraintsWhenParamIsAnArray() $this->param->allowBlank = false; $this->assertEquals(array(new Constraints\All(array( new Constraints\NotNull(), - )), new Constraints\NotNull(), new Constraints\NotBlank()), $this->param->getConstraints()); + new Constraints\NotBlank(), + )), new Constraints\NotNull()), $this->param->getConstraints()); } public function testArrayWithNoConstraintsDoesNotCreateInvalidConstraint()