Skip to content

Commit f75649d

Browse files
committed
fix(symfony): use Type constraint violation code instead of exception code
1 parent fe07a7f commit f75649d

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

features/main/validation.feature

+7-7
Original file line numberDiff line numberDiff line change
@@ -119,40 +119,40 @@ Feature: Using validations groups
119119
{
120120
"propertyPath": "",
121121
"message": "This value should be of type unknown.",
122-
"code": "0",
122+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40",
123123
"hint": "Failed to create object because the class misses the \"baz\" property."
124124
},
125125
{
126126
"propertyPath": "qux",
127127
"message": "This value should be of type string.",
128-
"code": "0"
128+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40"
129129
},
130130
{
131131
"propertyPath": "foo",
132132
"message": "This value should be of type bool.",
133-
"code": "0"
133+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40"
134134
},
135135
{
136136
"propertyPath": "bar",
137137
"message": "This value should be of type int.",
138-
"code": "0"
138+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40"
139139
},
140140
{
141141
"propertyPath": "uuid",
142142
"message": "This value should be of type uuid.",
143-
"code": "0",
143+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40",
144144
"hint": "Invalid UUID string: y"
145145
},
146146
{
147147
"propertyPath": "relatedDummy",
148148
"message": "This value should be of type array|string.",
149-
"code": "0",
149+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40",
150150
"hint": "The type of the \"relatedDummy\" attribute must be \"array\" (nested document) or \"string\" (IRI), \"integer\" given."
151151
},
152152
{
153153
"propertyPath": "relatedDummies",
154154
"message": "This value should be of type array.",
155-
"code": "0"
155+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40"
156156
}
157157
]
158158
}

src/State/Provider/DeserializeProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
9797
if ($exception->canUseMessageForUser()) {
9898
$parameters['hint'] = $exception->getMessage();
9999
}
100-
$violations->add(new ConstraintViolation($this->translator->trans($message, ['{{ type }}' => implode('|', $exception->getExpectedTypes() ?? [])], 'validators'), $message, $parameters, null, $exception->getPath(), null, null, (string) $exception->getCode()));
100+
$violations->add(new ConstraintViolation($this->translator->trans($message, ['{{ type }}' => implode('|', $exception->getExpectedTypes() ?? [])], 'validators'), $message, $parameters, null, $exception->getPath(), null, null, (string) Type::INVALID_TYPE_ERROR));
101101
}
102102
if (0 !== \count($violations)) {
103103
throw new ValidationException($violations);

src/Symfony/EventListener/DeserializeListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function onKernelRequest(RequestEvent $event): void
115115
if ($exception->canUseMessageForUser()) {
116116
$parameters['hint'] = $exception->getMessage();
117117
}
118-
$violations->add(new ConstraintViolation($this->translator->trans($message, ['{{ type }}' => implode('|', $exception->getExpectedTypes() ?? [])], 'validators'), $message, $parameters, null, $exception->getPath(), null, null, (string) $exception->getCode()));
118+
$violations->add(new ConstraintViolation($this->translator->trans($message, ['{{ type }}' => implode('|', $exception->getExpectedTypes() ?? [])], 'validators'), $message, $parameters, null, $exception->getPath(), null, null, Type::INVALID_TYPE_ERROR));
119119
}
120120
if (0 !== \count($violations)) {
121121
throw new ValidationException($violations);

tests/Symfony/EventListener/DeserializeListenerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public function testTurnPartialDenormalizationExceptionIntoValidationException()
366366
$this->assertSame($violation->getPropertyPath(), 'foo');
367367
$this->assertNull($violation->getInvalidValue());
368368
$this->assertNull($violation->getPlural());
369-
$this->assertSame($violation->getCode(), '0');
369+
$this->assertSame($violation->getCode(), 'ba785a8c-82cb-4283-967c-3cf342181b40');
370370
}
371371
}
372372
}

0 commit comments

Comments
 (0)