Skip to content

Commit 79cb3a1

Browse files
author
Mathias STRASSER
committed
Add NotNull constraint on map
Fix #1765 Fix #1654
1 parent 4a1b701 commit 79cb3a1

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Controller/Annotations/AbstractScalarParam.php

Lines changed: 4 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}
@@ -63,6 +64,9 @@ public function getConstraints()
6364
$constraints = array(
6465
new All(array('constraints' => $constraints)),
6566
);
67+
if (false === $this->nullable) {
68+
$constraints[] = new NotNull();
69+
}
6670
}
6771

6872
return $constraints;

Tests/Controller/Annotations/AbstractScalarParamTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function testConstraintsTransformWhenParamIsAnArray()
9696
$this->param->map = true;
9797
$this->assertEquals(array(new Constraints\All(array(
9898
new Constraints\NotNull(),
99-
))), $this->param->getConstraints());
99+
)), new Constraints\NotNull()), $this->param->getConstraints());
100100
}
101101

102102
public function testArrayWithNoConstraintsDoesNotCreateInvalidConstraint()

0 commit comments

Comments
 (0)