From e49739c469a6cd693c0732f4894d1a804c84e116 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 3 Sep 2015 14:33:45 +0200 Subject: [PATCH] [2.7] Clean deprecated interfaces --- .../ChoiceList/ORMQueryBuilderLoaderTest.php | 1 + .../Form/Type/EntityTypePerformanceTest.php | 6 ++--- .../Factory/CachingFactoryDecorator.php | 4 +-- .../Factory/DefaultChoiceListFactory.php | 6 ++++- .../Factory/PropertyAccessDecorator.php | 4 +-- .../Form/Extension/Core/Type/ChoiceType.php | 2 +- .../Factory/CachingFactoryDecoratorTest.php | 17 ++++++++++++ .../Factory/DefaultChoiceListFactoryTest.php | 27 +++++++++++++++++++ .../Factory/PropertyAccessDecoratorTest.php | 3 +++ .../LegacyChoiceListAdapterTest.php | 1 + .../Extension/Core/Type/ChoiceTypeTest.php | 1 + .../Extension/Core/Type/DateTimeTypeTest.php | 3 +++ .../Extension/Core/Type/DateTypeTest.php | 3 +++ .../Extension/Core/Type/TimeTypeTest.php | 3 +++ .../Validator/ValidatorExtensionTest.php | 4 +++ .../ConstraintViolationInterface.php | 4 +++ .../Constraints/CallbackValidator.php | 5 +++- .../Constraints/CallbackValidatorTest.php | 4 +-- .../Tests/Validator/Abstract2Dot5ApiTest.php | 2 ++ .../Tests/Validator/AbstractLegacyApiTest.php | 1 + 20 files changed, 89 insertions(+), 12 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php index 8fec7584e4..5af59445e1 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php @@ -19,6 +19,7 @@ class ORMQueryBuilderLoaderTest extends \PHPUnit_Framework_TestCase { /** * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException + * @group legacy */ public function testItOnlyWorksWithQueryBuilderOrClosure() { diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php index 1269812bbf..57df4195bc 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/Type/EntityTypePerformanceTest.php @@ -90,7 +90,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase $this->setMaxRunningTime(1); for ($i = 0; $i < 40; ++$i) { - $form = $this->factory->create('entity', null, array( + $form = $this->factory->create('Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array( 'class' => self::ENTITY_CLASS, )); @@ -108,7 +108,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase $this->setMaxRunningTime(1); for ($i = 0; $i < 40; ++$i) { - $form = $this->factory->create('entity', null, array( + $form = $this->factory->create('Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array( 'class' => self::ENTITY_CLASS, 'choices' => $choices, )); @@ -127,7 +127,7 @@ class EntityTypePerformanceTest extends FormPerformanceTestCase $this->setMaxRunningTime(1); for ($i = 0; $i < 40; ++$i) { - $form = $this->factory->create('entity', null, array( + $form = $this->factory->create('Symfony\Bridge\Doctrine\Form\Type\EntityType', null, array( 'class' => self::ENTITY_CLASS, 'preferred_choices' => $choices, )); diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php b/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php index 0692781f40..ae7f2375bb 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php @@ -141,7 +141,7 @@ class CachingFactoryDecorator implements ChoiceListFactoryInterface * @deprecated Added for backwards compatibility in Symfony 2.7, to be * removed in Symfony 3.0. */ - public function createListFromFlippedChoices($choices, $value = null) + public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true) { if ($choices instanceof \Traversable) { $choices = iterator_to_array($choices); @@ -158,7 +158,7 @@ class CachingFactoryDecorator implements ChoiceListFactoryInterface $hash = self::generateHash(array($flatChoices, $value), 'fromFlippedChoices'); if (!isset($this->lists[$hash])) { - $this->lists[$hash] = $this->decoratedFactory->createListFromFlippedChoices($choices, $value); + $this->lists[$hash] = $this->decoratedFactory->createListFromFlippedChoices($choices, $value, $triggerDeprecationNotice); } return $this->lists[$hash]; diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php index b227180100..ef93ffdd76 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -43,8 +43,12 @@ class DefaultChoiceListFactory implements ChoiceListFactoryInterface * @deprecated Added for backwards compatibility in Symfony 2.7, to be * removed in Symfony 3.0. */ - public function createListFromFlippedChoices($choices, $value = null) + public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true) { + if ($triggerDeprecationNotice) { + @trigger_error('The '.__METHOD__.' is deprecated since version 2.7 and will be removed in 3.0.', E_USER_DEPRECATED); + } + return new ArrayKeyChoiceList($choices, $value); } diff --git a/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php b/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php index 87a364a5f4..1b68fd8924 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php @@ -116,11 +116,11 @@ class PropertyAccessDecorator implements ChoiceListFactoryInterface * @deprecated Added for backwards compatibility in Symfony 2.7, to be * removed in Symfony 3.0. */ - public function createListFromFlippedChoices($choices, $value = null) + public function createListFromFlippedChoices($choices, $value = null, $triggerDeprecationNotice = true) { // Property paths are not supported here, because array keys can never // be objects - return $this->decoratedFactory->createListFromFlippedChoices($choices, $value); + return $this->decoratedFactory->createListFromFlippedChoices($choices, $value, $triggerDeprecationNotice); } /** diff --git a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php index 386f27dbc9..5102efb55c 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php @@ -280,7 +280,7 @@ class ChoiceType extends AbstractType // BC when choices are in the keys, not in the values if (!$options['choices_as_values']) { - return $choiceListFactory->createListFromFlippedChoices($choices, $options['choice_value']); + return $choiceListFactory->createListFromFlippedChoices($choices, $options['choice_value'], false); } return $choiceListFactory->createListFromChoices($choices, $options['choice_value']); diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php index 9855c4a708..d3d530afb5 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php @@ -155,6 +155,9 @@ class CachingFactoryDecoratorTest extends \PHPUnit_Framework_TestCase $this->assertSame($list2, $this->factory->createListFromChoices($choices, $closure2)); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesEmpty() { $list = new \stdClass(); @@ -168,6 +171,9 @@ class CachingFactoryDecoratorTest extends \PHPUnit_Framework_TestCase $this->assertSame($list, $this->factory->createListFromFlippedChoices(array())); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesComparesTraversableChoicesAsArray() { // The top-most traversable is converted to an array @@ -184,6 +190,9 @@ class CachingFactoryDecoratorTest extends \PHPUnit_Framework_TestCase $this->assertSame($list, $this->factory->createListFromFlippedChoices($choices2)); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesFlattensChoices() { $choices1 = array('key' => array('a' => 'A')); @@ -201,6 +210,7 @@ class CachingFactoryDecoratorTest extends \PHPUnit_Framework_TestCase /** * @dataProvider provideSameKeyChoices + * @group legacy */ public function testCreateFromFlippedChoicesSameChoices($choice1, $choice2) { @@ -219,6 +229,7 @@ class CachingFactoryDecoratorTest extends \PHPUnit_Framework_TestCase /** * @dataProvider provideDistinguishedKeyChoices + * @group legacy */ public function testCreateFromFlippedChoicesDifferentChoices($choice1, $choice2) { @@ -240,6 +251,9 @@ class CachingFactoryDecoratorTest extends \PHPUnit_Framework_TestCase $this->assertSame($list2, $this->factory->createListFromFlippedChoices($choices2)); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesSameValueClosure() { $choices = array(1); @@ -255,6 +269,9 @@ class CachingFactoryDecoratorTest extends \PHPUnit_Framework_TestCase $this->assertSame($list, $this->factory->createListFromFlippedChoices($choices, $closure)); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesDifferentValueClosure() { $choices = array(1); diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php index 9210bc3d70..741cde5b43 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php @@ -193,6 +193,9 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase $this->assertObjectListWithCustomValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesEmpty() { $list = $this->factory->createListFromFlippedChoices(array()); @@ -201,6 +204,9 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase $this->assertSame(array(), $list->getValues()); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesFlat() { $list = $this->factory->createListFromFlippedChoices( @@ -210,6 +216,9 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase $this->assertScalarListWithChoiceValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesFlatTraversable() { $list = $this->factory->createListFromFlippedChoices( @@ -219,6 +228,9 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase $this->assertScalarListWithChoiceValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesFlatValuesAsCallable() { $list = $this->factory->createListFromFlippedChoices( @@ -229,6 +241,9 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase $this->assertScalarListWithCustomValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesFlatValuesAsClosure() { $list = $this->factory->createListFromFlippedChoices( @@ -246,6 +261,9 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase $this->assertScalarListWithCustomValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesGrouped() { $list = $this->factory->createListFromFlippedChoices( @@ -258,6 +276,9 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase $this->assertScalarListWithChoiceValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesGroupedTraversable() { $list = $this->factory->createListFromFlippedChoices( @@ -270,6 +291,9 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase $this->assertScalarListWithChoiceValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesGroupedValuesAsCallable() { $list = $this->factory->createListFromFlippedChoices( @@ -283,6 +307,9 @@ class DefaultChoiceListFactoryTest extends \PHPUnit_Framework_TestCase $this->assertScalarListWithCustomValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesGroupedValuesAsClosure() { $list = $this->factory->createListFromFlippedChoices( diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/PropertyAccessDecoratorTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/PropertyAccessDecoratorTest.php index 311db477b1..44490a686a 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/PropertyAccessDecoratorTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/PropertyAccessDecoratorTest.php @@ -63,6 +63,9 @@ class PropertyAccessDecoratorTest extends \PHPUnit_Framework_TestCase $this->assertSame(array('value'), $this->factory->createListFromChoices($choices, new PropertyPath('property'))); } + /** + * @group legacy + */ public function testCreateFromFlippedChoices() { // Property paths are not supported here, because array keys can never diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/LegacyChoiceListAdapterTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/LegacyChoiceListAdapterTest.php index 521c950331..911d8c001e 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/LegacyChoiceListAdapterTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/LegacyChoiceListAdapterTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface; /** * @author Bernhard Schussek + * @group legacy */ class LegacyChoiceListAdapterTest extends \PHPUnit_Framework_TestCase { diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php index 61c20c2f67..215ddac936 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/ChoiceTypeTest.php @@ -1529,6 +1529,7 @@ class ChoiceTypeTest extends \Symfony\Component\Form\Test\TypeTestCase /** * @dataProvider getOptionsWithPlaceholder + * @group legacy */ public function testPassEmptyValueBC($multiple, $expanded, $required, $placeholder, $viewValue) { diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php index 34889ed321..de12bb1e44 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php @@ -328,6 +328,9 @@ class DateTimeTypeTest extends TestCase $this->assertSame('Empty', $view['time']['second']->vars['placeholder']); } + /** + * @group legacy + */ public function testPassEmptyValueBC() { $form = $this->factory->create('datetime', null, array( diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php index f690917cd7..5cb5429939 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php @@ -759,6 +759,9 @@ class DateTypeTest extends TestCase $this->assertSame('Empty', $view['day']->vars['placeholder']); } + /** + * @group legacy + */ public function testPassEmptyValueBC() { $form = $this->factory->create('date', null, array( diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php index e0faf4c179..520f9f22ef 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php @@ -562,6 +562,9 @@ class TimeTypeTest extends TestCase $this->assertSame('Empty', $view['second']->vars['placeholder']); } + /** + * @group legacy + */ public function testPassEmptyValueBC() { $form = $this->factory->create('time', null, array( diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php index ee822316ad..a4dcc1532a 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ValidatorExtensionTest.php @@ -48,6 +48,9 @@ class ValidatorExtensionTest extends \PHPUnit_Framework_TestCase $this->assertInstanceOf('Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser', $guesser); } + /** + * @group legacy + */ public function test2Dot4ValidationApi() { $factory = $this->getMock('Symfony\Component\Validator\MetadataFactoryInterface'); @@ -82,6 +85,7 @@ class ValidatorExtensionTest extends \PHPUnit_Framework_TestCase /** * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException + * @group legacy */ public function testInvalidValidatorInterface() { diff --git a/src/Symfony/Component/Validator/ConstraintViolationInterface.php b/src/Symfony/Component/Validator/ConstraintViolationInterface.php index 232fb5513f..9baee2f37c 100644 --- a/src/Symfony/Component/Validator/ConstraintViolationInterface.php +++ b/src/Symfony/Component/Validator/ConstraintViolationInterface.php @@ -68,6 +68,8 @@ interface ConstraintViolationInterface * @see getMessageTemplate() * * @api + * + * @deprecated since version 2.7, to be replaced by getParameters() in 3.0. */ public function getMessageParameters(); @@ -86,6 +88,8 @@ interface ConstraintViolationInterface * pluralization form (in this case "choices"). * * @return int|null The number to use to pluralize of the message. + * + * @deprecated since version 2.7, to be replaced by getPlural() in 3.0. */ public function getMessagePluralization(); diff --git a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php index eaf2f3c011..a75e6d2f66 100644 --- a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php @@ -54,7 +54,10 @@ class CallbackValidator extends ConstraintValidator $method($object, $this->context); } elseif (is_array($method)) { if (!is_callable($method)) { - throw new ConstraintDefinitionException(sprintf('"%s::%s" targeted by Callback constraint is not a valid callable', $method[0], $method[1])); + if (isset($method[0]) && is_object($method[0])) { + $method[0] = get_class($method[0]); + } + throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable', json_encode($method))); } call_user_func($method, $object, $this->context); diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php index b619291665..5ad8276563 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php @@ -298,7 +298,7 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest { $object = new CallbackValidatorTest_Object(); - $this->validator->validate($object, new Callback(array('foobar'))); + $this->validator->validate($object, new Callback(array('callback' => array('foobar')))); } /** @@ -308,7 +308,7 @@ class CallbackValidatorTest extends AbstractConstraintValidatorTest { $object = new CallbackValidatorTest_Object(); - $this->validator->validate($object, new Callback(array(array('foo', 'bar')))); + $this->validator->validate($object, new Callback(array('callback' => array('foo', 'bar')))); } /** diff --git a/src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php b/src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php index a2da68f9f1..6995d25817 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php @@ -544,6 +544,7 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest /** * @expectedException \Symfony\Component\Validator\Exception\UnsupportedMetadataException + * @group legacy */ public function testMetadataMustImplementClassMetadataInterface() { @@ -561,6 +562,7 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest /** * @expectedException \Symfony\Component\Validator\Exception\UnsupportedMetadataException + * @group legacy */ public function testReferenceMetadataMustImplementClassMetadataInterface() { diff --git a/src/Symfony/Component/Validator/Tests/Validator/AbstractLegacyApiTest.php b/src/Symfony/Component/Validator/Tests/Validator/AbstractLegacyApiTest.php index 22af86e3de..d78b67bee7 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/AbstractLegacyApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/AbstractLegacyApiTest.php @@ -26,6 +26,7 @@ use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface; * @since 2.5 * * @author Bernhard Schussek + * @group legacy */ abstract class AbstractLegacyApiTest extends AbstractValidatorTest {