Skip to content

Commit 84855d6

Browse files
committed
test: add types
1 parent d52f07b commit 84855d6

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

tests/system/Filters/CorsTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CodeIgniter\Exceptions\ConfigException;
1717
use CodeIgniter\HTTP\CLIRequest;
1818
use CodeIgniter\HTTP\IncomingRequest;
19+
use CodeIgniter\HTTP\RequestInterface;
1920
use CodeIgniter\HTTP\ResponseInterface;
2021
use CodeIgniter\HTTP\SiteURI;
2122
use CodeIgniter\HTTP\UserAgent;
@@ -75,6 +76,9 @@ private function createValidActualRequest(): IncomingRequest
7576
return $request;
7677
}
7778

79+
/**
80+
* @param array<string, mixed> $options
81+
*/
7882
private function createCors(array $options = []): Cors
7983
{
8084
$passedOptions = array_merge(
@@ -132,7 +136,7 @@ public function testItDoesNotModifyOnARequestWithoutOrigin(): void
132136
$this->assertFalse($response->hasHeader('Access-Control-Allow-Origin'));
133137
}
134138

135-
private function handle($request): ResponseInterface
139+
private function handle(RequestInterface $request): ResponseInterface
136140
{
137141
$response = $this->cors->before($request);
138142
if ($response instanceof ResponseInterface) {
@@ -215,7 +219,7 @@ public function testItDoesntPermitWildcardAllowedHeadersAndSupportsCredentials()
215219
$this->handle($request);
216220
}
217221

218-
public function testItSetsAllowCredentialsHeaderWhenFlagIsSetOnValidActualRequest()
222+
public function testItSetsAllowCredentialsHeaderWhenFlagIsSetOnValidActualRequest(): void
219223
{
220224
$this->cors = $this->createCors(['supportsCredentials' => true]);
221225
$request = $this->createValidActualRequest();

tests/system/HTTP/CorsTest.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@
2323
*/
2424
final class CorsTest extends CIUnitTestCase
2525
{
26+
/**
27+
* @param array{
28+
* allowedOrigins?: list<string>,
29+
* allowedOriginsPatterns?: list<string>,
30+
* supportsCredentials?: bool,
31+
* allowedHeaders?: list<string>,
32+
* exposedHeaders?: list<string>,
33+
* allowedMethods?: list<string>,
34+
* maxAge?: int,
35+
* } $config
36+
*/
2637
private function createCors(array $config = []): Cors
2738
{
2839
return new Cors($config);
@@ -33,6 +44,9 @@ private function createRequest(): IncomingRequest
3344
return Services::incomingrequest(null, false);
3445
}
3546

47+
/**
48+
* @return array<string, mixed>
49+
*/
3650
private function getDefaultConfig(): array
3751
{
3852
return [
@@ -50,14 +64,14 @@ private function assertHeader(ResponseInterface $response, string $name, string
5064
$this->assertSame($value, $response->getHeaderLine($name));
5165
}
5266

53-
public function testInstantiate()
67+
public function testInstantiate(): void
5468
{
5569
$cors = $this->createCors();
5670

5771
$this->assertInstanceOf(Cors::class, $cors);
5872
}
5973

60-
public function testIsPreflightRequestTrue()
74+
public function testIsPreflightRequestTrue(): void
6175
{
6276
$cors = $this->createCors();
6377

@@ -68,7 +82,7 @@ public function testIsPreflightRequestTrue()
6882
$this->assertTrue($cors->isPreflightRequest($request));
6983
}
7084

71-
public function testIsPreflightRequestFalse()
85+
public function testIsPreflightRequestFalse(): void
7286
{
7387
$cors = $this->createCors();
7488

@@ -78,7 +92,7 @@ public function testIsPreflightRequestFalse()
7892
$this->assertFalse($cors->isPreflightRequest($request));
7993
}
8094

81-
public function testHandlePreflightRequestSingleAllowedOrigin()
95+
public function testHandlePreflightRequestSingleAllowedOrigin(): void
8296
{
8397
$config = $this->getDefaultConfig();
8498
$config['allowedOrigins'] = ['http://localhost:8080'];
@@ -113,7 +127,7 @@ public function testHandlePreflightRequestSingleAllowedOrigin()
113127
);
114128
}
115129

116-
public function testHandlePreflightRequestMultipleAllowedOriginsAllowed()
130+
public function testHandlePreflightRequestMultipleAllowedOriginsAllowed(): void
117131
{
118132
$config = $this->getDefaultConfig();
119133
$config['allowedOrigins'] = ['https://example.com', 'https://api.example.com'];
@@ -150,7 +164,7 @@ public function testHandlePreflightRequestMultipleAllowedOriginsAllowed()
150164
);
151165
}
152166

153-
public function testHandlePreflightRequestMultipleAllowedOriginsAllowedAlreadyVary()
167+
public function testHandlePreflightRequestMultipleAllowedOriginsAllowedAlreadyVary(): void
154168
{
155169
$config = $this->getDefaultConfig();
156170
$config['allowedOrigins'] = ['https://example.com', 'https://api.example.com'];
@@ -188,7 +202,7 @@ public function testHandlePreflightRequestMultipleAllowedOriginsAllowedAlreadyVa
188202
);
189203
}
190204

191-
public function testHandlePreflightRequestMultipleAllowedOriginsNotAllowed()
205+
public function testHandlePreflightRequestMultipleAllowedOriginsNotAllowed(): void
192206
{
193207
$config = $this->getDefaultConfig();
194208
$config['allowedOrigins'] = ['https://example.com', 'https://api.example.com'];
@@ -214,7 +228,7 @@ public function testHandlePreflightRequestMultipleAllowedOriginsNotAllowed()
214228
);
215229
}
216230

217-
public function testHandlePreflightRequestAllowedOriginsPatternsAllowed()
231+
public function testHandlePreflightRequestAllowedOriginsPatternsAllowed(): void
218232
{
219233
$config = $this->getDefaultConfig();
220234
$config['allowedOriginsPatterns'] = ['https://\w+\.example\.com'];
@@ -251,7 +265,7 @@ public function testHandlePreflightRequestAllowedOriginsPatternsAllowed()
251265
);
252266
}
253267

254-
public function testHandlePreflightRequestAllowedOriginsPatternsNotAllowed()
268+
public function testHandlePreflightRequestAllowedOriginsPatternsNotAllowed(): void
255269
{
256270
$config = $this->getDefaultConfig();
257271
$config['allowedOriginsPatterns'] = ['https://\w+\.example\.com'];
@@ -277,7 +291,7 @@ public function testHandlePreflightRequestAllowedOriginsPatternsNotAllowed()
277291
);
278292
}
279293

