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

api-platform / core / 7407219156

04 Jan 2024 08:32AM UTC coverage: 35.357% (-1.9%) from 37.257%
7407219156

push

github

soyuka
cs: various fixes

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

425 existing lines in 27 files now uncovered.

10237 of 28953 relevant lines covered (35.36%)

27.07 hits per line

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

0.0
/src/GraphQl/Tests/Serializer/Exception/ValidationExceptionNormalizerTest.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\GraphQl\Tests\Serializer\Exception;
15

16
use ApiPlatform\GraphQl\Serializer\Exception\ValidationExceptionNormalizer;
17
use ApiPlatform\Validator\Exception\ConstraintViolationListAwareExceptionInterface;
18
use GraphQL\Error\Error;
19
use PHPUnit\Framework\TestCase;
20
use Symfony\Component\Validator\ConstraintViolation;
21
use Symfony\Component\Validator\ConstraintViolationList;
22
use Symfony\Component\Validator\ConstraintViolationListInterface;
23

24
/**
25
 * @author Mahmood Bazdar<mahmood@bazdar.me>
26
 */
27
class ValidationExceptionNormalizerTest extends TestCase
28
{
29
    private ValidationExceptionNormalizer $validationExceptionNormalizer;
30

31
    /**
32
     * {@inheritdoc}
33
     */
34
    protected function setUp(): void
35
    {
UNCOV
36
        $this->validationExceptionNormalizer = new ValidationExceptionNormalizer();
×
37
    }
38

39
    public function testNormalize(): void
40
    {
41
        $exceptionMessage = 'exception message';
×
42
        $exception = new class($exceptionMessage) extends \Exception implements ConstraintViolationListAwareExceptionInterface {
×
43
            public function getConstraintViolationList(): ConstraintViolationListInterface
44
            {
45
                return new ConstraintViolationList([
×
UNCOV
46
                    new ConstraintViolation('message 1', '', [], '', 'field 1', 'invalid'),
×
47
                    new ConstraintViolation('message 2', '', [], '', 'field 2', 'invalid'),
×
48
                ]);
×
49
            }
UNCOV
50
        };
×
51
        $error = new Error('test message', null, null, [], null, $exception);
×
52

UNCOV
53
        $normalizedError = $this->validationExceptionNormalizer->normalize($error);
×
54
        $this->assertSame($exceptionMessage, $normalizedError['message']);
×
55
        $this->assertSame(422, $normalizedError['extensions']['status']);
×
56
        // graphql-php < 15
57
        if (\defined(Error::class.'::CATEGORY_INTERNAL')) {
×
58
            $this->assertSame('user', $normalizedError['extensions']['category']);
×
59
        }
60
        $this->assertArrayHasKey('violations', $normalizedError['extensions']);
×
61
        $this->assertEquals([
×
62
            [
×
63
                'path' => 'field 1',
×
64
                'message' => 'message 1',
×
UNCOV
65
            ],
×
UNCOV
66
            [
×
UNCOV
67
                'path' => 'field 2',
×
UNCOV
68
                'message' => 'message 2',
×
69
            ],
×
70
        ], $normalizedError['extensions']['violations']);
×
71
    }
72

73
    public function testSupportsNormalization(): void
74
    {
UNCOV
75
        $exception = $this->createStub(ConstraintViolationListAwareExceptionInterface::class);
×
UNCOV
76
        $exception->method('getConstraintViolationList')->willReturn(new ConstraintViolationList([]));
×
UNCOV
77
        $error = new Error('test message', null, null, [], null, $exception);
×
78

UNCOV
79
        $this->assertTrue($this->validationExceptionNormalizer->supportsNormalization($error));
×
80
    }
81
}
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

© 2025 Coveralls, Inc