[Serializer] Normalize constraint violation parameters

This commit is contained in:
Maxime Steinhausser 2018-11-07 18:51:10 +01:00
parent 3895acd175
commit 32c90ebc8e
3 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
4.3.0
-----
* added the list of constraint violations' parameters in `ConstraintViolationListNormalizer`
4.2.0
-----

View File

@ -49,6 +49,7 @@ class ConstraintViolationListNormalizer implements NormalizerInterface, Cacheabl
$violationEntry = [
'propertyPath' => $propertyPath,
'title' => $violation->getMessage(),
'parameters' => $violation->getParameters(),
];
if (null !== $code = $violation->getCode()) {
$violationEntry['type'] = sprintf('urn:uuid:%s', $code);

View File

@ -38,7 +38,7 @@ class ConstraintViolationListNormalizerTest extends TestCase
public function testNormalize()
{
$list = new ConstraintViolationList([
new ConstraintViolation('a', 'b', [], 'c', 'd', 'e', null, 'f'),
new ConstraintViolation('a', 'b', ['value' => 'foo'], 'c', 'd', 'e', null, 'f'),
new ConstraintViolation('1', '2', [], '3', '4', '5', null, '6'),
]);
@ -52,11 +52,15 @@ class ConstraintViolationListNormalizerTest extends TestCase
'propertyPath' => 'd',
'title' => 'a',
'type' => 'urn:uuid:f',
'parameters' => [
'value' => 'foo',
],
],
[
'propertyPath' => '4',
'title' => '1',
'type' => 'urn:uuid:6',
'parameters' => [],
],
],
];