diff --git a/src/Symfony/Bridge/Monolog/Tests/Handler/ChromePhpHandlerTest.php b/src/Symfony/Bridge/Monolog/Tests/Handler/ChromePhpHandlerTest.php index 1d237059619f7..a83ef9eb6cbd5 100644 --- a/src/Symfony/Bridge/Monolog/Tests/Handler/ChromePhpHandlerTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/Handler/ChromePhpHandlerTest.php @@ -22,15 +22,19 @@ class ChromePhpHandlerTest extends TestCase { public function testOnKernelResponseShouldNotTriggerDeprecation() { - $this->expectNotToPerformAssertions(); - $request = Request::create('/'); $request->headers->remove('User-Agent'); $response = new Response('foo'); $event = new ResponseEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST, $response); + $error = null; + set_error_handler(function ($type, $message) use (&$error) { $error = $message; }, \E_DEPRECATED); + $listener = new ChromePhpHandler(); $listener->onKernelResponse($event); + restore_error_handler(); + + $this->assertNull($error); } } diff --git a/src/Symfony/Component/Validator/CHANGELOG.md b/src/Symfony/Component/Validator/CHANGELOG.md index 5e480139e8690..b5e79134e98a9 100644 --- a/src/Symfony/Component/Validator/CHANGELOG.md +++ b/src/Symfony/Component/Validator/CHANGELOG.md @@ -18,6 +18,7 @@ CHANGELOG * Add the `Week` constraint * Add `CompoundConstraintTestCase` to ease testing Compound Constraints * Add context variable to `WhenValidator` + * Add `format` parameter to `DateTime` constraint violation message 7.1 --- diff --git a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php index 9784a57976d29..f5765cbf6e119 100644 --- a/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php +++ b/src/Symfony/Component/Validator/Constraints/DateTimeValidator.php @@ -44,6 +44,7 @@ public function validate(mixed $value, Constraint $constraint): void if (0 < $errors['error_count']) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setParameter('{{ format }}', $this->formatValue($constraint->format)) ->setCode(DateTime::INVALID_FORMAT_ERROR) ->addViolation(); @@ -58,16 +59,19 @@ public function validate(mixed $value, Constraint $constraint): void if ('The parsed date was invalid' === $warning) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setParameter('{{ format }}', $this->formatValue($constraint->format)) ->setCode(DateTime::INVALID_DATE_ERROR) ->addViolation(); } elseif ('The parsed time was invalid' === $warning) { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setParameter('{{ format }}', $this->formatValue($constraint->format)) ->setCode(DateTime::INVALID_TIME_ERROR) ->addViolation(); } else { $this->context->buildViolation($constraint->message) ->setParameter('{{ value }}', $this->formatValue($value)) + ->setParameter('{{ format }}', $this->formatValue($constraint->format)) ->setCode(DateTime::INVALID_FORMAT_ERROR) ->addViolation(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php index 8da07c424f40e..42519ffd4d6d6 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DateTimeValidatorTest.php @@ -53,6 +53,7 @@ public function testDateTimeWithDefaultFormat() $this->buildViolation('This value is not a valid datetime.') ->setParameter('{{ value }}', '"1995-03-24"') + ->setParameter('{{ format }}', '"Y-m-d H:i:s"') ->setCode(DateTime::INVALID_FORMAT_ERROR) ->assertRaised(); } @@ -96,6 +97,7 @@ public function testInvalidDateTimes($format, $dateTime, $code) $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"'.$dateTime.'"') + ->setParameter('{{ format }}', '"'.$format.'"') ->setCode($code) ->assertRaised(); } @@ -124,6 +126,7 @@ public function testInvalidDateTimeNamed() $this->buildViolation('myMessage') ->setParameter('{{ value }}', '"2010-01-01 00:00:00"') + ->setParameter('{{ format }}', '"Y-m-d"') ->setCode(DateTime::INVALID_FORMAT_ERROR) ->assertRaised(); }