From bc6efad0747fad7ddf313c60349861531993db49 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 4 Jan 2015 15:37:21 +0100 Subject: [PATCH] [2.5] cleanup deprecated uses --- Constraints/GroupSequence.php | 2 ++ .../AbstractConstraintValidatorTest.php | 4 ++++ ...est.php => LegacyExecutionContextTest.php} | 4 +++- ...pcCacheTest.php => LegacyApcCacheTest.php} | 4 +++- .../BlackHoleMetadataFactoryTest.php} | 10 ++++----- .../LazyLoadingMetadataFactoryTest.php} | 14 ++++++------- ...Test.php => LegacyElementMetadataTest.php} | 4 +++- Tests/Validator/Abstract2Dot5ApiTest.php | 4 +++- Tests/Validator/AbstractLegacyApiTest.php | 2 ++ Tests/Validator/AbstractValidatorTest.php | 8 +++++-- Tests/ValidatorBuilderTest.php | 12 ++++++++--- ValidatorBuilder.php | 21 ++++++++++++------- 12 files changed, 60 insertions(+), 29 deletions(-) rename Tests/{ExecutionContextTest.php => LegacyExecutionContextTest.php} (98%) rename Tests/Mapping/Cache/{ApcCacheTest.php => LegacyApcCacheTest.php} (94%) rename Tests/Mapping/{BlackholeMetadataFactoryTest.php => Factory/BlackHoleMetadataFactoryTest.php} (64%) rename Tests/Mapping/{ClassMetadataFactoryTest.php => Factory/LazyLoadingMetadataFactoryTest.php} (87%) rename Tests/Mapping/{ElementMetadataTest.php => LegacyElementMetadataTest.php} (94%) diff --git a/Constraints/GroupSequence.php b/Constraints/GroupSequence.php index de5210285..72bfb16d2 100644 --- a/Constraints/GroupSequence.php +++ b/Constraints/GroupSequence.php @@ -55,6 +55,8 @@ * @author Bernhard Schussek * * @api + * + * Implementing \ArrayAccess, \IteratorAggregate and \Countable is @deprecated since 2.5 and will be removed in 3.0. */ class GroupSequence implements \ArrayAccess, \IteratorAggregate, \Countable { diff --git a/Tests/Constraints/AbstractConstraintValidatorTest.php b/Tests/Constraints/AbstractConstraintValidatorTest.php index 8cc834a90..de274124f 100644 --- a/Tests/Constraints/AbstractConstraintValidatorTest.php +++ b/Tests/Constraints/AbstractConstraintValidatorTest.php @@ -53,6 +53,10 @@ abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCa protected function setUp() { + if (Validation::API_VERSION_2_5 !== $this->getApiVersion()) { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + } + $this->group = 'MyGroup'; $this->metadata = null; $this->object = null; diff --git a/Tests/ExecutionContextTest.php b/Tests/LegacyExecutionContextTest.php similarity index 98% rename from Tests/ExecutionContextTest.php rename to Tests/LegacyExecutionContextTest.php index 3b54a9e47..88549d581 100644 --- a/Tests/ExecutionContextTest.php +++ b/Tests/LegacyExecutionContextTest.php @@ -20,7 +20,7 @@ use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; use Symfony\Component\Validator\ValidationVisitor; -class ExecutionContextTest extends \PHPUnit_Framework_TestCase +class LegacyExecutionContextTest extends \PHPUnit_Framework_TestCase { const TRANS_DOMAIN = 'trans_domain'; @@ -38,6 +38,8 @@ class ExecutionContextTest extends \PHPUnit_Framework_TestCase protected function setUp() { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + $this->visitor = $this->getMockBuilder('Symfony\Component\Validator\ValidationVisitor') ->disableOriginalConstructor() ->getMock(); diff --git a/Tests/Mapping/Cache/ApcCacheTest.php b/Tests/Mapping/Cache/LegacyApcCacheTest.php similarity index 94% rename from Tests/Mapping/Cache/ApcCacheTest.php rename to Tests/Mapping/Cache/LegacyApcCacheTest.php index 4c7fe790f..a80e2cb59 100644 --- a/Tests/Mapping/Cache/ApcCacheTest.php +++ b/Tests/Mapping/Cache/LegacyApcCacheTest.php @@ -13,10 +13,12 @@ use Symfony\Component\Validator\Mapping\Cache\ApcCache; -class ApcCacheTest extends \PHPUnit_Framework_TestCase +class LegacyApcCacheTest extends \PHPUnit_Framework_TestCase { protected function setUp() { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + if (!extension_loaded('apc') || !ini_get('apc.enable_cli')) { $this->markTestSkipped('APC is not loaded.'); } diff --git a/Tests/Mapping/BlackholeMetadataFactoryTest.php b/Tests/Mapping/Factory/BlackHoleMetadataFactoryTest.php similarity index 64% rename from Tests/Mapping/BlackholeMetadataFactoryTest.php rename to Tests/Mapping/Factory/BlackHoleMetadataFactoryTest.php index 74bcc69d7..641bf919d 100644 --- a/Tests/Mapping/BlackholeMetadataFactoryTest.php +++ b/Tests/Mapping/Factory/BlackHoleMetadataFactoryTest.php @@ -9,24 +9,24 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Validator\Tests\Mapping; +namespace Symfony\Component\Validator\Tests\Mapping\Factory; -use Symfony\Component\Validator\Mapping\BlackholeMetadataFactory; +use Symfony\Component\Validator\Mapping\Factory\BlackHoleMetadataFactory; -class BlackholeMetadataFactoryTest extends \PHPUnit_Framework_TestCase +class BlackHoleMetadataFactoryTest extends \PHPUnit_Framework_TestCase { /** * @expectedException \LogicException */ public function testGetMetadataForThrowsALogicException() { - $metadataFactory = new BlackholeMetadataFactory(); + $metadataFactory = new BlackHoleMetadataFactory(); $metadataFactory->getMetadataFor('foo'); } public function testHasMetadataForReturnsFalse() { - $metadataFactory = new BlackholeMetadataFactory(); + $metadataFactory = new BlackHoleMetadataFactory(); $this->assertFalse($metadataFactory->hasMetadataFor('foo')); } diff --git a/Tests/Mapping/ClassMetadataFactoryTest.php b/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php similarity index 87% rename from Tests/Mapping/ClassMetadataFactoryTest.php rename to Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php index b55985292..74ee912cb 100644 --- a/Tests/Mapping/ClassMetadataFactoryTest.php +++ b/Tests/Mapping/Factory/LazyLoadingMetadataFactoryTest.php @@ -9,21 +9,21 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Validator\Tests\Mapping; +namespace Symfony\Component\Validator\Tests\Mapping\Factory; use Symfony\Component\Validator\Mapping\ClassMetadata; -use Symfony\Component\Validator\Mapping\ClassMetadataFactory; +use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; use Symfony\Component\Validator\Mapping\Loader\LoaderInterface; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; -class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase +class LazyLoadingMetadataFactoryTest extends \PHPUnit_Framework_TestCase { const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity'; const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent'; public function testLoadClassMetadata() { - $factory = new ClassMetadataFactory(new TestLoader()); + $factory = new LazyLoadingMetadataFactory(new TestLoader()); $metadata = $factory->getMetadataFor(self::PARENTCLASS); $constraints = array( @@ -35,7 +35,7 @@ public function testLoadClassMetadata() public function testMergeParentConstraints() { - $factory = new ClassMetadataFactory(new TestLoader()); + $factory = new LazyLoadingMetadataFactory(new TestLoader()); $metadata = $factory->getMetadataFor(self::CLASSNAME); $constraints = array( @@ -61,7 +61,7 @@ public function testMergeParentConstraints() public function testWriteMetadataToCache() { $cache = $this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface'); - $factory = new ClassMetadataFactory(new TestLoader(), $cache); + $factory = new LazyLoadingMetadataFactory(new TestLoader(), $cache); $tester = $this; $constraints = array( @@ -90,7 +90,7 @@ public function testReadMetadataFromCache() { $loader = $this->getMock('Symfony\Component\Validator\Mapping\Loader\LoaderInterface'); $cache = $this->getMock('Symfony\Component\Validator\Mapping\Cache\CacheInterface'); - $factory = new ClassMetadataFactory($loader, $cache); + $factory = new LazyLoadingMetadataFactory($loader, $cache); $tester = $this; $metadata = new ClassMetadata(self::PARENTCLASS); diff --git a/Tests/Mapping/ElementMetadataTest.php b/Tests/Mapping/LegacyElementMetadataTest.php similarity index 94% rename from Tests/Mapping/ElementMetadataTest.php rename to Tests/Mapping/LegacyElementMetadataTest.php index c2eb4cee7..473eea617 100644 --- a/Tests/Mapping/ElementMetadataTest.php +++ b/Tests/Mapping/LegacyElementMetadataTest.php @@ -15,12 +15,14 @@ use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; use Symfony\Component\Validator\Tests\Fixtures\ConstraintB; -class ElementMetadataTest extends \PHPUnit_Framework_TestCase +class LegacyElementMetadataTest extends \PHPUnit_Framework_TestCase { protected $metadata; protected function setUp() { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + $this->metadata = new TestElementMetadata(); } diff --git a/Tests/Validator/Abstract2Dot5ApiTest.php b/Tests/Validator/Abstract2Dot5ApiTest.php index 62fa87ccf..fbc045d26 100644 --- a/Tests/Validator/Abstract2Dot5ApiTest.php +++ b/Tests/Validator/Abstract2Dot5ApiTest.php @@ -633,8 +633,10 @@ public function testReferenceMetadataMustImplementClassMetadataInterface() /** * @expectedException \Symfony\Component\Validator\Exception\UnsupportedMetadataException */ - public function testPropertyMetadataMustImplementPropertyMetadataInterface() + public function testLegacyPropertyMetadataMustImplementPropertyMetadataInterface() { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + $entity = new Entity(); // Legacy interface diff --git a/Tests/Validator/AbstractLegacyApiTest.php b/Tests/Validator/AbstractLegacyApiTest.php index 748e106d4..bef0b9817 100644 --- a/Tests/Validator/AbstractLegacyApiTest.php +++ b/Tests/Validator/AbstractLegacyApiTest.php @@ -42,6 +42,8 @@ abstract protected function createValidator(MetadataFactoryInterface $metadataFa protected function setUp() { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + parent::setUp(); $this->validator = $this->createValidator($this->metadataFactory); diff --git a/Tests/Validator/AbstractValidatorTest.php b/Tests/Validator/AbstractValidatorTest.php index 2236d6cb0..26085901f 100644 --- a/Tests/Validator/AbstractValidatorTest.php +++ b/Tests/Validator/AbstractValidatorTest.php @@ -841,8 +841,10 @@ public function testValidateProperty() * * @expectedException \Symfony\Component\Validator\Exception\ValidatorException */ - public function testValidatePropertyFailsIfPropertiesNotSupported() + public function testLegacyValidatePropertyFailsIfPropertiesNotSupported() { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + // $metadata does not implement PropertyMetadataContainerInterface $metadata = $this->getMock('Symfony\Component\Validator\MetadataInterface'); @@ -971,8 +973,10 @@ public function testValidatePropertyValueWithClassName() * * @expectedException \Symfony\Component\Validator\Exception\ValidatorException */ - public function testValidatePropertyValueFailsIfPropertiesNotSupported() + public function testLegacyValidatePropertyValueFailsIfPropertiesNotSupported() { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + // $metadata does not implement PropertyMetadataContainerInterface $metadata = $this->getMock('Symfony\Component\Validator\MetadataInterface'); diff --git a/Tests/ValidatorBuilderTest.php b/Tests/ValidatorBuilderTest.php index ba184f7c7..4de62efe9 100644 --- a/Tests/ValidatorBuilderTest.php +++ b/Tests/ValidatorBuilderTest.php @@ -110,8 +110,10 @@ public function testSetTranslationDomain() $this->assertSame($this->builder, $this->builder->setTranslationDomain('TRANS_DOMAIN')); } - public function testDefaultApiVersion() + public function testLegacyDefaultApiVersion() { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + if (PHP_VERSION_ID < 50309) { // Old implementation on PHP < 5.3.9 $this->assertInstanceOf('Symfony\Component\Validator\Validator', $this->builder->getValidator()); @@ -121,8 +123,10 @@ public function testDefaultApiVersion() } } - public function testSetApiVersion24() + public function testLegacySetApiVersion24() { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + $this->assertSame($this->builder, $this->builder->setApiVersion(Validation::API_VERSION_2_4)); $this->assertInstanceOf('Symfony\Component\Validator\Validator', $this->builder->getValidator()); } @@ -133,8 +137,10 @@ public function testSetApiVersion25() $this->assertInstanceOf('Symfony\Component\Validator\Validator\RecursiveValidator', $this->builder->getValidator()); } - public function testSetApiVersion24And25() + public function testLegacySetApiVersion24And25() { + $this->iniSet('error_reporting', -1 & E_USER_DEPRECATED); + if (PHP_VERSION_ID < 50309) { $this->markTestSkipped('Not supported prior to PHP 5.3.9'); } diff --git a/ValidatorBuilder.php b/ValidatorBuilder.php index b4489f4c2..f0c7e3c7e 100644 --- a/ValidatorBuilder.php +++ b/ValidatorBuilder.php @@ -23,6 +23,7 @@ use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Mapping\Cache\CacheInterface; use Symfony\Component\Validator\Mapping\ClassMetadataFactory; +use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory; use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader; use Symfony\Component\Validator\Mapping\Loader\LoaderChain; use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader; @@ -345,6 +346,13 @@ public function setApiVersion($apiVersion) public function getValidator() { $metadataFactory = $this->metadataFactory; + $apiVersion = $this->apiVersion; + + if (null === $apiVersion) { + $apiVersion = PHP_VERSION_ID < 50309 + ? Validation::API_VERSION_2_4 + : Validation::API_VERSION_2_5_BC; + } if (!$metadataFactory) { $loaders = array(); @@ -377,18 +385,15 @@ public function getValidator() $loader = $loaders[0]; } - $metadataFactory = new ClassMetadataFactory($loader, $this->metadataCache); + if (Validation::API_VERSION_2_5 === $apiVersion) { + $metadataFactory = new LazyLoadingMetadataFactory($loader, $this->metadataCache); + } else { + $metadataFactory = new ClassMetadataFactory($loader, $this->metadataCache); + } } $validatorFactory = $this->validatorFactory ?: new ConstraintValidatorFactory($this->propertyAccessor); $translator = $this->translator ?: new DefaultTranslator(); - $apiVersion = $this->apiVersion; - - if (null === $apiVersion) { - $apiVersion = PHP_VERSION_ID < 50309 - ? Validation::API_VERSION_2_4 - : Validation::API_VERSION_2_5_BC; - } if (Validation::API_VERSION_2_4 === $apiVersion) { return new ValidatorV24($metadataFactory, $validatorFactory, $translator, $this->translationDomain, $this->initializers);