Skip to content

LazyLoadingMetadataFactory looks broken #21538

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 4 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
24 changes: 24 additions & 0 deletions src/Symfony/Component/Validator/Tests/Fixtures/EntityStaticCar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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;

use Symfony\Component\Validator\Mapping\ClassMetadata;

use Symfony\Component\Validator\Constraints\Length;

class EntityStaticCar extends EntityStaticVehicle
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('wheels', new Length(array ('max' => 99,)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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;

use Symfony\Component\Validator\Mapping\ClassMetadata;

use Symfony\Component\Validator\Constraints\Length;

class EntityStaticCarTurbo extends EntityStaticCar
{
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('wheels', new Length(array ('max' => 99,)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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;

use Symfony\Component\Validator\Mapping\ClassMetadata;

use Symfony\Component\Validator\Constraints\Length;

class EntityStaticVehicle
{
public $wheels;

public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('wheels', new Length(array ('max' => 99,)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,43 @@ public function testMetadataCacheWithRuntimeConstraint()

$metadata = $factory->getMetadataFor(self::CLASS_NAME);
}

public function testGroupsFromParent()
{
$reader = new \Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader();
$factory = new LazyLoadingMetadataFactory($reader);
$metadata = $factory->getMetadataFor('Symfony\Component\Validator\Tests\Fixtures\EntityStaticCarTurbo');
$classMetaDataCollection = $metadata->getPropertyMetadata('wheels');

/*
* Array element will be removed if it exists
* in any constraint group
*/
$expectedConstraints = [
'Default' => 'Default',
'EntityStaticCarTurbo' => 'EntityStaticCarTurbo',
'EntityStaticCar' => 'EntityStaticCar',
'EntityStaticVehicle' => 'EntityStaticVehicle',
];

foreach ($classMetaDataCollection as $classMetaData) {
$constraints = $classMetaData->getConstraints();
foreach ($constraints as $constraint) {
$groups = $constraint->groups;
foreach ($groups as $group) {
if (array_key_exists($group, $expectedConstraints)) {
unset($expectedConstraints[$group]);
}
}
}
}

$this->assertEmpty(
$expectedConstraints,
"Following groups were not found " . implode(',', $expectedConstraints)
);
}

}

class TestLoader implements LoaderInterface
Expand Down