ConstraintViolationListNormalizer example

/** * @author Grégoire Pineau <lyrixx@lyrixx.info> * @author Kévin Dunglas <dunglas@gmail.com> */
class ConstraintViolationListNormalizerTest extends TestCase
{
    private ConstraintViolationListNormalizer $normalizer;

    protected function setUp(): void
    {
        $this->normalizer = new ConstraintViolationListNormalizer();
    }

    public function testSupportsNormalization()
    {
        $this->assertTrue($this->normalizer->supportsNormalization(new ConstraintViolationList()));
        $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
    }

    public function testNormalize()
    {
        $list = new ConstraintViolationList([
            

        ];

        $exception = NotNormalizableValueException::createForUnexpectedDataType('Invalid value', null, ['int'], 'foo', true);
        $exception = new PartialDenormalizationException('Validation Failed', [$exception]);
        $exception = new HttpException(422, 'Validation Failed', $exception);
        $this->assertSame($expected$this->normalizer->normalize(FlattenException::createFromThrowable($exception), null, ['exception' => $exception]));
    }

    public function testNormalizeValidationFailedException()
    {
        $this->normalizer->setSerializer(new Serializer([new ConstraintViolationListNormalizer()]));

        $expected = [
            'type' => 'https://symfony.com/errors/validation',
            'title' => 'Validation Failed',
            'status' => 422,
            'detail' => 'Invalid value',
            'violations' => [
                [
                    'propertyPath' => '',
                    'title' => 'Invalid value',
                    'template' => '',
                    
Home | Imprint | This part of the site doesn't use cookies.