Skip to content

Commit

Permalink
bug #21208 [Validator] Add object handling of invalid constraints in …
Browse files Browse the repository at this point in the history
…Composite (SenseException)

This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #21208).

Discussion
----------

[Validator] Add object handling of invalid constraints in Composite

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21206
| License       | MIT
| Doc PR        | n/a

This PR fixes a minor bug described in #21206. The constraint `Symfony\Component\Validator\Constraints\Composite` doesn't check in it's exception handling if the wrongly created instance of a nested constraint is an object, which is the expected type for a constraint.

Commits
-------

4bd2c22 [Validator] Add object handling of invalid constraints in Composite
  • Loading branch information
fabpot committed Mar 22, 2017
2 parents f9b64a2 + 4bd2c22 commit ad95227
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Constraints/Composite.php
Expand Up @@ -67,6 +67,10 @@ public function __construct($options = null)

foreach ($nestedConstraints as $constraint) {
if (!$constraint instanceof Constraint) {
if (is_object($constraint)) {
$constraint = get_class($constraint);
}

throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, get_class($this)));
}

Expand Down
Expand Up @@ -125,6 +125,17 @@ public function testFailIfNoConstraint()
));
}

/**
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
*/
public function testFailIfNoConstraintObject()
{
new ConcreteComposite(array(
new NotNull(array('groups' => 'Default')),
new \ArrayObject(),
));
}

/**
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
*/
Expand Down

0 comments on commit ad95227

Please sign in to comment.