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

api-platform / core / 13203378522

07 Feb 2025 03:56PM UTC coverage: 8.501% (+0.7%) from 7.837%
13203378522

push

github

soyuka
Merge 4.1

111 of 490 new or added lines in 51 files covered. (22.65%)

5590 existing lines in 163 files now uncovered.

13345 of 156987 relevant lines covered (8.5%)

22.88 hits per line

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

0.0
/tests/Functional/ErrorTest.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\Tests\Functional;
15

16
use ApiPlatform\State\ApiResource\Error;
17
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
18
use ApiPlatform\Tests\SetupClassResourcesTrait;
19
use PHPUnit\Framework\Attributes\DataProvider;
20

21
final class ErrorTest extends ApiTestCase
22
{
23
    use SetupClassResourcesTrait;
24

25
    /**
26
     * @return class-string[]
27
     */
28
    public static function getResources(): array
29
    {
NEW
30
        return [Error::class];
×
31
    }
32

33
    #[DataProvider('formatsProvider')]
34
    public function testRetrieveError(string $format, string $status, $expected): void
35
    {
NEW
36
        self::createClient()->request('GET', '/errors/'.$status, ['headers' => ['accept' => $format]]);
×
NEW
37
        $this->assertJsonContains($expected);
×
38
    }
39

40
    public function testRetrieveErrorHtml(): void
41
    {
NEW
42
        $response = self::createClient()->request('GET', '/errors/403', ['headers' => ['accept' => 'text/html']]);
×
NEW
43
        $this->assertEquals('<!DOCTYPE html>
×
44
<html>
45
<head>
46
  <meta charset="UTF-8" />
47
  <title>Error 403</title>
48
    </head>
49
    <body><h1>Error 403</h1>Forbidden</body>
NEW
50
</html>', $response->getContent());
×
51
    }
52

53
    public static function formatsProvider(): array
54
    {
NEW
55
        return [
×
NEW
56
            [
×
NEW
57
                'application/vnd.api+json',
×
NEW
58
                '401',
×
NEW
59
                [
×
NEW
60
                    'errors' => [['id' => '/errors/401', 'detail' => 'Unauthorized']],
×
NEW
61
                ],
×
NEW
62
            ],
×
NEW
63
            [
×
NEW
64
                'application/ld+json',
×
NEW
65
                '401',
×
NEW
66
                [
×
NEW
67
                    '@type' => 'hydra:Error',
×
NEW
68
                    'description' => 'Unauthorized',
×
NEW
69
                ],
×
NEW
70
            ],
×
NEW
71
            [
×
NEW
72
                'application/json',
×
NEW
73
                '401',
×
NEW
74
                [
×
NEW
75
                    'detail' => 'Unauthorized',
×
NEW
76
                ],
×
NEW
77
            ],
×
NEW
78
        ];
×
79
    }
80
}
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