1
1
<?php
2
2
3
- namespace ICanBoogie \HTTP ;
3
+ namespace Test \ ICanBoogie \HTTP ;
4
4
5
5
use ICanBoogie \DateTime ;
6
+ use ICanBoogie \HTTP \FileResponse ;
7
+ use ICanBoogie \HTTP \Headers ;
8
+ use ICanBoogie \HTTP \Request ;
9
+ use ICanBoogie \HTTP \RequestMethod ;
10
+ use ICanBoogie \HTTP \RequestOptions ;
11
+ use ICanBoogie \HTTP \RequestRange ;
12
+ use ICanBoogie \HTTP \ResponseStatus ;
6
13
use LogicException ;
7
14
use PHPUnit \Framework \Attributes \DataProvider ;
8
15
use PHPUnit \Framework \MockObject \Rule \InvokedCount ;
@@ -36,7 +43,7 @@ public function test_closure_body(int $status, \Closure $expected_provider)
36
43
37
44
$ response = $ this
38
45
->getMockBuilder (FileResponse::class)
39
- ->setConstructorArgs ([ __FILE__ , Request::from ()])
46
+ ->setConstructorArgs ([ __FILE__ , Request::from () ])
40
47
->onlyMethods ([ 'send_file ' , 'send_headers ' ])
41
48
->getMock ();
42
49
$ response
@@ -93,8 +100,13 @@ public function test_invoke(string $cache_control, bool $is_modified, int $expec
93
100
}
94
101
95
102
#[DataProvider('provide_test_invoke_with_range ' )]
96
- public function test_invoke_with_range (string $ cache_control , bool $ is_modified , bool $ is_satisfiable , bool $ is_total , int $ expected )
97
- {
103
+ public function test_invoke_with_range (
104
+ string $ cache_control ,
105
+ bool $ is_modified ,
106
+ bool $ is_satisfiable ,
107
+ bool $ is_total ,
108
+ int $ expected
109
+ ): void {
98
110
$ headers = new Headers ();
99
111
$ headers ['If-Range ' ] = $ etag = "123 " ;
100
112
@@ -171,22 +183,26 @@ public function test_send_body(): void
171
183
}
172
184
173
185
#[DataProvider('provide_test_get_content_type ' )]
174
- public function test_get_content_type (string $ expected , string $ file , array $ options = [], array $ headers = [])
175
- {
186
+ public function test_get_content_type (
187
+ string $ expected ,
188
+ string $ file ,
189
+ array $ options = [],
190
+ array $ headers = []
191
+ ): void {
176
192
$ response = new FileResponse ($ file , Request::from (), $ options , $ headers );
177
- $ this ->assertEquals ($ expected , (string ) $ response ->headers ->content_type );
193
+ $ this ->assertEquals ($ expected , (string )$ response ->headers ->content_type );
178
194
}
179
195
180
196
public static function provide_test_get_content_type (): array
181
197
{
182
198
return [
183
199
184
200
[ 'application/octet-stream ' , create_file () ],
185
- [ 'text/plain ' , create_file (), [ FileResponse::OPTION_MIME => 'text/plain ' ] ],
186
- [ 'text/plain ' , create_file (), [], [ 'Content-Type ' => 'text/plain ' ] ],
201
+ [ 'text/plain ' , create_file (), [ FileResponse::OPTION_MIME => 'text/plain ' ] ],
202
+ [ 'text/plain ' , create_file (), [], [ 'Content-Type ' => 'text/plain ' ] ],
187
203
[ 'image/png ' , create_image ('.png ' ) ],
188
- [ 'text/plain ' , create_image ('.png ' ), [ FileResponse::OPTION_MIME => 'text/plain ' ] ],
189
- [ 'text/plain ' , create_image ('.png ' ), [], [ 'Content-Type ' => 'text/plain ' ] ],
204
+ [ 'text/plain ' , create_image ('.png ' ), [ FileResponse::OPTION_MIME => 'text/plain ' ] ],
205
+ [ 'text/plain ' , create_image ('.png ' ), [], [ 'Content-Type ' => 'text/plain ' ] ],
190
206
191
207
];
192
208
}
@@ -208,7 +224,7 @@ public static function provide_test_get_etag(): array
208
224
209
225
[ $ file_hash , $ file ],
210
226
[ $ file_hash_custom , $ file , [ FileResponse::OPTION_ETAG => $ file_hash_custom ] ],
211
- [ $ file_hash_custom , $ file , [ ], [ 'ETag ' => $ file_hash_custom ] ],
227
+ [ $ file_hash_custom , $ file , [], [ 'ETag ' => $ file_hash_custom ] ],
212
228
213
229
];
214
230
}
@@ -232,8 +248,8 @@ public static function provide_test_get_expires(): array
232
248
[ $ expires_default , $ file ],
233
249
[ $ expires2 , $ file , [ FileResponse::OPTION_EXPIRES => $ expires2_str ] ],
234
250
[ $ expires2 , $ file , [ FileResponse::OPTION_EXPIRES => $ expires2 ] ],
235
- [ $ expires2 , $ file , [ ], [ 'Expires ' => $ expires2_str ] ],
236
- [ $ expires2 , $ file , [ ], [ 'Expires ' => $ expires2 ] ],
251
+ [ $ expires2 , $ file , [], [ 'Expires ' => $ expires2_str ] ],
252
+ [ $ expires2 , $ file , [], [ 'Expires ' => $ expires2 ] ],
237
253
238
254
];
239
255
}
@@ -273,13 +289,31 @@ public static function provide_test_get_is_modified(): array
273
289
274
290
return [
275
291
276
- [ true , [ ] ],
277
- [ true , [ 'If-Modified-Since ' => (string ) $ modified_since ] ],
278
- [ true , [ 'If-Modified-Since ' => (string ) $ modified_since ], $ modified_time_older ],
279
- [ true , [ 'If-Modified-Since ' => (string ) $ modified_since , 'If-None-Match ' => uniqid () ], $ modified_time_older ],
280
- [ true , [ 'If-Modified-Since ' => (string ) $ modified_since , 'If-None-Match ' => uniqid () ], $ modified_time_older ],
281
- [ true , [ 'If-Modified-Since ' => (string ) $ modified_since , 'If-None-Match ' => $ etag ], $ modified_time_newer , $ etag ],
282
- [ false , [ 'If-Modified-Since ' => (string ) $ modified_since , 'If-None-Match ' => $ etag ], $ modified_time_older , $ etag ],
292
+ [ true , [] ],
293
+ [ true , [ 'If-Modified-Since ' => (string )$ modified_since ] ],
294
+ [ true , [ 'If-Modified-Since ' => (string )$ modified_since ], $ modified_time_older ],
295
+ [
296
+ true ,
297
+ [ 'If-Modified-Since ' => (string )$ modified_since , 'If-None-Match ' => uniqid () ],
298
+ $ modified_time_older
299
+ ],
300
+ [
301
+ true ,
302
+ [ 'If-Modified-Since ' => (string )$ modified_since , 'If-None-Match ' => uniqid () ],
303
+ $ modified_time_older
304
+ ],
305
+ [
306
+ true ,
307
+ [ 'If-Modified-Since ' => (string )$ modified_since , 'If-None-Match ' => $ etag ],
308
+ $ modified_time_newer ,
309
+ $ etag
310
+ ],
311
+ [
312
+ false ,
313
+ [ 'If-Modified-Since ' => (string )$ modified_since , 'If-None-Match ' => $ etag ],
314
+ $ modified_time_older ,
315
+ $ etag
316
+ ],
283
317
284
318
];
285
319
}
@@ -289,13 +323,13 @@ public function test_filename(string $file, string|bool $filename, string $expec
289
323
{
290
324
$ response = new FileResponse ($ file , Request::from (), [ FileResponse::OPTION_FILENAME => $ filename ]);
291
325
292
- $ this ->assertEquals ('binary ' , (string ) $ response ->headers ['Content-Transfer-Encoding ' ]);
293
- $ this ->assertEquals ('File Transfer ' , (string ) $ response ->headers ['Content-Description ' ]);
326
+ $ this ->assertEquals ('binary ' , (string )$ response ->headers ['Content-Transfer-Encoding ' ]);
327
+ $ this ->assertEquals ('File Transfer ' , (string )$ response ->headers ['Content-Description ' ]);
294
328
$ this ->assertEquals ('attachment ' , $ response ->headers ->content_disposition ->type );
295
329
$ this ->assertEquals ($ expected , $ response ->headers ->content_disposition ->filename );
296
330
}
297
331
298
- public static function provide_test_filename ()
332
+ public static function provide_test_filename (): array
299
333
{
300
334
$ file = create_file ();
301
335
$ filename = "Filename " . uniqid () . ".png " ;
@@ -309,7 +343,7 @@ public static function provide_test_filename()
309
343
}
310
344
311
345
#[DataProvider('provide_test_accept_ranges ' )]
312
- public function test_accept_ranges (RequestMethod $ method , string $ type )
346
+ public function test_accept_ranges (RequestMethod $ method , string $ type ): void
313
347
{
314
348
$ request = Request::from ([ Request::OPTION_URI => '/ ' , 'method ' => $ method ]);
315
349
@@ -321,10 +355,10 @@ public function test_accept_ranges(RequestMethod $method, string $type)
321
355
322
356
/* @var $response FileResponse */
323
357
324
- $ this ->assertStringContainsString ("Accept-Ranges: $ type " , (string ) $ response );
358
+ $ this ->assertStringContainsString ("Accept-Ranges: $ type " , (string )$ response );
325
359
}
326
360
327
- public static function provide_test_accept_ranges ()
361
+ public static function provide_test_accept_ranges (): array
328
362
{
329
363
return [
330
364
@@ -337,7 +371,7 @@ public static function provide_test_accept_ranges()
337
371
}
338
372
339
373
#[DataProvider('provide_test_range_response ' )]
340
- public function test_range_response (string $ bytes , string $ pathname , string $ expected )
374
+ public function test_range_response (string $ bytes , string $ pathname , string $ expected ): void
341
375
{
342
376
$ etag = sha1_file ($ pathname );
343
377
@@ -369,7 +403,7 @@ public function test_range_response(string $bytes, string $pathname, string $exp
369
403
$ this ->assertSame ($ expected , $ content );
370
404
}
371
405
372
- public static function provide_test_range_response ()
406
+ public static function provide_test_range_response (): array
373
407
{
374
408
$ pathname = create_file ();
375
409
$ data = file_get_contents ($ pathname );
0 commit comments