• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 14980015570

12 May 2025 06:41PM UTC coverage: 26.309% (+2.6%) from 23.685%
14980015570

Pull #7140

github

web-flow
Merge 1e6b14143 into 202c60fcb
Pull Request #7140: Fix: PHPize HTTP cache headers

0 of 1 new or added line in 1 file covered. (0.0%)

4614 existing lines in 185 files now uncovered.

13550 of 51504 relevant lines covered (26.31%)

71.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/JsonApi/Tests/Serializer/ConstraintViolationNormalizerTest.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\JsonApi\Tests\Serializer;
15

16
use ApiPlatform\JsonApi\Serializer\ConstraintViolationListNormalizer;
17
use ApiPlatform\JsonApi\Tests\Fixtures\Dummy;
18
use ApiPlatform\JsonApi\Tests\Fixtures\RelatedDummy;
19
use ApiPlatform\Metadata\ApiProperty;
20
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
21
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
22
use PHPUnit\Framework\TestCase;
23
use Prophecy\PhpUnit\ProphecyTrait;
24
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
25
use Symfony\Component\TypeInfo\Type;
26
use Symfony\Component\Validator\ConstraintViolation;
27
use Symfony\Component\Validator\ConstraintViolationList;
28
use Symfony\Component\Validator\ConstraintViolationListInterface;
29

30
/**
31
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
32
 */
33
class ConstraintViolationNormalizerTest extends TestCase
34
{
35
    use ProphecyTrait;
36

37
    public function testSupportNormalization(): void
38
    {
39
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
UNCOV
40
        $nameConverterInterface = $this->prophesize(NameConverterInterface::class);
×
41

UNCOV
42
        $normalizer = new ConstraintViolationListNormalizer($propertyMetadataFactoryProphecy->reveal(), $nameConverterInterface->reveal());
×
43

44
        $this->assertTrue($normalizer->supportsNormalization(new ConstraintViolationList(), ConstraintViolationListNormalizer::FORMAT));
×
45
        $this->assertFalse($normalizer->supportsNormalization(new ConstraintViolationList(), 'xml'));
×
46
        $this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ConstraintViolationListNormalizer::FORMAT));
×
47
        $this->assertEmpty($normalizer->getSupportedTypes('json'));
×
UNCOV
48
        $this->assertSame([ConstraintViolationListInterface::class => true], $normalizer->getSupportedTypes($normalizer::FORMAT));
×
49
    }
50

51
    #[IgnoreDeprecations]
52
    public function testNormalize(): void
53
    {
54
        $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
×
UNCOV
55
        $propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy')->willReturn((new ApiProperty())->withNativeType(Type::object(RelatedDummy::class)))->shouldBeCalledTimes(1);
×
56
        $propertyMetadataFactoryProphecy->create(Dummy::class, 'name')->willReturn((new ApiProperty())->withNativeType(Type::string()))->shouldBeCalledTimes(1);
×
57

58
        $nameConverterProphecy = $this->prophesize(NameConverterInterface::class);
×
UNCOV
59
        $nameConverterProphecy->normalize('relatedDummy', Dummy::class, 'jsonapi')->willReturn('relatedDummy')->shouldBeCalledTimes(1);
×
60
        $nameConverterProphecy->normalize('name', Dummy::class, 'jsonapi')->willReturn('name')->shouldBeCalledTimes(1);
×
61

62
        $dummy = new Dummy();
×
63

64
        $constraintViolationList = new ConstraintViolationList([
×
65
            new ConstraintViolation('This value should not be null.', 'This value should not be null.', [], $dummy, 'relatedDummy', null),
×
66
            new ConstraintViolation('This value should not be null.', 'This value should not be null.', [], $dummy, 'name', null),
×
UNCOV
67
            new ConstraintViolation('Unknown violation.', 'Unknown violation.', [], $dummy, '', ''),
×
68
        ]);
×
69

70
        $this->assertEquals(
×
71
            [
×
72
                'errors' => [
×
73
                    [
×
74
                        'detail' => 'This value should not be null.',
×
75
                        'source' => [
×
76
                            'pointer' => 'data/relationships/relatedDummy',
×
77
                        ],
×
78
                    ],
×
79
                    [
×
80
                        'detail' => 'This value should not be null.',
×
81
                        'source' => [
×
82
                            'pointer' => 'data/attributes/name',
×
83
                        ],
×
84
                    ],
×
85
                    [
×
86
                        'detail' => 'Unknown violation.',
×
87
                        'source' => [
×
88
                            'pointer' => 'data',
×
89
                        ],
×
90
                    ],
×
91
                ],
×
92
            ],
×
UNCOV
93
            (new ConstraintViolationListNormalizer($propertyMetadataFactoryProphecy->reveal(), $nameConverterProphecy->reveal()))->normalize($constraintViolationList)
×
UNCOV
94
        );
×
95
    }
96
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc