-
-
Notifications
You must be signed in to change notification settings - Fork 963
Expand file tree
/
Copy pathResponseHeaderParameterTest.php
More file actions
77 lines (63 loc) · 2.84 KB
/
ResponseHeaderParameterTest.php
File metadata and controls
77 lines (63 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Tests\Functional\Parameters;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use ApiPlatform\Tests\Fixtures\TestBundle\ApiResource\WithResponseHeaderParameter;
use ApiPlatform\Tests\SetupClassResourcesTrait;
final class ResponseHeaderParameterTest extends ApiTestCase
{
use SetupClassResourcesTrait;
protected static ?bool $alwaysBootKernel = false;
/**
* @return class-string[]
*/
public static function getResources(): array
{
return [WithResponseHeaderParameter::class];
}
public function testResponseHeadersAreSet(): void
{
self::createClient()->request('GET', 'with_response_headers/1');
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('ratelimit-limit', '100');
$this->assertResponseHeaderSame('ratelimit-remaining', '99');
}
public function testProcessorSetsResponseHeaders(): void
{
self::createClient()->request('POST', 'with_response_headers', [
'headers' => ['Content-Type' => 'application/ld+json'],
'json' => ['id' => '3', 'name' => 'test'],
]);
$this->assertResponseIsSuccessful();
$this->assertResponseHeaderSame('ratelimit-limit', '50');
$this->assertResponseHeaderSame('ratelimit-remaining', '49');
}
public function testOpenApiDocumentsResponseHeaders(): void
{
$response = self::createClient()->request('GET', 'docs', ['headers' => ['Accept' => 'application/vnd.openapi+json']]);
$this->assertResponseIsSuccessful();
$json = $response->toArray();
$itemPath = $json['paths']['/with_response_headers/{id}']['get'];
$this->assertArrayHasKey('responses', $itemPath);
$successResponse = $itemPath['responses']['200'] ?? $itemPath['responses'][200] ?? null;
$this->assertNotNull($successResponse);
$this->assertArrayHasKey('headers', $successResponse);
$this->assertArrayHasKey('RateLimit-Limit', $successResponse['headers']);
$this->assertArrayHasKey('RateLimit-Remaining', $successResponse['headers']);
$this->assertSame('integer', $successResponse['headers']['RateLimit-Limit']['schema']['type']);
$this->assertSame('Maximum number of requests per window', $successResponse['headers']['RateLimit-Limit']['description']);
// Verify headers are NOT in request parameters
foreach ($itemPath['parameters'] ?? [] as $parameter) {
$this->assertNotSame('RateLimit-Limit', $parameter['name']);
$this->assertNotSame('RateLimit-Remaining', $parameter['name']);
}
}
}