8000 [Validator] Fixed Constraint class to not destroy custom groups upon serialization by webmozart · Pull Request #11691 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Fixed Constraint class to not destroy custom groups upon serialization #11691

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
Aug 19, 2014
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
8000 Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function getTargets()
public function __sleep()
{
// Initialize "groups" option if it is not set
$this->__get('groups');
$this->groups;

return array_keys(get_object_vars($this));
}
Expand Down
24 changes: 18 additions & 6 deletions src/Symfony/Component/Validator/Tests/ConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,34 @@ public function testSerialize()
$this->assertEquals($constraint, $restoredConstraint);
}

public function testSerializeInitializesGroupsOption()
public function testSerializeInitializesGroupsOptionToDefault()
{
$constraintWithExplicitGroup = new ConstraintA(array(
$constraint = new ConstraintA(array(
'property1' => 'foo',
'property2' => 'bar',
));

$constraint = unserialize(serialize($constraint));

$expected = new ConstraintA(array(
'property1' => 'foo',
'property2' => 'bar',
'groups' => 'Default',
));

$constraintWithoutExplicitGroup = new ConstraintA(array(
$this->assertEquals($expected, $constraint);
}

public function testSerializeKeepsCustomGroups()
{
$constraint = new ConstraintA(array(
'property1' => 'foo',
'property2' => 'bar',
'groups' => 'MyGroup',
));

$constraintWithExplicitGroup = unserialize(serialize($constraintWithExplicitGroup));
$constraintWithoutExplicitGroup = unserialize(serialize($constraintWithoutExplicitGroup));
$constraint = unserialize(serialize($constraint));

$this->assertEquals($constraintWithExplicitGroup, $constraintWithoutExplicitGroup);
$this->assertSame(array('MyGroup'), $constraint->groups);
}
}
0