|
21 | 21 | use Prophecy\Argument;
|
22 | 22 | use Prophecy\PhpUnit\ProphecyTrait;
|
23 | 23 | use Symfony\Component\HttpFoundation\Request;
|
| 24 | +use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; |
24 | 25 |
|
25 | 26 | class ContentNegotiationProviderTest extends TestCase
|
26 | 27 | {
|
@@ -60,4 +61,65 @@ public function testRequestWithEmptyContentType(): void
|
60 | 61 |
|
61 | 62 | $this->assertSame($expectedResult, $result);
|
62 | 63 | }
|
| 64 | + |
| 65 | + public function testRequestWhenNoInput(): void |
| 66 | + { |
| 67 | + $expectedResult = new \stdClass(); |
| 68 | + |
| 69 | + $decorated = $this->prophesize(ProviderInterface::class); |
| 70 | + $decorated->provide(Argument::cetera())->willReturn($expectedResult); |
| 71 | + |
| 72 | + $negotiator = new Negotiator(); |
| 73 | + $formats = ['jsonld' => ['application/ld+json']]; |
| 74 | + $errorFormats = ['jsonld' => ['application/ld+json']]; |
| 75 | + |
| 76 | + $provider = new ContentNegotiationProvider($decorated->reveal(), $negotiator, $formats, $errorFormats); |
| 77 | + |
| 78 | + $request = new Request( |
| 79 | + server: [ |
| 80 | + 'REQUEST_METHOD' => 'POST', |
| 81 | + 'REQUEST_URI' => '/', |
| 82 | + 'CONTENT_TYPE' => 'some-not-supported/content-type', |
| 83 | + ], |
| 84 | + content: '' |
| 85 | + ); |
| 86 | + |
| 87 | + $operation = new Post(); |
| 88 | + $operation = $operation->withDeserialize(false); |
| 89 | + $context = ['request' => $request]; |
| 90 | + |
| 91 | + $result = $provider->provide($operation, [], $context); |
| 92 | + |
| 93 | + $this->assertSame($expectedResult, $result); |
| 94 | + } |
| 95 | + |
| 96 | + public function testRequestWithInput(): void |
| 97 | + { |
| 98 | + $this->expectException(UnsupportedMediaTypeHttpException::class); |
| 99 | + |
| 100 | + $decorated = $this->prophesize(ProviderInterface::class); |
| 101 | + |
| 102 | + $negotiator = new Negotiator(); |
| 103 | + $formats = ['jsonld' => ['application/ld+json']]; |
| 104 | + $errorFormats = ['jsonld' => ['application/ld+json']]; |
| 105 | + |
| 106 | + $provider = new ContentNegotiationProvider($decorated->reveal(), $negotiator, $formats, $errorFormats); |
| 107 | + |
| 108 | + $request = new Request( |
| 109 | + server: [ |
| 110 | + 'REQUEST_METHOD' => 'POST', |
| 111 | + 'REQUEST_URI' => '/', |
| 112 | + 'CONTENT_TYPE' => 'some-not-supported/content-type', |
| 113 | + ], |
| 114 | + content: '' |
| 115 | + ); |
| 116 | + |
| 117 | + $operation = new Post(); |
| 118 | + $operation = $operation->withDeserialize(); |
| 119 | + $context = ['request' => $request]; |
| 120 | + |
| 121 | + $result = $provider->provide($operation, [], $context); |
| 122 | + |
| 123 | + $this->assertSame($expectedResult, $result); |
| 124 | + } |
63 | 125 | }
|
0 commit comments