8000 [Validator] property constraints can be added in child classes by xabbuh · Pull Request #21592 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] property constraints can be added in child classes #21592

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 2 commits into from
Feb 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
8000 Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
property constraints can be added in child classes
  • Loading branch information
xabbuh committed Feb 13, 2017
commit 9513a8aa526ba3818667900e5dda355f1d3053b0
4 changes: 0 additions & 4 deletions src/Symfony/Component/Validator/Mapping/ClassMetadata.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,6 @@ public function mergeConstraints(ClassMetadata $source)
}

foreach ($source->getConstrainedProperties() as $property) {
if ($this->hasPropertyMetadata($property)) {
continue;
}

foreach ($source->getPropertyMetadata($property) as $member) {
$member = clone $member;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Validator\Tests\Mapping;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\GreaterThan;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
Expand Down Expand Up @@ -304,21 +303,6 @@ public function testGetPropertyMetadataReturnsEmptyArrayWithoutConfiguredMetadat
{
$this->assertCount(0, $this->metadata->getPropertyMetadata('foo'), '->getPropertyMetadata() returns an empty collection if no metadata is configured for the given property');
}

public function testMergeDoesOverrideConstraintsFromParentClassIfPropertyIsOverriddenInChildClass()
{
$parentMetadata = new ClassMetadata('\Symfony\Component\Validator\Tests\Mapping\ParentClass');
$parentMetadata->addPropertyConstraint('example', new GreaterThan(0));

$childMetadata = new ClassMetadata('\Symfony\Component\Validator\Tests\Mapping\ChildClass');
8000 $childMetadata->addPropertyConstraint('example', new GreaterThan(1));
$childMetadata->mergeConstraints($parentMetadata);

$expectedMetadata = new ClassMetadata('\Symfony\Component\Validator\Tests\Mapping\ChildClass');
$expectedMetadata->addPropertyConstraint('example', new GreaterThan(1));

$this->assertEquals($expectedMetadata, $childMetadata);
}
}

class ParentClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,14 @@ public function testGroupsFromParent()
$reader = new \Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader();
$factory = new LazyLoadingMetadataFactory($reader);
$metadata = $factory->getMetadataFor('Symfony\Component\Validator\Tests\Fixtures\EntityStaticCarTurbo');
$classMetaData = $metadata->getPropertyMetadata('wheels');
$constraints = $classMetaData[0]->getConstraints();
$groups = $constraints[0]->groups;
$groups = array();

foreach ($metadata->getPropertyMetadata('wheels') as $propertyMetadata) {
$constraints = $propertyMetadata->getConstraints();
$groups = array_replace($groups, $constraints[0]->groups);
}

$this->assertCount(4, $groups);
$this->assertContains('Default', $groups);
$this->assertContains('EntityStaticCarTurbo', $groups);
$this->assertContains('EntityStaticCar', $groups);
Expand Down
0