From 37c1cbbed3f74f2340a1997a9f905556b825bc1b Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Wed, 29 May 2019 10:06:33 +0200 Subject: [PATCH] [Validator] Remove DateTime support in date/time validators --- .../Constraints/DateTimeValidator.php | 6 ----- .../Validator/Constraints/DateValidator.php | 6 ----- .../Validator/Constraints/TimeValidator.php | 6 ----- .../Constraints/DateTimeValidatorTest.php | 22 ------------------- .../Tests/Constraints/DateValidatorTest.php | 22 ------------------- .../Tests/Constraints/TimeValidatorTest.php | 22 ------------------- 6 files changed, 84 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php index 16abf6f671ce4..73ff99c9dcb63 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php @@ -34,12 +34,6 @@ public function validate($value, Constraint $constraint) return; } - if ($value instanceof \DateTimeInterface) { - @trigger_error(sprintf('Validating a \\DateTimeInterface with "%s" is deprecated since version 4.2. Use "%s" instead or remove the constraint if the underlying model is already type hinted to \\DateTimeInterface.', DateTime::class, Type::class), E_USER_DEPRECATED); - - return; - } - if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedValueException($value, 'string'); } diff --git a/src/Symfony/Component/Validator/Constraints/DateValidator.php b/src/Symfony/Component/Validator/Constraints/DateValidator.php index 93b1f7d074e18..b3bbb5da20228 100644 --- a/src/Symfony/Component/Validator/Constraints/DateValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateValidator.php @@ -52,12 +52,6 @@ public function validate($value, Constraint $constraint) return; } - if ($value instanceof \DateTimeInterface) { - @trigger_error(sprintf('Validating a \\DateTimeInterface with "%s" is deprecated since version 4.2. Use "%s" instead or remove the constraint if the underlying model is already type hinted to \\DateTimeInterface.', Date::class, Type::class), E_USER_DEPRECATED); - - return; - } - if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedValueException($value, 'string'); } diff --git a/src/Symfony/Component/Validator/Constraints/TimeValidator.php b/src/Symfony/Component/Validator/Constraints/TimeValidator.php index 799dbc3108e0c..2613ac5280354 100644 --- a/src/Symfony/Component/Validator/Constraints/TimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/TimeValidator.php @@ -52,12 +52,6 @@ public function validate($value, Constraint $constraint) return; } - if ($value instanceof \DateTimeInterface) { - @trigger_error(sprintf('Validating a \\DateTimeInterface with "%s" is deprecated since version 4.2. Use "%s" instead or remove the constraint if the underlying model is already type hinted to \\DateTimeInterface.', Time::class, Type::class), E_USER_DEPRECATED); - - return; - } - if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) { throw new UnexpectedValueException($value, 'string'); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php index 06f3894cfc962..968ce10178062 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php @@ -36,28 +36,6 @@ public function testEmptyStringIsValid() $this->assertNoViolation(); } - /** - * @group legacy - * @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\DateTime" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface. - */ - public function testDateTimeClassIsValid() - { - $this->validator->validate(new \DateTime(), new DateTime()); - - $this->assertNoViolation(); - } - - /** - * @group legacy - * @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\DateTime" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface. - */ - public function testDateTimeImmutableClassIsValid() - { - $this->validator->validate(new \DateTimeImmutable(), new DateTime()); - - $this->assertNoViolation(); - } - /** * @expectedException \Symfony\Component\Validator\Exception\UnexpectedValueException */ diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php index 4dc8a966b4ccf..fa3bdd49ee442 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateValidatorTest.php @@ -36,28 +36,6 @@ public function testEmptyStringIsValid() $this->assertNoViolation(); } - /** - * @group legacy - * @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\Date" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface. - */ - public function testDateTimeClassIsValid() - { - $this->validator->validate(new \DateTime(), new Date()); - - $this->assertNoViolation(); - } - - /** - * @group legacy - * @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\Date" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface. - */ - public function testDateTimeImmutableClassIsValid() - { - $this->validator->validate(new \DateTimeImmutable(), new Date()); - - $this->assertNoViolation(); - } - /** * @expectedException \Symfony\Component\Validator\Exception\UnexpectedValueException */ diff --git a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php index e2045628456e5..da5b4eb9df7bb 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/TimeValidatorTest.php @@ -36,17 +36,6 @@ public function testEmptyStringIsValid() $this->assertNoViolation(); } - /** - * @group legacy - * @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\Time" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface. - */ - public function testDateTimeClassIsValid() - { - $this->validator->validate(new \DateTime(), new Time()); - - $this->assertNoViolation(); - } - /** * @expectedException \Symfony\Component\Validator\Exception\UnexpectedValueException */ @@ -103,15 +92,4 @@ public function getInvalidTimes() ['00:00:60', Time::INVALID_TIME_ERROR], ]; } - - /** - * @group legacy - * @expectedDeprecation Validating a \DateTimeInterface with "Symfony\Component\Validator\Constraints\Time" is deprecated since version 4.2. Use "Symfony\Component\Validator\Constraints\Type" instead or remove the constraint if the underlying model is already type hinted to \DateTimeInterface. - */ - public function testDateTimeImmutableIsValid() - { - $this->validator->validate(new \DateTimeImmutable(), new Time()); - - $this->assertNoViolation(); - } }