8000 [Validator] Remove DateTime support in date/time validators by ro0NL · Pull Request #31679 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Remove DateTime support in date/time validators #31679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Validator] Remove DateTime support in date/time validators
  • Loading branch information
ro0NL committed May 29, 2019
commit 37c1cbbed3f74f2340a1997a9f905556b825bc1b
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ public function validate($value, Constraint $constraint)
return;
}

if ($value instanceof \DateTimeInterface) {
8000 @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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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