Skip to content

Commit 558b149

Browse files
authored
Merge pull request #1769 from roukmoute/fix_map
Fix problems with map option
2 parents f36db22 + da8d1ff commit 558b149

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Controller/Annotations/AbstractScalarParam.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Validator\Constraint;
1616
use Symfony\Component\Validator\Constraints\NotBlank;
1717
use Symfony\Component\Validator\Constraints\All;
18+
use Symfony\Component\Validator\Constraints\NotNull;
1819

1920
/**
2021
* {@inheritdoc}
@@ -65,6 +66,12 @@ public function getConstraints()
6566
$constraints = array(
6667
new All(array('constraints' => $constraints)),
6768
);
69+
if (false === $this->nullable) {
70+
$constraints[] = new NotNull();
71+
}
72+
if (false === $this->allowBlank) {
73+
$constraints[] = new NotBlank();
74+
}
6875
}
6976

7077
return $constraints;

Tests/Controller/Annotations/AbstractScalarParamTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,17 @@ public function testConstraintsTransformWhenParamIsAnArray()
9797
$this->param->map = true;
9898
$this->assertEquals(array(new Constraints\All(array(
9999
new Constraints\NotNull(),
100-
))), $this->param->getConstraints());
100+
)), new Constraints\NotNull()), $this->param->getConstraints());
101+
}
102+
103+
public function testArrayWithBlankConstraintsWhenParamIsAnArray()
104+
{
105+
$this->param->map = true;
106+
$this->param->allowBlank = false;
107+
$this->assertEquals(array(new Constraints\All(array(
108+
new Constraints\NotNull(),
109+
new Constraints\NotBlank(),
110+
)), new Constraints\NotNull(), new Constraints\NotBlank()), $this->param->getConstraints());
101111
}
102112

103113
public function testArrayWithNoConstraintsDoesNotCreateInvalidConstraint()

0 commit comments

Comments
 (0)