Skip to content

Commit

Permalink
bug #23925 [Validator] Fix use of GroupSequenceProvider in child clas…
Browse files Browse the repository at this point in the history
…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 b4452f8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Expand Up @@ -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);
}
Expand Down
@@ -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
{
}
22 changes: 12 additions & 10 deletions src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
*/
Expand All @@ -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.