280-
public function testHandlePreflightRequestSingleAllowedOriginWithCredentials()
294+
public function testHandlePreflightRequestSingleAllowedOriginWithCredentials(): void
281295
{
282296
$config = $this->getDefaultConfig();
283297
$config['allowedOrigins'] = ['http://localhost:8080'];
@@ -315,7 +329,7 @@ public function testHandlePreflightRequestSingleAllowedOriginWithCredentials()
315329
);
316330
}
317331

318-
public function testAddResponseHeadersSingleAllowedOriginSimpleRequest()
332+
public function testAddResponseHeadersSingleAllowedOriginSimpleRequest(): void
319333
{
320334
$config = $this->getDefaultConfig();
321335
$config['allowedOrigins'] = ['http://localhost:8080'];
@@ -346,7 +360,7 @@ public function testAddResponseHeadersSingleAllowedOriginSimpleRequest()
346360
);
347361
}
348362

349-
public function testAddResponseHeadersSingleAllowedOriginRealRequest()
363+
public function testAddResponseHeadersSingleAllowedOriginRealRequest(): void
350364
{
351365
$config = $this->getDefaultConfig();
352366
$config['allowedOrigins'] = ['http://localhost:8080'];
@@ -368,7 +382,7 @@ public function testAddResponseHeadersSingleAllowedOriginRealRequest()
368382
);
369383
}
370384

371-
public function testAddResponseHeadersSingleAllowedOriginWithCredentials()
385+
public function testAddResponseHeadersSingleAllowedOriginWithCredentials(): void
372386
{
373387
$config = $this->getDefaultConfig();
374388
$config['allowedOrigins'] = ['http://localhost:8080'];
@@ -397,7 +411,7 @@ public function testAddResponseHeadersSingleAllowedOriginWithCredentials()
397411
);
398412
}
399413

400-
public function testAddResponseHeadersSingleAllowedOriginWithExposeHeaders()
414+
public function testAddResponseHeadersSingleAllowedOriginWithExposeHeaders(): void
401415
{
402416
$config = $this->getDefaultConfig();
403417
$config['allowedOrigins'] = ['http://localhost:8080'];
@@ -425,7 +439,7 @@ public function testAddResponseHeadersSingleAllowedOriginWithExposeHeaders()
425439
);
426440
}
427441

428-
public function testAddResponseHeadersMultipleAllowedOriginsAllowed()
442+
public function testAddResponseHeadersMultipleAllowedOriginsAllowed(): void
429443
{
430444
$config = $this->getDefaultConfig();
431445
$config['allowedOrigins'] = ['https://example.com', 'https://api.example.com'];
@@ -457,7 +471,7 @@ public function testAddResponseHeadersMultipleAllowedOriginsAllowed()
457471
);
458472
}
459473

460-
public function testAddResponseHeadersMultipleAllowedOriginsAllowedAlreadyVary()
474+
public function testAddResponseHeadersMultipleAllowedOriginsAllowedAlreadyVary(): void
461475
{
462476
$config = $this->getDefaultConfig();
463477
$config['allowedOrigins'] = ['https://example.com', 'https://api.example.com'];
@@ -484,7 +498,7 @@ public function testAddResponseHeadersMultipleAllowedOriginsAllowedAlreadyVary()
484498
);
485499
}
486500

487-
public function testAddResponseHeadersMultipleAllowedOriginsNotAllowed()
501+
public function testAddResponseHeadersMultipleAllowedOriginsNotAllowed(): void
488502
{
489503
$config = $this->getDefaultConfig();
490504
$config['allowedOrigins'] = ['https://example.com', 'https://api.example.com'];

0 commit comments

Comments
 (0)