|
25 | 25 | /**
|
26 | 26 | * @author Kévin Dunglas <[email protected]>
|
27 | 27 | * @author Antonio J. García Lagar <[email protected]>
|
| 28 | + * @author Aurélien Pillevesse <[email protected]> |
28 | 29 | */
|
29 | 30 | class PsrHttpFactoryTest extends TestCase
|
30 | 31 | {
|
@@ -243,4 +244,52 @@ public function testUploadErrNoFile()
|
243 | 244 | $this->assertSame(\UPLOAD_ERR_NO_FILE, $uploadedFiles['f1']->getError());
|
244 | 245 | $this->assertSame(\UPLOAD_ERR_NO_FILE, $uploadedFiles['f2']->getError());
|
245 | 246 | }
|
| 247 | + |
| 248 | + public function testJsonContent() |
| 249 | + { |
| 250 | + if (!method_exists(Request::class, 'getPayload')) { |
| 251 | + $this->markTestSkipped(); |
| 252 | + } |
| 253 | + |
| 254 | + $headers = [ |
| 255 | + 'HTTP_HOST' => 'http_host.fr', |
| 256 | + 'CONTENT_TYPE' => 'application/json', |
| 257 | + ]; |
| 258 | + $request = new Request([], [], [], [], [], $headers, '{"city":"Paris","country":"France"}'); |
| 259 | + $psrRequest = $this->factory->createRequest($request); |
| 260 | + |
| 261 | + $this->assertSame(['city' => 'Paris', 'country' => 'France'], $psrRequest->getParsedBody()); |
| 262 | + } |
| 263 | + |
| 264 | + public function testEmptyJsonContent() |
| 265 | + { |
| 266 | + if (!method_exists(Request::class, 'getPayload')) { |
| 267 | + $this->markTestSkipped(); |
| 268 | + } |
| 269 | + |
| 270 | + $headers = [ |
| 271 | + 'HTTP_HOST' => 'http_host.fr', |
| 272 | + 'CONTENT_TYPE' => 'application/json', |
| 273 | + ]; |
| 274 | + $request = new Request([], [], [], [], [], $headers, '{}'); |
| 275 | + $psrRequest = $this->factory->createRequest($request); |
| 276 | + |
| 277 | + $this->assertSame([], $psrRequest->getParsedBody()); |
| 278 | + } |
| 279 | + |
| 280 | + public function testWrongJsonContent() |
| 281 | + { |
| 282 | + if (!method_exists(Request::class, 'getPayload')) { |
| 283 | + $this->markTestSkipped(); |
| 284 | + } |
| 285 | + |
| 286 | + $headers = [ |
| 287 | + 'HTTP_HOST' => 'http_host.fr', |
| 288 | + 'CONTENT_TYPE' => 'application/json', |
| 289 | + ]; |
| 290 | + $request = new Request([], [], [], [], [], $headers, '{"city":"Paris"'); |
| 291 | + $psrRequest = $this->factory->createRequest($request); |
| 292 | + |
| 293 | + $this->assertSame([], $psrRequest->getParsedBody()); |
| 294 | + } |
246 | 295 | }
|
0 commit comments