8000 [Serializer] Fix tests · symfony/symfony@967a351 · GitHub
[go: up one dir, main page]

Skip to content

Commit 967a351

Browse files
[Serializer] Fix tests
1 parent 1bc8c67 commit 967a351

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,22 @@ public function normalize(mixed $object, string $format = null, array $context =
6868
$template = 'This value should be of type {{ type }}.';
6969
$data = [
7070
self::TYPE => 'https://symfony.com/errors/validation',
71+
self::TITLE => 'Validation Failed',
7172
'violations' => array_map(
7273
fn ($e) => [
7374
'propertyPath' => $e->getPath(),
7475
'title' => $trans($template, [
7576
'{{ type }}' => implode('|', $e->getExpectedTypes() ?? ['?']),
7677
], 'validators'),
7778
'template' => $template,
78-
'parameter' => [
79+
'parameters' => [
7980
'{{ type }}' => implode('|', $e->getExpectedTypes() ?? ['?']),
8081
],
8182
] + ($debug || $e->canUseMessageForUser() ? ['hint' => $e->getMessage()] : []),
8283
$exception->getErrors()
8384
),
8485
];
86+
$data['detail'] = implode("\n", array_map(fn ($e) => $e['propertyPath'].': '.$e['title'], $data['violations']));
8587
} elseif ($exception instanceof ValidationFailedException
8688
&& $this->serializer instanceof NormalizerInterface
8789
&& $this->serializer->supportsNormalization($exception->getViolations(), $format, $context)
@@ -94,7 +96,7 @@ public function normalize(mixed $object, string $format = null, array $context =
9496
self::TYPE => $data[self::TYPE] ?? $context[self::TYPE] ?? 'https://tools.ietf.org/html/rfc2616#section-10',
9597
self::TITLE => $data[self::TITLE] ?? $context[self::TITLE] ?? 'An error occurred',
9698
self::STATUS => $context[self::STATUS] ?? $object->getStatusCode(),
97-
'detail' => $debug ? $object->getMessage() : $object->getStatusText(),
99+
'detail' => $data['detail'] ?? ($debug ? $object->getMessage() : $object->getStatusText()),
98100
] + $data;
99101
if ($debug) {
100102
$data['class'] = $object->getClass();

src/Symfony/Component/Serializer/Tests/Normalizer/ProblemNormalizerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public function testNormalizePartialDenormalizationException()
6060

6161
$expected = [
6262
'type' => 'https://symfony.com/errors/validation',
63-
'title' => 'An error occurred',
63+
'title' => 'Validation Failed',
6464
'status' => 422,
65-
'detail' => 'Unprocessable Content',
65+
'detail' => 'foo: This value should be of type int.',
6666
'violations' => [
6767
[
6868
'propertyPath' => 'foo',
@@ -90,7 +90,7 @@ public function testNormalizeValidationFailedException()
9090
'type' => 'https://symfony.com/errors/validation',
9191
'title' => 'Validation Failed',
9292
'status' => 422,
93-
'detail' => 'Unprocessable Content',
93+
'detail' => 'Invalid value',
9494
'violations' => [
9595
[
9696
'propertyPath' => '',

0 commit comments

Comments
 (0)
0