return empty metadata collection if none do exist
The PropertyMetadataContainerInterface defines that the method getPropertyMetadata() has to return an empty collection if no metadata have been configured for the given property. Though, its implementation in the ClassMetadata class didn't check for existence of such metadata. This behavior led to unexpected PHP notices when validating a property or a property value of a property without any configured constraints (only affects the new 2.5 API). Additionally, the getMemberMetadatas() didn't check for existing array keys as well which has also been fixed.
This commit is contained in:
parent
56a75179d1
commit
f5bc18d648
@ -298,6 +298,10 @@ class ClassMetadata extends ElementMetadata implements MetadataInterface, ClassB
|
|||||||
*/
|
*/
|
||||||
public function getMemberMetadatas($property)
|
public function getMemberMetadatas($property)
|
||||||
{
|
{
|
||||||
|
if (!isset($this->members[$property])) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->members[$property];
|
return $this->members[$property];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,6 +318,10 @@ class ClassMetadata extends ElementMetadata implements MetadataInterface, ClassB
|
|||||||
*/
|
*/
|
||||||
public function getPropertyMetadata($property)
|
public function getPropertyMetadata($property)
|
||||||
{
|
{
|
||||||
|
if (!isset($this->members[$property])) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
return $this->members[$property];
|
return $this->members[$property];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,4 +222,20 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase
|
|||||||
$metadata->setGroupSequenceProvider(true);
|
$metadata->setGroupSequenceProvider(true);
|
||||||
$this->assertTrue($metadata->isGroupSequenceProvider());
|
$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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user