[Validator] Fix use of GroupSequenceProvider in child classes

This commit is contained in:
Sergey Linnik 2017-08-18 00:27:11 +03:00 committed by Fabien Potencier
parent 26c9a0dc46
commit 8d7b203d80
3 changed files with 32 additions and 10 deletions

View File

@ -381,6 +381,10 @@ class ClassMetadata extends ElementMetadata implements ClassMetadataInterface
*/
public function mergeConstraints(ClassMetadata $source)
{
if ($source->isGroupSequenceProvider()) {
$this->setGroupSequenceProvider(true);
}
foreach ($source->getConstraints() as $constraint) {
$this->addConstraint(clone $constraint);
}

View File

@ -0,0 +1,16 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator\Tests\Fixtures;
class GroupSequenceProviderChildEntity extends GroupSequenceProviderEntity
{
}

View File

@ -24,6 +24,7 @@ class ClassMetadataTest extends TestCase
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
const PROVIDERCLASS = 'Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity';
const PROVIDERCHILDCLASS = 'Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderChildEntity';
protected $metadata;
@ -301,6 +302,17 @@ class ClassMetadataTest extends TestCase
$this->assertTrue($metadata->isGroupSequenceProvider());
}
public function testMergeConstraintsMergesGroupSequenceProvider()
{
$parent = new ClassMetadata(self::PROVIDERCLASS);
$parent->setGroupSequenceProvider(true);
$metadata = new ClassMetadata(self::PROVIDERCHILDCLASS);
$metadata->mergeConstraints($parent);
$this->assertTrue($metadata->isGroupSequenceProvider());
}
/**
* https://github.com/symfony/symfony/issues/11604.
*/
@ -309,13 +321,3 @@ class ClassMetadataTest extends TestCase
$this->assertCount(0, $this->metadata->getPropertyMetadata('foo'), '->getPropertyMetadata() returns an empty collection if no metadata is configured for the given property');
}
}
class ParentClass
{
public $example = 0;
}
class ChildClass extends ParentClass
{
public $example = 1; // overrides parent property of same name
}