|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\Component\ErrorHandler\Exception\FlattenException;
|
16 | 16 | use Symfony\Component\HttpKernel\Exception\HttpException;
|
| 17 | +use Symfony\Component\Messenger\Exception\ValidationFailedException as MessageValidationFailedException; |
17 | 18 | use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
|
18 | 19 | use Symfony\Component\Serializer\Exception\PartialDenormalizationException;
|
19 | 20 | use Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer;
|
@@ -102,4 +103,28 @@ public function testNormalizeValidationFailedException()
|
102 | 103 | $exception = new HttpException(422, 'Validation Failed', $exception);
|
103 | 104 | $this->assertSame($expected, $this->normalizer->normalize(FlattenException::createFromThrowable($exception), null, ['exception' => $exception]));
|
104 | 105 | }
|
| 106 | + |
| 107 | + public function testNormalizeMessageValidationFailedException() |
| 108 | + { |
| 109 | + $this->normalizer->setSerializer(new Serializer([new ConstraintViolationListNormalizer()])); |
| 110 | + |
| 111 | + $expected = [ |
| 112 | + 'type' => 'https://symfony.com/errors/validation', |
| 113 | + 'title' => 'Validation Failed', |
| 114 | + 'status' => 422, |
| 115 | + 'detail' => 'Invalid value', |
| 116 | + 'violations' => [ |
| 117 | + [ |
| 118 | + 'propertyPath' => '', |
| 119 | + 'title' => 'Invalid value', |
| 120 | + 'template' => '', |
| 121 | + 'parameters' => [], |
| 122 | + ], |
| 123 | + ], |
| 124 | + ]; |
| 125 | + |
| 126 | + $exception = new MessageValidationFailedException(new \stdClass(), new ConstraintViolationList([new ConstraintViolation('Invalid value', '', [], '', null, null)])); |
| 127 | + $exception = new HttpException(422, 'Validation Failed', $exception); |
| 128 | + $this->assertSame($expected, $this->normalizer->normalize(FlattenException::createFromThrowable($exception), null, ['exception' => $exception])); |
| 129 | + } |
105 | 130 | }
|
0 commit comments