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 8fec7584e41c3..5af59445e1825 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 1269812bbf151..57df4195bcec4 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 @@ public function testCollapsedEntityField() $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 @@ public function testCollapsedEntityFieldWithChoices() $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 @@ public function testCollapsedEntityFieldWithPreferredChoices() $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 0692781f40ee4..ae7f2375bb896 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/CachingFactoryDecorator.php @@ -141,7 +141,7 @@ public function createListFromChoices($choices, $value = null) * @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 @@ public function createListFromFlippedChoices($choices, $value = null) $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 b227180100d7b..ef93ffdd76336 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/DefaultChoiceListFactory.php @@ -43,8 +43,12 @@ public function createListFromChoices($choices, $value = null) * @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 87a364a5f4d55..1b68fd8924284 100644 --- a/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php +++ b/src/Symfony/Component/Form/ChoiceList/Factory/PropertyAccessDecorator.php @@ -116,11 +116,11 @@ public function createListFromChoices($choices, $value = null) * @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 386f27dbc91a0..5102efb55c9ed 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 @@ public function configureOptions(OptionsResolver $resolver) // 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 9855c4a708d67..d3d530afb58f8 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 @@ public function testCreateFromChoicesDifferentValueClosure() $this->assertSame($list2, $this->factory->createListFromChoices($choices, $closure2)); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesEmpty() { $list = new \stdClass(); @@ -168,6 +171,9 @@ public function testCreateFromFlippedChoicesEmpty() $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 @@ public function testCreateFromFlippedChoicesComparesTraversableChoicesAsArray() $this->assertSame($list, $this->factory->createListFromFlippedChoices($choices2)); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesFlattensChoices() { $choices1 = array('key' => array('a' => 'A')); @@ -201,6 +210,7 @@ public function testCreateFromFlippedChoicesFlattensChoices() /** * @dataProvider provideSameKeyChoices + * @group legacy */ public function testCreateFromFlippedChoicesSameChoices($choice1, $choice2) { @@ -219,6 +229,7 @@ public function testCreateFromFlippedChoicesSameChoices($choice1, $choice2) /** * @dataProvider provideDistinguishedKeyChoices + * @group legacy */ public function testCreateFromFlippedChoicesDifferentChoices($choice1, $choice2) { @@ -240,6 +251,9 @@ public function testCreateFromFlippedChoicesDifferentChoices($choice1, $choice2) $this->assertSame($list2, $this->factory->createListFromFlippedChoices($choices2)); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesSameValueClosure() { $choices = array(1); @@ -255,6 +269,9 @@ public function testCreateFromFlippedChoicesSameValueClosure() $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 9210bc3d70ede..741cde5b43921 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 @@ function ($object) { return $object->value; } $this->assertObjectListWithCustomValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesEmpty() { $list = $this->factory->createListFromFlippedChoices(array()); @@ -201,6 +204,9 @@ public function testCreateFromFlippedChoicesEmpty() $this->assertSame(array(), $list->getValues()); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesFlat() { $list = $this->factory->createListFromFlippedChoices( @@ -210,6 +216,9 @@ public function testCreateFromFlippedChoicesFlat() $this->assertScalarListWithChoiceValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesFlatTraversable() { $list = $this->factory->createListFromFlippedChoices( @@ -219,6 +228,9 @@ public function testCreateFromFlippedChoicesFlatTraversable() $this->assertScalarListWithChoiceValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesFlatValuesAsCallable() { $list = $this->factory->createListFromFlippedChoices( @@ -229,6 +241,9 @@ public function testCreateFromFlippedChoicesFlatValuesAsCallable() $this->assertScalarListWithCustomValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesFlatValuesAsClosure() { $list = $this->factory->createListFromFlippedChoices( @@ -246,6 +261,9 @@ function ($choice) { $this->assertScalarListWithCustomValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesGrouped() { $list = $this->factory->createListFromFlippedChoices( @@ -258,6 +276,9 @@ public function testCreateFromFlippedChoicesGrouped() $this->assertScalarListWithChoiceValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesGroupedTraversable() { $list = $this->factory->createListFromFlippedChoices( @@ -270,6 +291,9 @@ public function testCreateFromFlippedChoicesGroupedTraversable() $this->assertScalarListWithChoiceValues($list); } + /** + * @group legacy + */ public function testCreateFromFlippedChoicesGroupedValuesAsCallable() { $list = $this->factory->createListFromFlippedChoices( @@ -283,6 +307,9 @@ public function testCreateFromFlippedChoicesGroupedValuesAsCallable() $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 311db477b1993..44490a686a83d 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 @@ public function testCreateFromChoicesPropertyPathInstance() $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 521c950331054..911d8c001e054 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/LegacyChoiceListAdapterTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/LegacyChoiceListAdapterTest.php @@ -16,6 +16,7 @@ /** * @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 61c20c2f67287..215ddac936a54 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 @@ public function testPassPlaceholderToView($multiple, $expanded, $required, $plac /** * @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 34889ed321cd9..de12bb1e44a66 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 @@ public function testPassPlaceholderAsString() $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 f690917cd7acb..5cb542993924a 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 @@ public function testPassPlaceholderAsString() $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 e0faf4c179e28..520f9f22ef112 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 @@ public function testPassPlaceholderAsString() $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 ee822316ade37..a4dcc1532a86f 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 @@ public function test2Dot5ValidationApi() $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 @@ public function test2Dot4ValidationApi() /** * @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 232fb5513f768..9baee2f37c625 100644 --- a/src/Symfony/Component/Validator/ConstraintViolationInterface.php +++ b/src/Symfony/Component/Validator/ConstraintViolationInterface.php @@ -68,6 +68,8 @@ public function getMessageTemplate(); * @see getMessageTemplate() * * @api + * + * @deprecated since version 2.7, to be replaced by getParameters() in 3.0. */ public function getMessageParameters(); @@ -86,6 +88,8 @@ public function getMessageParameters(); * 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 eaf2f3c0114c2..a75e6d2f66dfb 100644 --- a/src/Symfony/Component/Validator/Constraints/CallbackValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CallbackValidator.php @@ -54,7 +54,10 @@ public function validate($object, Constraint $constraint) $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 b619291665e9d..5ad8276563344 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CallbackValidatorTest.php @@ -298,7 +298,7 @@ public function testExpectValidMethods() { $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 @@ public function testExpectValidCallbacks() { $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 a2da68f9f1d30..6995d25817988 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php @@ -544,6 +544,7 @@ public function testAddCustomizedViolation() /** * @expectedException \Symfony\Component\Validator\Exception\UnsupportedMetadataException + * @group legacy */ public function testMetadataMustImplementClassMetadataInterface() { @@ -561,6 +562,7 @@ public function testMetadataMustImplementClassMetadataInterface() /** * @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 22af86e3deb32..d78b67bee7e9a 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/AbstractLegacyApiTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/AbstractLegacyApiTest.php @@ -26,6 +26,7 @@ * @since 2.5 * * @author Bernhard Schussek + * @group legacy */ abstract class AbstractLegacyApiTest extends AbstractValidatorTest {