From 60bc402f8cdc397567370a668478e1f759966e7b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 8 Jan 2015 12:50:58 +0100 Subject: [PATCH] [Form] fixed deprecation triggers, removed usage of deprecated features --- .../Component/Form/Exception/AlreadyBoundException.php | 10 ++++++++-- .../Validator/ViolationMapper/ViolationMapper.php | 4 ++-- src/Symfony/Component/Form/Tests/CompoundFormTest.php | 8 ++++++-- .../Form/Tests/Extension/Core/Type/FormTypeTest.php | 4 +++- .../Validator/Constraints/FormValidatorTest.php | 2 +- src/Symfony/Component/Form/Tests/SimpleFormTest.php | 4 +++- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Component/Form/Exception/AlreadyBoundException.php b/src/Symfony/Component/Form/Exception/AlreadyBoundException.php index 03e258ff07..debedf4521 100644 --- a/src/Symfony/Component/Form/Exception/AlreadyBoundException.php +++ b/src/Symfony/Component/Form/Exception/AlreadyBoundException.php @@ -11,8 +11,6 @@ namespace Symfony\Component\Form\Exception; -trigger_error('The '.__NAMESPACE__.'\AlreadyBoundException class is deprecated since version 2.3 and will be removed in 3.0. Use the Symfony\Component\Form\Exception\AlreadySubmittedException class instead.', E_USER_DEPRECATED); - /** * Alias of {@link AlreadySubmittedException}. * @@ -21,4 +19,12 @@ trigger_error('The '.__NAMESPACE__.'\AlreadyBoundException class is deprecated s */ class AlreadyBoundException extends LogicException { + public function __construct($message = '', $code = 0, \Exception $previous = null) + { + if (__CLASS__ === get_class($this)) { + trigger_error('The '.__CLASS__.' class is deprecated since version 2.3 and will be removed in 3.0. Use the Symfony\Component\Form\Exception\AlreadySubmittedException class instead.', E_USER_DEPRECATED); + } + + parent::__construct($message, $code, $previous); + } } diff --git a/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php b/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php index 1007924b6b..8ea37bff7a 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php +++ b/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php @@ -127,8 +127,8 @@ class ViolationMapper implements ViolationMapperInterface $scope->addError(new FormError( $violation->getMessage(), $violation->getMessageTemplate(), - $violation->getMessageParameters(), - $violation->getMessagePluralization(), + $violation->getParameters(), + $violation->getPlural(), $violation )); } diff --git a/src/Symfony/Component/Form/Tests/CompoundFormTest.php b/src/Symfony/Component/Form/Tests/CompoundFormTest.php index 9bb2528c6e..57c2f7a2e9 100644 --- a/src/Symfony/Component/Form/Tests/CompoundFormTest.php +++ b/src/Symfony/Component/Form/Tests/CompoundFormTest.php @@ -791,8 +791,10 @@ class CompoundFormTest extends AbstractFormTest $this->assertEquals(array('extra' => 'data'), $form->getExtraData()); } - public function testGetErrorsAsStringDeep() + public function testLegacyGetErrorsAsStringDeep() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $parent = $this->getBuilder() ->setCompound(true) ->setDataMapper($this->getDataMapper()) @@ -810,8 +812,10 @@ class CompoundFormTest extends AbstractFormTest ); } - public function testGetErrorsAsStringDeepWithIndentation() + public function testLegacyGetErrorsAsStringDeepWithIndentation() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $parent = $this->getBuilder() ->setCompound(true) ->setDataMapper($this->getDataMapper()) diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php index 93d5285405..c578ab20b5 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FormTypeTest.php @@ -637,8 +637,10 @@ class FormTypeTest extends BaseTypeTest $this->assertSame('0', $view->vars['label']); } - public function testCanGetErrorsWhenButtonInForm() + public function testLegacyCanGetErrorsWhenButtonInForm() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $builder = $this->factory->createBuilder('form', null, array( 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', 'required' => false, diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php index e1b941ab8e..d62a315839 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorTest.php @@ -575,7 +575,7 @@ class FormValidatorTest extends AbstractConstraintValidatorTest ->add($this->getBuilder('child')) ->getForm(); - $form->bind(array('foo' => 'bar')); + $form->submit(array('foo' => 'bar')); $context->expects($this->never()) ->method('addViolation'); diff --git a/src/Symfony/Component/Form/Tests/SimpleFormTest.php b/src/Symfony/Component/Form/Tests/SimpleFormTest.php index 4c4e0ed8de..016f58c524 100644 --- a/src/Symfony/Component/Form/Tests/SimpleFormTest.php +++ b/src/Symfony/Component/Form/Tests/SimpleFormTest.php @@ -733,8 +733,10 @@ class SimpleFormTest extends AbstractFormTest $this->assertSame($view, $form->createView($parentView)); } - public function testGetErrorsAsString() + public function testLegacyGetErrorsAsString() { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + $this->form->addError(new FormError('Error!')); $this->assertEquals("ERROR: Error!\n", $this->form->getErrorsAsString());