8000 [Validator] respect groups when merging constraints by xabbuh · Pull Request #21183 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] respect groups when merging constraints #21183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
< 8000 span data-view-component="true"> Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually you might have to call that prior to the previous if statement?

8000 Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That shouldn't make a difference.

}

Expand Down
Original file line number Diff line number Diff line change
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