diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php index ffba37a568818..81cc89536d781 100644 --- a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php @@ -371,6 +371,10 @@ public function hasMemberMetadatas($property) */ public function getMemberMetadatas($property) { + if (!isset($this->members[$property])) { + return array(); + } + return $this->members[$property]; } @@ -387,6 +391,10 @@ public function hasPropertyMetadata($property) */ public function getPropertyMetadata($property) { + if (!isset($this->members[$property])) { + return array(); + } + return $this->members[$property]; } diff --git a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php index 9579b36b5b560..b9f6faee5abe9 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php @@ -220,4 +220,20 @@ public function testGroupSequenceProvider() $metadata->setGroupSequenceProvider(true); $this->assertTrue($metadata->isGroupSequenceProvider()); } + + /** + * https://github.com/symfony/symfony/issues/11604 + */ + public function testGetMemberMetadatasReturnsEmptyArrayWithoutConfiguredMetadata() + { + $this->assertCount(0, $this->metadata->getMemberMetadatas('foo'), '->getMemberMetadatas() returns an empty collection if no metadata is configured for the given property'); + } + + /** + * https://github.com/symfony/symfony/issues/11604 + */ + public function testGetPropertyMetadataReturnsEmptyArrayWithoutConfiguredMetadata() + { + $this->assertCount(0, $this->metadata->getPropertyMetadata('foo'), '->getPropertyMetadata() returns an empty collection if no metadata is configured for the given property'); + } } diff --git a/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php b/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php index 952f5111a7491..2236d6cb02cd3 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/AbstractValidatorTest.php @@ -851,6 +851,17 @@ public function testValidatePropertyFailsIfPropertiesNotSupported() $this->validateProperty('VALUE', 'someProperty'); } + /** + * https://github.com/symfony/symfony/issues/11604 + */ + public function testValidatePropertyWithoutConstraints() + { + $entity = new Entity(); + $violations = $this->validateProperty($entity, 'lastName'); + + $this->assertCount(0, $violations, '->validateProperty() returns no violations if no constraints have been configured for the property being validated'); + } + public function testValidatePropertyValue() { $test = $this; @@ -970,6 +981,17 @@ public function testValidatePropertyValueFailsIfPropertiesNotSupported() $this->validatePropertyValue('VALUE', 'someProperty', 'someValue'); } + /** + * https://github.com/symfony/symfony/issues/11604 + */ + public function testValidatePropertyValueWithoutConstraints() + { + $entity = new Entity(); + $violations = $this->validatePropertyValue($entity, 'lastName', 'foo'); + + $this->assertCount(0, $violations, '->validatePropertyValue() returns no violations if no constraints have been configured for the property being validated'); + } + public function testValidateObjectOnlyOncePerGroup() { $entity = new Entity();