From f5bc18d6483202f2405787db997e1a494c427220 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 8 Aug 2014 10:52:31 +0200 Subject: [PATCH 1/2] 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. --- .../Validator/Mapping/ClassMetadata.php | 8 ++++++++ .../Tests/Mapping/ClassMetadataTest.php | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php index 553d7806ad..792d8e5140 100644 --- a/src/Symfony/Component/Validator/Mapping/ClassMetadata.php +++ b/src/Symfony/Component/Validator/Mapping/ClassMetadata.php @@ -298,6 +298,10 @@ class ClassMetadata extends ElementMetadata implements MetadataInterface, ClassB */ public function getMemberMetadatas($property) { + if (!isset($this->members[$property])) { + return array(); + } + return $this->members[$property]; } @@ -314,6 +318,10 @@ class ClassMetadata extends ElementMetadata implements MetadataInterface, ClassB */ 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 9ead7d134e..08ae9600ce 100644 --- a/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php +++ b/src/Symfony/Component/Validator/Tests/Mapping/ClassMetadataTest.php @@ -222,4 +222,20 @@ class ClassMetadataTest extends \PHPUnit_Framework_TestCase $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'); + } } From 5440ed5c38eb82a3b38873d54b8986357157c7c4 Mon Sep 17 00:00:00 2001 From: Bernhard Schussek Date: Mon, 18 Aug 2014 18:29:10 +0200 Subject: [PATCH 2/2] [Validators] Fixed failing tests requiring ICU 52.1 which are skipped otherwise --- .../Validator/Tests/Constraints/CountryValidatorTest.php | 2 +- .../Validator/Tests/Constraints/CurrencyValidatorTest.php | 2 +- .../Validator/Tests/Constraints/LanguageValidatorTest.php | 3 +-- .../Validator/Tests/Constraints/LocaleValidatorTest.php | 3 +-- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php index a080852c2a..c6693020f8 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php @@ -82,7 +82,7 @@ class CountryValidatorTest extends AbstractConstraintValidatorTest $this->validator->validate($country, $constraint); $this->assertViolation('myMessage', array( - '{{ value }}' => $country, + '{{ value }}' => '"'.$country.'"', )); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php index 99636e6ca4..0480b60ed7 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php @@ -96,7 +96,7 @@ class CurrencyValidatorTest extends AbstractConstraintValidatorTest $this->validator->validate($currency, $constraint); $this->assertViolation('myMessage', array( - '{{ value }}' => $currency, + '{{ value }}' => '"'.$currency.'"', )); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php index 98f7533cb8..ad2b1e8971 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php @@ -14,7 +14,6 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Validator\Constraints\Language; use Symfony\Component\Validator\Constraints\LanguageValidator; -use Symfony\Component\Validator\Validation; class LanguageValidatorTest extends AbstractConstraintValidatorTest { @@ -83,7 +82,7 @@ class LanguageValidatorTest extends AbstractConstraintValidatorTest $this->validator->validate($language, $constraint); $this->assertViolation('myMessage', array( - '{{ value }}' => $language, + '{{ value }}' => '"'.$language.'"', )); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php index 5d40dd20bd..8c76485e53 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php @@ -14,7 +14,6 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\Intl\Util\IntlTestHelper; use Symfony\Component\Validator\Constraints\Locale; use Symfony\Component\Validator\Constraints\LocaleValidator; -use Symfony\Component\Validator\Validation; class LocaleValidatorTest extends AbstractConstraintValidatorTest { @@ -85,7 +84,7 @@ class LocaleValidatorTest extends AbstractConstraintValidatorTest $this->validator->validate($locale, $constraint); $this->assertViolation('myMessage', array( - '{{ value }}' => $locale, + '{{ value }}' => '"'.$locale.'"', )); }