Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f825f5d

Browse files
committed
minor #11615 [Validator] return empty metadata collection if none do exist (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Validator] return empty metadata collection if none do exist | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | [The reference to the documentation PR if any] Backport of #11614 for Symfony 2.3 and 2.4. Commits ------- f5bc18d return empty metadata collection if none do exist
2 parents b674e67 + f5bc18d commit f825f5d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Symfony/Component/Validator/Mapping/ClassMetadata.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ public function hasMemberMetadatas($property)
298298
*/
299299
public function getMemberMetadatas($property)
300300
{
301+
if (!isset($this->members[$property])) {
302+
return array();
303+
}
304+
301305
return $this->members[$property];
302306
}
303307

@@ -314,6 +318,10 @@ public function hasPropertyMetadata($property)
314318
*/
315319
public function getPropertyMetadata($property)
316320
{
321+
if (!isset($this->members[$property])) {
322+
return array();
323+
}
324+
317325
return $this->members[$property];
318326
}
319327

src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,20 @@ public function testGroupSequenceProvider()
222222
$metadata->setGroupSequenceProvider(true);
223223
$this->assertTrue($metadata->isGroupSequenceProvider());
224224
}
225+
226+
/**
227+
* https://github.com/symfony/symfony/issues/11604
228+
*/
229+
public function testGetMemberMetadatasReturnsEmptyArrayWithoutConfiguredMetadata()
230+
{
231+
$this->assertCount(0, $this->metadata->getMemberMetadatas('foo'), '->getMemberMetadatas() returns an empty collection if no metadata is configured for the given property');
232+
}
233+
234+
/**
235+
* https://github.com/symfony/symfony/issues/11604
236+
*/
237+
public function testGetPropertyMetadataReturnsEmptyArrayWithoutConfiguredMetadata()
238+
{
239+
$this->assertCount(0, $this->metadata->getPropertyMetadata('foo'), '->getPropertyMetadata() returns an empty collection if no metadata is configured for the given property');
240+
}
225241
}

0 commit comments

Comments
 (0)