diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/EntityStaticCar.php b/src/Symfony/Component/Validator/Tests/Fixtures/EntityStaticCar.php new file mode 100644 index 0000000000000..e8d2667199197 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Fixtures/EntityStaticCar.php @@ -0,0 +1,24 @@ + + * + * 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,))); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/EntityStaticCarTurbo.php b/src/Symfony/Component/Validator/Tests/Fixtures/EntityStaticCarTurbo.php new file mode 100644 index 0000000000000..b26522d66ba07 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Fixtures/EntityStaticCarTurbo.php @@ -0,0 +1,24 @@ + + * + * 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,))); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/EntityStaticVehicle.php b/src/Symfony/Component/Validator/Tests/Fixtures/EntityStaticVehicle.php new file mode 100644 index 0000000000000..3dc5bfd2f4d54 --- /dev/null +++ b/src/Symfony/Component/Validator/Tests/Fixtures/EntityStaticVehicle.php @@ -0,0 +1,26 @@ + + * + * 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,))); + } +} diff --git a/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php b/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php index 9696744166537..bc584f1fec360 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php @@ -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