23
23
*/
24
24
final class CorsTest extends CIUnitTestCase
25
25
{
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
+ */
26
37
private function createCors (array $ config = []): Cors
27
38
{
28
39
return new Cors ($ config );
@@ -33,6 +44,9 @@ private function createRequest(): IncomingRequest
33
44
return Services::incomingrequest (null , false );
34
45
}
35
46
47
+ /**
48
+ * @return array<string, mixed>
49
+ */
36
50
private function getDefaultConfig (): array
37
51
{
38
52
return [
@@ -50,14 +64,14 @@ private function assertHeader(ResponseInterface $response, string $name, string
50
64
$ this ->assertSame ($ value , $ response ->getHeaderLine ($ name ));
51
65
}
52
66
53
- public function testInstantiate ()
67
+ public function testInstantiate (): void
54
68
{
55
69
$ cors = $ this ->createCors ();
56
70
57
71
$ this ->assertInstanceOf (Cors::class, $ cors );
58
72
}
59
73
60
- public function testIsPreflightRequestTrue ()
74
+ public function testIsPreflightRequestTrue (): void
61
75
{
62
76
$ cors = $ this ->createCors ();
63
77
@@ -68,7 +82,7 @@ public function testIsPreflightRequestTrue()
68
82
$ this ->assertTrue ($ cors ->isPreflightRequest ($ request ));
69
83
}
70
84
71
- public function testIsPreflightRequestFalse ()
85
+ public function testIsPreflightRequestFalse (): void
72
86
{
73
87
$ cors = $ this ->createCors ();
74
88
@@ -78,7 +92,7 @@ public function testIsPreflightRequestFalse()
78
92
$ this ->assertFalse ($ cors ->isPreflightRequest ($ request ));
79
93
}
80
94
81
- public function testHandlePreflightRequestSingleAllowedOrigin ()
95
+ public function testHandlePreflightRequestSingleAllowedOrigin (): void
82
96
{
83
97
$ config = $ this ->getDefaultConfig ();
84
98
$ config ['allowedOrigins ' ] = ['http://localhost:8080 ' ];
@@ -113,7 +127,7 @@ public function testHandlePreflightRequestSingleAllowedOrigin()
113
127
);
114
128
}
115
129
116
- public function testHandlePreflightRequestMultipleAllowedOriginsAllowed ()
130
+ public function testHandlePreflightRequestMultipleAllowedOriginsAllowed (): void
117
131
{
118
132
$ config = $ this ->getDefaultConfig ();
119
133
$ config ['allowedOrigins ' ] = ['https://example.com ' , 'https://api.example.com ' ];
@@ -150,7 +164,7 @@ public function testHandlePreflightRequestMultipleAllowedOriginsAllowed()
150
164
);
151
165
}
152
166
153
- public function testHandlePreflightRequestMultipleAllowedOriginsAllowedAlreadyVary ()
167
+ public function testHandlePreflightRequestMultipleAllowedOriginsAllowedAlreadyVary (): void
154
168
{
155
169
$ config = $ this ->getDefaultConfig ();
156
170
$ config ['allowedOrigins ' ] = ['https://example.com ' , 'https://api.example.com ' ];
@@ -188,7 +202,7 @@ public function testHandlePreflightRequestMultipleAllowedOriginsAllowedAlreadyVa
188
202
);
189
203
}
190
204
191
- public function testHandlePreflightRequestMultipleAllowedOriginsNotAllowed ()
205
+ public function testHandlePreflightRequestMultipleAllowedOriginsNotAllowed (): void
192
206
{
193
207
$ config = $ this ->getDefaultConfig ();
194
208
$ config ['allowedOrigins ' ] = ['https://example.com ' , 'https://api.example.com ' ];
@@ -214,7 +228,7 @@ public function testHandlePreflightRequestMultipleAllowedOriginsNotAllowed()
214
228
);
215
229
}
216
230
217
- public function testHandlePreflightRequestAllowedOriginsPatternsAllowed ()
231
+ public function testHandlePreflightRequestAllowedOriginsPatternsAllowed (): void
218
232
{
219
233
$ config = $ this ->getDefaultConfig ();
220
234
$ config ['allowedOriginsPatterns ' ] = ['https://\w+\.example\.com ' ];
@@ -251,7 +265,7 @@ public function testHandlePreflightRequestAllowedOriginsPatternsAllowed()
251
265
);
252
266
}
253
267
254
- public function testHandlePreflightRequestAllowedOriginsPatternsNotAllowed ()
268
+ public function testHandlePreflightRequestAllowedOriginsPatternsNotAllowed (): void
255
269
{
256
270
$ config = $ this ->getDefaultConfig ();
257
271
$ config ['allowedOriginsPatterns ' ] = ['https://\w+\.example\.com ' ];
@@ -277,7 +291,7 @@ public function testHandlePreflightRequestAllowedOriginsPatternsNotAllowed()
277
291
);
278
292
}
279
293
280
- public function testHandlePreflightRequestSingleAllowedOriginWithCredentials ()
294
+ public function testHandlePreflightRequestSingleAllowedOriginWithCredentials (): void
281
295
{
282
296
$ config = $ this ->getDefaultConfig ();
283
297
$ config ['allowedOrigins ' ] = ['http://localhost:8080 ' ];
@@ -315,7 +329,7 @@ public function testHandlePreflightRequestSingleAllowedOriginWithCredentials()
315
329
);
316
330
}
317
331
318
- public function testAddResponseHeadersSingleAllowedOriginSimpleRequest ()
332
+ public function testAddResponseHeadersSingleAllowedOriginSimpleRequest (): void
319
333
{
320
334
$ config = $ this ->getDefaultConfig ();
321
335
$ config ['allowedOrigins ' ] = ['http://localhost:8080 ' ];
@@ -346,7 +360,7 @@ public function testAddResponseHeadersSingleAllowedOriginSimpleRequest()
346
360
);
347
361
}
348
362
349
- public function testAddResponseHeadersSingleAllowedOriginRealRequest ()
363
+ public function testAddResponseHeadersSingleAllowedOriginRealRequest (): void
350
364
{
351
365
$ config = $ this ->getDefaultConfig ();
352
366
$ config ['allowedOrigins ' ] = ['http://localhost:8080 ' ];
@@ -368,7 +382,7 @@ public function testAddResponseHeadersSingleAllowedOriginRealRequest()
368
382
);
369
383
}
370
384
371
- public function testAddResponseHeadersSingleAllowedOriginWithCredentials ()
385
+ public function testAddResponseHeadersSingleAllowedOriginWithCredentials (): void
372
386
{
373
387
$ config = $ this ->getDefaultConfig ();
374
388
$ config ['allowedOrigins ' ] = ['http://localhost:8080 ' ];
@@ -397,7 +411,7 @@ public function testAddResponseHeadersSingleAllowedOriginWithCredentials()
397
411
);
398
412
}
399
413
400
- public function testAddResponseHeadersSingleAllowedOriginWithExposeHeaders ()
414
+ public function testAddResponseHeadersSingleAllowedOriginWithExposeHeaders (): void
401
415
{
402
416
$ config = $ this ->getDefaultConfig ();
403
417
$ config ['allowedOrigins ' ] = ['http://localhost:8080 ' ];
@@ -425,7 +439,7 @@ public function testAddResponseHeadersSingleAllowedOriginWithExposeHeaders()
425
439
);
426
440
}
427
441
428
- public function testAddResponseHeadersMultipleAllowedOriginsAllowed ()
442
+ public function testAddResponseHeadersMultipleAllowedOriginsAllowed (): void
429
443
{
430
444
$ config = $ this ->getDefaultConfig ();
431
445
$ config ['allowedOrigins ' ] = ['https://example.com ' , 'https://api.example.com ' ];
@@ -457,7 +471,7 @@ public function testAddResponseHeadersMultipleAllowedOriginsAllowed()
457
471
);
458
472
}
459
473
460
- public function testAddResponseHeadersMultipleAllowedOriginsAllowedAlreadyVary ()
474
+ public function testAddResponseHeadersMultipleAllowedOriginsAllowedAlreadyVary (): void
461
475
{
462
476
$ config = $ this ->getDefaultConfig ();
463
477
$ config ['allowedOrigins ' ] = ['https://example.com ' , 'https://api.example.com ' ];
@@ -484,7 +498,7 @@ public function testAddResponseHeadersMultipleAllowedOriginsAllowedAlreadyVary()
484
498
);
485
499
}
486
500
487
- public function testAddResponseHeadersMultipleAllowedOriginsNotAllowed ()
501
+ public function testAddResponseHeadersMultipleAllowedOriginsNotAllowed (): void
488
502
{
489
503
$ config = $ this ->getDefaultConfig ();
490
504
$ config ['allowedOrigins ' ] = ['https://example.com ' , 'https://api.example.com ' ];
0 commit comments