8000 [Validator] Add object handling of invalid constraints in Composite · symfony/symfony@4bd2c22 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4bd2c22

Browse files
SenseExceptionfabpot
authored andcommitted
[Validator] Add object handling of invalid constraints in Composite
1 parent f9b64a2 commit 4bd2c22

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Symfony/Component/Validator/Constraints/Composite.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public function __construct($options = null)
6767

6868
foreach ($nestedConstraints as $constraint) {
6969
if (!$constraint instanceof Constraint) {
70+
if (is_object($constraint)) {
71+
$constraint = get_class($constraint);
72+
}
73+
7074
throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, get_class($this)));
7175
}
7276

src/Symfony/Component/Validator/Tests/Constraints/CompositeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,17 @@ public function testFailIfNoConstraint()
125125
));
126126
}
127127

128+
/**
129+
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
130+
*/
131+
public function testFailIfNoConstraintObject()
132+
{
133+
new ConcreteComposite(array(
134+
new NotNull(array('groups' => 'Default')),
135+
new \ArrayObject(),
136+
));
137+
}
138+
128139
/**
129140
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
130141
*/

0 commit comments

Comments
 (0)
0