Skip to content

Commit

Permalink
bug #21183 [Validator] respect groups when merging constraints (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 2.7 branch.

Discussion
----------

[Validator] respect groups when merging constraints

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

Commits
-------

9a60057 respect groups when merging constraints
  • Loading branch information
fabpot committed Jan 10, 2017
2 parents c584769 + 9a60057 commit f83ad56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Expand Up @@ -354,7 +354,10 @@ public function mergeConstraints(ClassMetadata $source)
$member = clone $member;

foreach ($member->getConstraints() as $constraint) {
$member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint;
if (in_array($constraint::DEFAULT_GROUP, $constraint->groups, true)) {
$member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint;
}

$constraint->addImplicitGroupName($this->getDefaultGroup());
}

Expand Down
Expand Up @@ -135,6 +135,7 @@ public function testMergeConstraintsMergesMemberConstraints()
{
$parent = new ClassMetadata(self::PARENTCLASS);
$parent->addPropertyConstraint('firstName', new ConstraintA());
$parent->addPropertyConstraint('firstName', new ConstraintB(array('groups' => 'foo')));

$this->metadata->mergeConstraints($parent);
$this->metadata->addPropertyConstraint('firstName', new ConstraintA());
Expand All @@ -148,9 +149,13 @@ public function testMergeConstraintsMergesMemberConstraints()
'Default',
'Entity',
)));
$constraintB = new ConstraintB(array(
'groups' => array('foo'),
));

$constraints = array(
$constraintA1,
$constraintB,
$constraintA2,
);

Expand All @@ -166,6 +171,9 @@ public function testMergeConstraintsMergesMemberConstraints()
$constraintA1,
$constraintA2,
),
'foo' => array(
$constraintB,
),
);

$members = $this->metadata->getPropertyMetadata('firstName');
Expand Down

0 comments on commit f83ad56

Please sign in to comment.