diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php index 655609300ad9b..abe29277056b8 100644 --- a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php @@ -94,7 +94,7 @@ public function accept(ValidationVisitorInterface $visitor, $value, $group, $pro } foreach ($groups as $group) { - $this->accept($visitor, $value, $group, $propertyPath, Constraint::DEFAULT_GROUP); + $this->accept($visitor, $value, $group, $propertyPath, ($this->defaultGroup === $group) ? Constraint::DEFAULT_GROUP : null); if (count($visitor->getViolations()) > 0) { break; diff --git a/src/Symfony/Component/Validator/Tests/ValidationVisitorTest.php b/src/Symfony/Component/Validator/Tests/ValidationVisitorTest.php index 2fe4395c2d2ac..4573944a34f31 100644 --- a/src/Symfony/Component/Validator/Tests/ValidationVisitorTest.php +++ b/src/Symfony/Component/Validator/Tests/ValidationVisitorTest.php @@ -203,6 +203,38 @@ public function testValidateInGroupSequencePropagatesDefaultGroup() $this->assertEquals($violations, $this->visitor->getViolations()); } + public function testValidateInGroupSequenceCascadeWithExplicitGroup() + { + $entity = new Entity(); + $entity->reference = new Reference(); + + $this->metadata->addPropertyConstraint('reference', new Valid()); + $this->metadata->setGroupSequence(array($this->metadata->getDefaultGroup(), 'Reference')); + + $referenceMetadata = new ClassMetadata(get_class($entity->reference)); + $referenceMetadata->addConstraint(new FailingConstraint(array( + 'groups' => 'Reference', + ))); + $this->metadataFactory->addMetadata($referenceMetadata); + + $this->visitor->validate($entity, 'Default', ''); + + // The validation of the reference's FailingConstraint in group + // "Reference" was launched + $violations = new ConstraintViolationList(array( + new ConstraintViolation( + 'Failed', + 'Failed', + array(), + 'Root', + 'reference', + $entity->reference + ), + )); + + $this->assertEquals($violations, $this->visitor->getViolations()); + } + public function testValidateInOtherGroupTraversesNoGroupSequence() { $entity = new Entity(); @@ -217,7 +249,7 @@ public function testValidateInOtherGroupTraversesNoGroupSequence() $this->visitor->validate($entity, $this->metadata->getDefaultGroup(), ''); - // Only group "Second" was validated + // Only group "Entity" was validated $violations = new ConstraintViolationList(array( new ConstraintViolation( 'Failed',