Skip to content

Commit

Permalink
minor #31679 [Validator] Remove DateTime support in date/time validat…
Browse files Browse the repository at this point in the history
…ors (ro0NL)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[Validator] Remove DateTime support in date/time validators

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

See #25015

Commits
-------

37c1cbb [Validator] Remove DateTime support in date/time validators
  • Loading branch information
nicolas-grekas committed May 29, 2019
2 parents 03797a1 + 37c1cbb commit a052378
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 84 deletions.
Expand Up @@ -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');
}
Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Component/Validator/Constraints/DateValidator.php
Expand Up @@ -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');
}
Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Component/Validator/Constraints/TimeValidator.php
Expand Up @@ -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');
}
Expand Down
Expand Up @@ -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
*/
Expand Down
Expand Up @@ -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
*/
Expand Down
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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();
}
}

0 comments on commit a052378

Please sign in to comment.