Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Validator] Fixed group sequence using explicit group for cascaded pr… #15659

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

Closed
wants to merge 1 commit into from
Closed
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.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 33 additions & 1 deletion src/Symfony/Component/Validator/Tests/ValidationVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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',
Expand Down