Skip to content

Commit af81c8c

Browse files
committed
bug #19388 [Validator][GroupSequence] fixed GroupSequence validation ignores PropetyMetadata of parent classes (Sandro Hopf)
This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #19388). Discussion ---------- [Validator][GroupSequence] fixed GroupSequence validation ignores PropetyMetadata of parent classes | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #19387 | License | MIT | Doc PR | N/A Commits ------- 54a7eff [Validator][GroupSequence] fixed GroupSequence validation ignores PropertyMetadata of parent classes
2 parents 6de4359 + 54a7eff commit af81c8c

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

src/Symfony/Component/Validator/Mapping/ClassMetadata.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ public function mergeConstraints(ClassMetadata $source)
350350
$member = clone $member;
351351

352352
foreach ($member->getConstraints() as $constraint) {
353+
$member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint;
353354
$constraint->addImplicitGroupName($this->getDefaultGroup());
354355
}
355356

src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,41 @@ public function testMergeConstraintsMergesMemberConstraints()
138138
$this->metadata->mergeConstraints($parent);
139139
$this->metadata->addPropertyConstraint('firstName', new ConstraintA());
140140

141+
$constraintA1 = new ConstraintA(array('groups' => array(
142+
'Default',
143+
'EntityParent',
144+
'Entity',
145+
)));
146+
$constraintA2 = new ConstraintA(array('groups' => array(
147+
'Default',
148+
'Entity',
149+
)));
150+
141151
$constraints = array(
142-
new ConstraintA(array('groups' => array(
143-
'Default',
144-
'EntityParent',
145-
'Entity',
146-
))),
147-
new ConstraintA(array('groups' => array(
148-
'Default',
149-
'Entity',
150-
))),
152+
$constraintA1,
153+
$constraintA2,
154+
);
155+
156+
$constraintsByGroup = array(
157+
'Default' => array(
158+
$constraintA1,
159+
$constraintA2,
160+
),
161+
'EntityParent' => array(
162+
$constraintA1,
163+
),
164+
'Entity' => array(
165+
$constraintA1,
166+
$constraintA2,
167+
),
151168
);
152169

153170
$members = $this->metadata->getPropertyMetadata('firstName');
154171

155172
$this->assertCount(1, $members);
156173
$this->assertEquals(self::PARENTCLASS, $members[0]->getClassName());
157174
$this->assertEquals($constraints, $members[0]->getConstraints());
175+
$this->assertEquals($constraintsByGroup, $members[0]->constraintsByGroup);
158176
}
159177

160178
public function testMemberMetadatas()

0 commit comments

Comments
 (0)