Skip to content
Permalink
Browse files

bug #23925 [Validator] Fix use of GroupSequenceProvider in child clas…

…ses (linniksa)

This PR was squashed before being merged into the 2.7 branch (closes #23925).

Discussion
----------

[Validator] Fix use of GroupSequenceProvider in child classes

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | not in real cases
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

For example validation of doctrine proxy objects fails.

Commits
-------

8d7b203 [Validator] Fix use of GroupSequenceProvider in child classes
  • Loading branch information...
fabpot committed Aug 26, 2017
2 parents 459e6cb + 8d7b203 commit b4452f8b3fe505f85f5b0010286775b8f50a46a8
@@ -381,6 +381,10 @@ public function addGetterMethodConstraints($property, $method, array $constraint
*/
public function mergeConstraints(ClassMetadata $source)
{
if ($source->isGroupSequenceProvider()) {
$this->setGroupSequenceProvider(true);
}
foreach ($source->getConstraints() as $constraint) {
$this->addConstraint(clone $constraint);
}
@@ -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
{
}
@@ -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 @@ public function testGroupSequenceProvider()
$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 @@ public function testGetPropertyMetadataReturnsEmptyArrayWithoutConfiguredMetadat
$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
}

0 comments on commit b4452f8

Please sign in to comment.
You can’t perform that action at this time.