Skip to content

Commit a697ed2

Browse files
committed
Fix tests namespace
1 parent f3cb979 commit a697ed2

19 files changed

+179
-268
lines changed

lib/FileList.php

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
<?php
22

3-
/*
4-
* This file is part of the ICanBoogie package.
5-
*
6-
* (c) Olivier Laviale <[email protected]>
7-
*
8-
* For the full copyright and license information, please view the LICENSE
9-
* file that was distributed with this source code.
10-
*/
11-
123
namespace ICanBoogie\HTTP;
134

145
use ArrayAccess;
@@ -19,7 +10,7 @@
1910
use function count;
2011

2112
/**
22-
* Representation of a list of request files.
13+
* Represents a list of request files.
2314
*
2415
* @implements ArrayAccess<string, File>
2516
* @implements IteratorAggregate<string, File>

phpstan.neon

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ parameters:
22
level: 5
33
paths:
44
- lib
5+
scanFiles:
6+
- tests/bootstrap.php
57
ignoreErrors:
68
- "#.*get_.* is unused#"
79
- "#.*set_.* is unused#"

tests/FileInfoTest.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace ICanBoogie\HTTP;
12+
namespace Test\ICanBoogie\HTTP;
1313

14+
use ICanBoogie\HTTP\FileInfo;
1415
use PHPUnit\Framework\Attributes\DataProvider;
16+
use PHPUnit\Framework\TestCase;
1517

16-
class FileInfoTest extends \PHPUnit\Framework\TestCase
18+
class FileInfoTest extends TestCase
1719
{
1820
/**
1921
* @param $pathname
@@ -25,7 +27,7 @@ public function test_resolve_type($pathname, $expected)
2527
$this->assertEquals($expected, FileInfo::resolve_type($pathname));
2628
}
2729

28-
public static function provide_test_resolve_type()
30+
public static function provide_test_resolve_type(): array
2931
{
3032
$bytes = create_file();
3133

tests/FileListTest.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<?php
22

3-
namespace ICanBoogie\HTTP;
3+
namespace Test\ICanBoogie\HTTP;
44

5-
class FileListTest extends \PHPUnit\Framework\TestCase
5+
use ICanBoogie\HTTP\File;
6+
use ICanBoogie\HTTP\FileList;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class FileListTest extends TestCase
610
{
7-
public function test_from_self_should_return_clone()
11+
public function test_from_self_should_return_clone(): void
812
{
913
$files1 = new FileList();
1014
$files2 = FileList::from($files1);
@@ -13,13 +17,13 @@ public function test_from_self_should_return_clone()
1317
$this->assertNotSame($files1, $files2);
1418
}
1519

16-
public function test_should_return_null_if_offset_not_defined()
20+
public function test_should_return_null_if_offset_not_defined(): void
1721
{
1822
$files = new FileList();
1923
$this->assertNull($files['undefined']);
2024
}
2125

22-
public function test_should_create_instance_by_setting_offset()
26+
public function test_should_create_instance_by_setting_offset(): void
2327
{
2428
$files = new FileList();
2529
$files['one'] = [ 'pathname' => __FILE__ ];
@@ -28,7 +32,7 @@ public function test_should_create_instance_by_setting_offset()
2832
$this->assertEquals(__FILE__, $files['one']->pathname);
2933
}
3034

31-
public function test_should_remove_offset()
35+
public function test_should_remove_offset(): void
3236
{
3337
$files = new FileList();
3438
$files['one'] = [ 'pathname' => __FILE__ ];
@@ -37,7 +41,7 @@ public function test_should_remove_offset()
3741
$this->assertNull($files['one']);
3842
}
3943

40-
public function test_should_iterate()
44+
public function test_should_iterate(): void
4145
{
4246
$expected = [
4347

tests/FileResponseTest.php

+63-29
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
<?php
22

3-
namespace ICanBoogie\HTTP;
3+
namespace Test\ICanBoogie\HTTP;
44

55
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;
613
use LogicException;
714
use PHPUnit\Framework\Attributes\DataProvider;
815
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
@@ -36,7 +43,7 @@ public function test_closure_body(int $status, \Closure $expected_provider)
3643

3744
$response = $this
3845
->getMockBuilder(FileResponse::class)
39-
->setConstructorArgs([ __FILE__, Request::from()])
46+
->setConstructorArgs([ __FILE__, Request::from() ])
4047
->onlyMethods([ 'send_file', 'send_headers' ])
4148
->getMock();
4249
$response
@@ -93,8 +100,13 @@ public function test_invoke(string $cache_control, bool $is_modified, int $expec
93100
}
94101

95102
#[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 {
98110
$headers = new Headers();
99111
$headers['If-Range'] = $etag = "123";
100112

@@ -171,22 +183,26 @@ public function test_send_body(): void
171183
}
172184

173185
#[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 {
176192
$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);
178194
}
179195

180196
public static function provide_test_get_content_type(): array
181197
{
182198
return [
183199

184200
[ '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' ] ],
187203
[ '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' ] ],
190206

191207
];
192208
}
@@ -208,7 +224,7 @@ public static function provide_test_get_etag(): array
208224

209225
[ $file_hash, $file ],
210226
[ $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 ] ],
212228

213229
];
214230
}
@@ -232,8 +248,8 @@ public static function provide_test_get_expires(): array
232248
[ $expires_default, $file ],
233249
[ $expires2, $file, [ FileResponse::OPTION_EXPIRES => $expires2_str ] ],
234250
[ $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 ] ],
237253

238254
];
239255
}
@@ -273,13 +289,31 @@ public static function provide_test_get_is_modified(): array
273289

274290
return [
275291

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+
],
283317

284318
];
285319
}
@@ -289,13 +323,13 @@ public function test_filename(string $file, string|bool $filename, string $expec
289323
{
290324
$response = new FileResponse($file, Request::from(), [ FileResponse::OPTION_FILENAME => $filename ]);
291325

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']);
294328
$this->assertEquals('attachment', $response->headers->content_disposition->type);
295329
$this->assertEquals($expected, $response->headers->content_disposition->filename);
296330
}
297331

298-
public static function provide_test_filename()
332+
public static function provide_test_filename(): array
299333
{
300334
$file = create_file();
301335
$filename = "Filename" . uniqid() . ".png";
@@ -309,7 +343,7 @@ public static function provide_test_filename()
309343
}
310344

311345
#[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
313347
{
314348
$request = Request::from([ Request::OPTION_URI => '/', 'method' => $method ]);
315349

@@ -321,10 +355,10 @@ public function test_accept_ranges(RequestMethod $method, string $type)
321355

322356
/* @var $response FileResponse */
323357

324-
$this->assertStringContainsString("Accept-Ranges: $type", (string) $response);
358+
$this->assertStringContainsString("Accept-Ranges: $type", (string)$response);
325359
}
326360

327-
public static function provide_test_accept_ranges()
361+
public static function provide_test_accept_ranges(): array
328362
{
329363
return [
330364

@@ -337,7 +371,7 @@ public static function provide_test_accept_ranges()
337371
}
338372

339373
#[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
341375
{
342376
$etag = sha1_file($pathname);
343377

@@ -369,7 +403,7 @@ public function test_range_response(string $bytes, string $pathname, string $exp
369403
$this->assertSame($expected, $content);
370404
}
371405

372-
public static function provide_test_range_response()
406+
public static function provide_test_range_response(): array
373407
{
374408
$pathname = create_file();
375409
$data = file_get_contents($pathname);

0 commit comments

Comments
 (0)