8000 [Validator] Fix use of GroupSequenceProvider in child classes by linniksa · Pull Request #23925 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Fix use of GroupSequenceProvider in child classes #23925

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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