8000 LazyLoadingMetadataFactory looks broken by angelk · Pull Request #21538 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show 8000 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,)));
}
}
8000
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
0