8000 bug #23925 [Validator] Fix use of GroupSequenceProvider in child clas… · symfony/symfony@b4452f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit b4452f8

Browse files
committed
bug #23925 [Validator] Fix use of GroupSequenceProvider in child classes (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
2 parents 459e6cb + 8d7b203 commit b4452f8

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

src/Symfony/Component/Validator/Mapping/ClassMetadata.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ public function addGetterMethodConstraints($property, $method, array $constraint
381381
*/
382382
public function mergeConstraints(ClassMetadata $source)
383383
{
384+
if ($source->isGroupSequenceProvider()) {
385+
$this->setGroupSequenceProvider(true);
386+
}
387+
384388
foreach ($source->getConstraints() as $constraint) {
385389
$this->addConstraint(clone $constraint);
386390
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Validator\Tests\Fixtures;
13+
14+
class GroupSequenceProviderChildEntity extends GroupSequenceProviderEntity
15+
{
16+
}

src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ClassMetadataTest extends TestCase
2424
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
2525
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
2626
const PROVIDERCLASS = 'Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity';
27+
const PROVIDERCHILDCLASS = 'Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderChildEntity';
2728

2829
protected $metadata;
2930

@@ -301,6 +302,17 @@ public function testGroupSequenceProvider()
301302
$this->assertTrue($metadata->isGroupSequenceProvider());
302303
}
303304

305+
public function testMergeConstraintsMergesGroupSequenceProvider()
306+
{
307+
$parent = new ClassMetadata(self::PROVIDERCLASS);
308+
$parent->setGroupSequenceProvider(true);
309+
310+
$metadata = new ClassMetadata(self::PROVIDERCHILDCLASS);
311+
$metadata->mergeConstraints($parent);
312+
313+
$this->assertTrue($metadata->isGroupSequenceProvider());
314+
}
315+
304316
/**
305317
* https://github.com/symfony/symfony/issues/11604.
306318
*/
@@ -309,13 +321,3 @@ public function testGetPropertyMetadataReturnsEmptyArrayWithoutConfiguredMetadat
309321
$this->assertCount(0, $this->metadata->getPropertyMetadata('foo'), '->getPropertyMetadata() returns an empty collection if no metadata is configured for the given property');
310322
}
311323
}
312-
313-
class ParentClass
314-
{
315-
public $example = 0;
316-
}
317-
318-
class ChildClass extends ParentClass
319-
{
320-
public $example = 1; // overrides parent property of same name
321-
}

0 commit comments

Comments
 (0)
0