• 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/State/Provider/ContentNegotiationProviderTest.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\State\Provider;
15

16
use ApiPlatform\Metadata\Post;
17
use ApiPlatform\State\Provider\ContentNegotiationProvider;
18
use ApiPlatform\State\ProviderInterface;
19
use Negotiation\Negotiator;
20
use PHPUnit\Framework\TestCase;
21
use Prophecy\Argument;
22
use Prophecy\PhpUnit\ProphecyTrait;
23
use Symfony\Component\HttpFoundation\Request;
24
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
25

26
class ContentNegotiationProviderTest extends TestCase
27
{
28
    use ProphecyTrait;
29

30
    public function testRequestWithEmptyContentType(): void
31
    {
UNCOV
32
        $expectedResult = new \stdClass();
×
33

34
        $decorated = $this->prophesize(ProviderInterface::class);
×
UNCOV
35
        $decorated->provide(Argument::cetera())->willReturn($expectedResult);
×
36

37
        $negotiator = new Negotiator();
×
38
        $formats = ['jsonld' => ['application/ld+json']];
×
UNCOV
39
        $errorFormats = ['jsonld' => ['application/ld+json']];
×
40

UNCOV
41
        $provider = new ContentNegotiationProvider($decorated->reveal(), $negotiator, $formats, $errorFormats);
×
42

43
        // in Symfony (at least up to 7.0.2, 6.4.2, 6.3.11, 5.4.34), a request
44
        // without a content-type and content-length header will result in the
45
        // variables set to an empty string, not null
46

47
        $request = new Request(
×
48
            server: [
×
49
                'REQUEST_METHOD' => 'POST',
×
50
                'REQUEST_URI' => '/',
×
51
                'CONTENT_TYPE' => '',
×
52
                'CONTENT_LENGTH' => '',
×
53
            ],
×
54
            content: ''
×
UNCOV
55
        );
×
56

57
        $operation = new Post();
×
UNCOV
58
        $context = ['request' => $request];
×
59

UNCOV
60
        $result = $provider->provide($operation, [], $context);
×
61

UNCOV
62
        $this->assertSame($expectedResult, $result);
×
63
    }
64

65
    public function testRequestWhenNoInput(): void
66
    {
UNCOV
67
        $expectedResult = new \stdClass();
×
68

UNCOV
69
        $decorated = $this->prophesize(ProviderInterface::class);
×
UNCOV
70
        $decorated->provide(Argument::cetera())->willReturn($expectedResult);
×
71

UNCOV
72
        $negotiator = new Negotiator();
×
UNCOV
73
        $formats = ['jsonld' => ['application/ld+json']];
×
UNCOV
74
        $errorFormats = ['jsonld' => ['application/ld+json']];
×
75

UNCOV
76
        $provider = new ContentNegotiationProvider($decorated->reveal(), $negotiator, $formats, $errorFormats);
×
77

UNCOV
78
        $request = new Request(
×
UNCOV
79
            server: [
×
UNCOV
80
                'REQUEST_METHOD' => 'POST',
×
UNCOV
81
                'REQUEST_URI' => '/',
×
UNCOV
82
                'CONTENT_TYPE' => 'some-not-supported/content-type',
×
UNCOV
83
            ],
×
UNCOV
84
            content: ''
×
UNCOV
85
        );
×
86

UNCOV
87
        $operation = new Post();
×
UNCOV
88
        $operation = $operation->withDeserialize(false);
×
UNCOV
89
        $context = ['request' => $request];
×
90

UNCOV
91
        $result = $provider->provide($operation, [], $context);
×
92

UNCOV
93
        $this->assertSame($expectedResult, $result);
×
94
    }
95

96
    public function testRequestWithInput(): void
97
    {
UNCOV
98
        $this->expectException(UnsupportedMediaTypeHttpException::class);
×
99

UNCOV
100
        $decorated = $this->prophesize(ProviderInterface::class);
×
101

UNCOV
102
        $negotiator = new Negotiator();
×
UNCOV
103
        $formats = ['jsonld' => ['application/ld+json']];
×
UNCOV
104
        $errorFormats = ['jsonld' => ['application/ld+json']];
×
105

UNCOV
106
        $provider = new ContentNegotiationProvider($decorated->reveal(), $negotiator, $formats, $errorFormats);
×
107

UNCOV
108
        $request = new Request(
×
UNCOV
109
            server: [
×
UNCOV
110
                'REQUEST_METHOD' => 'POST',
×
UNCOV
111
                'REQUEST_URI' => '/',
×
UNCOV
112
                'CONTENT_TYPE' => 'some-not-supported/content-type',
×
UNCOV
113
            ],
×
UNCOV
114
            content: ''
×
UNCOV
115
        );
×
116

UNCOV
117
        $operation = new Post();
×
UNCOV
118
        $operation = $operation->withDeserialize();
×
UNCOV
119
        $context = ['request' => $request];
×
120

UNCOV
121
        $provider->provide($operation, [], $context);
×
122
    }
123
}
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