Skip to content
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

[DoctrineBridge] do not process private properties from parent class #31836

Merged
merged 1 commit into from Jun 4, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -21,7 +21,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class DoctrineLoaderEntity
class DoctrineLoaderEntity extends DoctrineLoaderParentEntity
{
/**
* @ORM\Id
@@ -0,0 +1,40 @@
<?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\Bridge\Doctrine\Tests\Fixtures;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\MappedSuperclass
*/
class DoctrineLoaderParentEntity
{
/**
* @ORM\Column(length=35)
*/
public $publicParentMaxLength;
/**
* @ORM\Column(length=30)
*/
private $privateParentMaxLength;
public function getPrivateParentMaxLength()
{
return $this->privateParentMaxLength;
}
public function setPrivateParentMaxLength($privateParentMaxLength): void
{
$this->privateParentMaxLength = $privateParentMaxLength;
}
}
@@ -16,6 +16,7 @@
use Symfony\Bridge\Doctrine\Tests\Fixtures\BaseUser;
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderEmbed;
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoctrineLoaderParentEntity;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Bridge\Doctrine\Validator\DoctrineLoader;
use Symfony\Component\Validator\Constraints\Length;
@@ -75,11 +76,30 @@ public function testLoadClassMetadata()
$this->assertSame(10, $alreadyMappedMaxLengthConstraints[0]->max);
$this->assertSame(1, $alreadyMappedMaxLengthConstraints[0]->min);
$publicParentMaxLengthMetadata = $classMetadata->getPropertyMetadata('publicParentMaxLength');
$this->assertCount(1, $publicParentMaxLengthMetadata);
$publicParentMaxLengthConstraints = $publicParentMaxLengthMetadata[0]->getConstraints();
$this->assertCount(1, $publicParentMaxLengthConstraints);
$this->assertInstanceOf(Length::class, $publicParentMaxLengthConstraints[0]);
$this->assertSame(35, $publicParentMaxLengthConstraints[0]->max);
$embeddedMetadata = $classMetadata->getPropertyMetadata('embedded');
$this->assertCount(1, $embeddedMetadata);
$this->assertSame(CascadingStrategy::CASCADE, $embeddedMetadata[0]->getCascadingStrategy());
$this->assertSame(TraversalStrategy::IMPLICIT, $embeddedMetadata[0]->getTraversalStrategy());
$parentClassMetadata = $validator->getMetadataFor(new DoctrineLoaderParentEntity());
$publicParentMaxLengthMetadata = $parentClassMetadata->getPropertyMetadata('publicParentMaxLength');
$this->assertCount(0, $publicParentMaxLengthMetadata);
$privateParentMaxLengthMetadata = $parentClassMetadata->getPropertyMetadata('privateParentMaxLength');
$this->assertCount(1, $privateParentMaxLengthMetadata);
$privateParentMaxLengthConstraints = $privateParentMaxLengthMetadata[0]->getConstraints();
$this->assertCount(1, $privateParentMaxLengthConstraints);
$this->assertInstanceOf(Length::class, $privateParentMaxLengthConstraints[0]);
$this->assertSame(30, $privateParentMaxLengthConstraints[0]->max);
$embeddedClassMetadata = $validator->getMetadataFor(new DoctrineLoaderEmbed());
$embeddedMaxLengthMetadata = $embeddedClassMetadata->getPropertyMetadata('embeddedMaxLength');
@@ -81,7 +81,7 @@ public function loadClassMetadata(ClassMetadata $metadata): bool
if (null === $constraint) {
if (isset($mapping['originalClass'])) {
$metadata->addPropertyConstraint($mapping['declaredField'], new Valid());
} else {
} elseif (property_exists($className, $mapping['fieldName'])) {
$metadata->addPropertyConstraint($mapping['fieldName'], new Length(['max' => $mapping['length']]));
}
} elseif (null === $constraint->max) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.