Skip to content

Commit 5de077e

Browse files
authored
fix(symfony): use Type constraint violation code instead of exception code (#6064)
1 parent 1dd35b6 commit 5de077e

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

features/main/validation.feature

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,39 +102,39 @@ Feature: Using validations groups
102102
{
103103
"propertyPath": "",
104104
"message": "This value should be of type unknown.",
105-
"code": "0",
105+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40",
106106
"hint": "Failed to create object because the class misses the \"baz\" property."
107107
},
108108
{
109109
"propertyPath": "qux",
110110
"message": "This value should be of type string.",
111-
"code": "0"
111+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40"
112112
},
113113
{
114114
"propertyPath": "foo",
115115
"message": "This value should be of type bool.",
116-
"code": "0"
116+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40"
117117
},
118118
{
119119
"propertyPath": "bar",
120120
"message": "This value should be of type int.",
121-
"code": "0"
121+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40"
122122
},
123123
{
124124
"propertyPath": "uuid",
125125
"message": "This value should be of type uuid.",
126-
"code": "0",
126+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40",
127127
"hint": "Invalid UUID string: y"
128128
},
129129
{
130130
"propertyPath": "relatedDummy",
131131
"message": "This value should be of type array|string.",
132-
"code": "0"
132+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40"
133133
},
134134
{
135135
"propertyPath": "relatedDummies",
136136
"message": "This value should be of type array.",
137-
"code": "0"
137+
"code": "ba785a8c-82cb-4283-967c-3cf342181b40"
138138
}
139139
]
140140
}

src/Symfony/EventListener/DeserializeListener.php

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

tests/Symfony/EventListener/DeserializeListenerTest.php

Lines changed: 1 addition & 1 deletion
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)