Skip to content

Commit

Permalink
[2.5] cleanup deprecated uses
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jan 5, 2015
1 parent 91f9a27 commit bc6efad
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 29 deletions.
2 changes: 2 additions & 0 deletions Constraints/GroupSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
* @author Bernhard Schussek <[email protected]>
*
* @api
*
* Implementing \ArrayAccess, \IteratorAggregate and \Countable is @deprecated since 2.5 and will be removed in 3.0.
*/
class GroupSequence implements \ArrayAccess, \IteratorAggregate, \Countable
{
Expand Down
4 changes: 4 additions & 0 deletions Tests/Constraints/AbstractConstraintValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion Tests/Validator/Abstract2Dot5ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Tests/Validator/AbstractLegacyApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions Tests/Validator/AbstractValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');

Expand Down
12 changes: 9 additions & 3 deletions Tests/ValidatorBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
}
Expand All @@ -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');
}
Expand Down
21 changes: 13 additions & 8 deletions ValidatorBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bc6efad

Please sign in to comment.