From a697ed2e0cb8cce07a34e22222b9c36ce536cf84 Mon Sep 17 00:00:00 2001 From: Olivier Laviale Date: Sat, 2 Nov 2024 10:19:28 +0100 Subject: [PATCH] Fix tests namespace --- lib/FileList.php | 11 +--- phpstan.neon | 2 + tests/FileInfoTest.php | 8 ++- tests/FileListTest.php | 18 ++++-- tests/FileResponseTest.php | 92 ++++++++++++++++++--------- tests/FileTest.php | 106 +++++++++++++------------------ tests/ForceRedirectTest.php | 9 --- tests/HeadersTest.php | 25 +++----- tests/MethodNotAllowedTest.php | 11 +--- tests/PermissionRequiredTest.php | 9 --- tests/RedirectResponseTest.php | 9 --- tests/RequestMethodTest.php | 9 --- tests/RequestRangeTest.php | 44 ++++++------- tests/RequestTest.php | 9 --- tests/RescueEventTest.php | 9 --- tests/ResponseTest.php | 35 ++++------ tests/StatusCodeNotValidTest.php | 14 ++-- tests/StatusTest.php | 25 +++----- tests/bootstrap.php | 2 +- 19 files changed, 179 insertions(+), 268 deletions(-) diff --git a/lib/FileList.php b/lib/FileList.php index 80b5171..f031f1d 100644 --- a/lib/FileList.php +++ b/lib/FileList.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace ICanBoogie\HTTP; use ArrayAccess; @@ -19,7 +10,7 @@ use function count; /** - * Representation of a list of request files. + * Represents a list of request files. * * @implements ArrayAccess * @implements IteratorAggregate diff --git a/phpstan.neon b/phpstan.neon index f8b6434..de0e5a0 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,6 +2,8 @@ parameters: level: 5 paths: - lib + scanFiles: + - tests/bootstrap.php ignoreErrors: - "#.*get_.* is unused#" - "#.*set_.* is unused#" diff --git a/tests/FileInfoTest.php b/tests/FileInfoTest.php index 887f887..b148e55 100644 --- a/tests/FileInfoTest.php +++ b/tests/FileInfoTest.php @@ -9,11 +9,13 @@ * file that was distributed with this source code. */ -namespace ICanBoogie\HTTP; +namespace Test\ICanBoogie\HTTP; +use ICanBoogie\HTTP\FileInfo; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\TestCase; -class FileInfoTest extends \PHPUnit\Framework\TestCase +class FileInfoTest extends TestCase { /** * @param $pathname @@ -25,7 +27,7 @@ public function test_resolve_type($pathname, $expected) $this->assertEquals($expected, FileInfo::resolve_type($pathname)); } - public static function provide_test_resolve_type() + public static function provide_test_resolve_type(): array { $bytes = create_file(); diff --git a/tests/FileListTest.php b/tests/FileListTest.php index bd05ec5..2e5b4fa 100644 --- a/tests/FileListTest.php +++ b/tests/FileListTest.php @@ -1,10 +1,14 @@ assertNotSame($files1, $files2); } - public function test_should_return_null_if_offset_not_defined() + public function test_should_return_null_if_offset_not_defined(): void { $files = new FileList(); $this->assertNull($files['undefined']); } - public function test_should_create_instance_by_setting_offset() + public function test_should_create_instance_by_setting_offset(): void { $files = new FileList(); $files['one'] = [ 'pathname' => __FILE__ ]; @@ -28,7 +32,7 @@ public function test_should_create_instance_by_setting_offset() $this->assertEquals(__FILE__, $files['one']->pathname); } - public function test_should_remove_offset() + public function test_should_remove_offset(): void { $files = new FileList(); $files['one'] = [ 'pathname' => __FILE__ ]; @@ -37,7 +41,7 @@ public function test_should_remove_offset() $this->assertNull($files['one']); } - public function test_should_iterate() + public function test_should_iterate(): void { $expected = [ diff --git a/tests/FileResponseTest.php b/tests/FileResponseTest.php index 125f604..25da338 100644 --- a/tests/FileResponseTest.php +++ b/tests/FileResponseTest.php @@ -1,8 +1,15 @@ getMockBuilder(FileResponse::class) - ->setConstructorArgs([ __FILE__, Request::from()]) + ->setConstructorArgs([ __FILE__, Request::from() ]) ->onlyMethods([ 'send_file', 'send_headers' ]) ->getMock(); $response @@ -93,8 +100,13 @@ public function test_invoke(string $cache_control, bool $is_modified, int $expec } #[DataProvider('provide_test_invoke_with_range')] - public function test_invoke_with_range(string $cache_control, bool $is_modified, bool $is_satisfiable, bool $is_total, int $expected) - { + public function test_invoke_with_range( + string $cache_control, + bool $is_modified, + bool $is_satisfiable, + bool $is_total, + int $expected + ): void { $headers = new Headers(); $headers['If-Range'] = $etag = "123"; @@ -171,10 +183,14 @@ public function test_send_body(): void } #[DataProvider('provide_test_get_content_type')] - public function test_get_content_type(string $expected, string $file, array $options = [], array $headers = []) - { + public function test_get_content_type( + string $expected, + string $file, + array $options = [], + array $headers = [] + ): void { $response = new FileResponse($file, Request::from(), $options, $headers); - $this->assertEquals($expected, (string) $response->headers->content_type); + $this->assertEquals($expected, (string)$response->headers->content_type); } public static function provide_test_get_content_type(): array @@ -182,11 +198,11 @@ public static function provide_test_get_content_type(): array return [ [ 'application/octet-stream', create_file() ], - [ 'text/plain', create_file(), [ FileResponse::OPTION_MIME => 'text/plain'] ], - [ 'text/plain', create_file(), [], [ 'Content-Type' => 'text/plain'] ], + [ 'text/plain', create_file(), [ FileResponse::OPTION_MIME => 'text/plain' ] ], + [ 'text/plain', create_file(), [], [ 'Content-Type' => 'text/plain' ] ], [ 'image/png', create_image('.png') ], - [ 'text/plain', create_image('.png'), [ FileResponse::OPTION_MIME => 'text/plain'] ], - [ 'text/plain', create_image('.png'), [], [ 'Content-Type' => 'text/plain'] ], + [ 'text/plain', create_image('.png'), [ FileResponse::OPTION_MIME => 'text/plain' ] ], + [ 'text/plain', create_image('.png'), [], [ 'Content-Type' => 'text/plain' ] ], ]; } @@ -208,7 +224,7 @@ public static function provide_test_get_etag(): array [ $file_hash, $file ], [ $file_hash_custom, $file, [ FileResponse::OPTION_ETAG => $file_hash_custom ] ], - [ $file_hash_custom, $file, [ ], [ 'ETag' => $file_hash_custom ] ], + [ $file_hash_custom, $file, [], [ 'ETag' => $file_hash_custom ] ], ]; } @@ -232,8 +248,8 @@ public static function provide_test_get_expires(): array [ $expires_default, $file ], [ $expires2, $file, [ FileResponse::OPTION_EXPIRES => $expires2_str ] ], [ $expires2, $file, [ FileResponse::OPTION_EXPIRES => $expires2 ] ], - [ $expires2, $file, [ ], [ 'Expires' => $expires2_str ] ], - [ $expires2, $file, [ ], [ 'Expires' => $expires2 ] ], + [ $expires2, $file, [], [ 'Expires' => $expires2_str ] ], + [ $expires2, $file, [], [ 'Expires' => $expires2 ] ], ]; } @@ -273,13 +289,31 @@ public static function provide_test_get_is_modified(): array return [ - [ true, [ ] ], - [ true, [ 'If-Modified-Since' => (string) $modified_since ] ], - [ true, [ 'If-Modified-Since' => (string) $modified_since ], $modified_time_older ], - [ true, [ 'If-Modified-Since' => (string) $modified_since, 'If-None-Match' => uniqid() ], $modified_time_older ], - [ true, [ 'If-Modified-Since' => (string) $modified_since, 'If-None-Match' => uniqid() ], $modified_time_older ], - [ true, [ 'If-Modified-Since' => (string) $modified_since, 'If-None-Match' => $etag ], $modified_time_newer, $etag ], - [ false, [ 'If-Modified-Since' => (string) $modified_since, 'If-None-Match' => $etag ], $modified_time_older, $etag ], + [ true, [] ], + [ true, [ 'If-Modified-Since' => (string)$modified_since ] ], + [ true, [ 'If-Modified-Since' => (string)$modified_since ], $modified_time_older ], + [ + true, + [ 'If-Modified-Since' => (string)$modified_since, 'If-None-Match' => uniqid() ], + $modified_time_older + ], + [ + true, + [ 'If-Modified-Since' => (string)$modified_since, 'If-None-Match' => uniqid() ], + $modified_time_older + ], + [ + true, + [ 'If-Modified-Since' => (string)$modified_since, 'If-None-Match' => $etag ], + $modified_time_newer, + $etag + ], + [ + false, + [ 'If-Modified-Since' => (string)$modified_since, 'If-None-Match' => $etag ], + $modified_time_older, + $etag + ], ]; } @@ -289,13 +323,13 @@ public function test_filename(string $file, string|bool $filename, string $expec { $response = new FileResponse($file, Request::from(), [ FileResponse::OPTION_FILENAME => $filename ]); - $this->assertEquals('binary', (string) $response->headers['Content-Transfer-Encoding']); - $this->assertEquals('File Transfer', (string) $response->headers['Content-Description']); + $this->assertEquals('binary', (string)$response->headers['Content-Transfer-Encoding']); + $this->assertEquals('File Transfer', (string)$response->headers['Content-Description']); $this->assertEquals('attachment', $response->headers->content_disposition->type); $this->assertEquals($expected, $response->headers->content_disposition->filename); } - public static function provide_test_filename() + public static function provide_test_filename(): array { $file = create_file(); $filename = "Filename" . uniqid() . ".png"; @@ -309,7 +343,7 @@ public static function provide_test_filename() } #[DataProvider('provide_test_accept_ranges')] - public function test_accept_ranges(RequestMethod $method, string $type) + public function test_accept_ranges(RequestMethod $method, string $type): void { $request = Request::from([ Request::OPTION_URI => '/', 'method' => $method ]); @@ -321,10 +355,10 @@ public function test_accept_ranges(RequestMethod $method, string $type) /* @var $response FileResponse */ - $this->assertStringContainsString("Accept-Ranges: $type", (string) $response); + $this->assertStringContainsString("Accept-Ranges: $type", (string)$response); } - public static function provide_test_accept_ranges() + public static function provide_test_accept_ranges(): array { return [ @@ -337,7 +371,7 @@ public static function provide_test_accept_ranges() } #[DataProvider('provide_test_range_response')] - public function test_range_response(string $bytes, string $pathname, string $expected) + public function test_range_response(string $bytes, string $pathname, string $expected): void { $etag = sha1_file($pathname); @@ -369,7 +403,7 @@ public function test_range_response(string $bytes, string $pathname, string $exp $this->assertSame($expected, $content); } - public static function provide_test_range_response() + public static function provide_test_range_response(): array { $pathname = create_file(); $data = file_get_contents($pathname); diff --git a/tests/FileTest.php b/tests/FileTest.php index cafcc32..cd3b55f 100644 --- a/tests/FileTest.php +++ b/tests/FileTest.php @@ -1,17 +1,9 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ICanBoogie\HTTP; +namespace Test\ICanBoogie\HTTP; use ICanBoogie\FormattedString; +use ICanBoogie\HTTP\File; use ICanBoogie\PropertyNotWritable; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -23,7 +15,7 @@ class FileTest extends TestCase { #[DataProvider('provide_test_get_extension')] - public function test_get_extension($expected, $pathname) + public function test_get_extension($expected, $pathname): void { $file = File::from([ File::OPTION_PATHNAME => $pathname ]); @@ -34,39 +26,39 @@ public static function provide_test_get_extension(): array { return [ - [ '.c', '/path/to/example.c' ], - [ '.zip', '/path/to/example.zip' ], + [ '.c', '/path/to/example.c' ], + [ '.zip', '/path/to/example.zip' ], [ '.document', '/path/to/example.document' ], - [ '.png', '/path/to/example.zip.png' ], - [ '.gz', '/path/to/example.tar.gz' ], - [ '', '/path/to/example' ] + [ '.png', '/path/to/example.zip.png' ], + [ '.gz', '/path/to/example.tar.gz' ], + [ '', '/path/to/example' ] ]; } #[DataProvider('provide_test_match')] - public function test_match($expected, $against) + public function test_match($expected, $against): void { $file = File::from([ File::OPTION_PATHNAME => '/path/to/example.zip' ]); $this->assertEquals($expected, $file->match($against)); } - public static function provide_test_match() + public static function provide_test_match(): array { return [ - [ true, null ], - [ true, false ], - [ true, '' ], - [ true, [] ], - [ true, '.zip' ], - [ true, 'application/zip' ], - [ true, 'application' ], - [ true, [ '.mp3', '.zip' ] ], - [ true, [ '.mp3', 'application' ] ], - [ true, [ '.mp3', 'application/zip' ] ], - [ true, [ '.zip', 'application/zip' ] ], + [ true, null ], + [ true, false ], + [ true, '' ], + [ true, [] ], + [ true, '.zip' ], + [ true, 'application/zip' ], + [ true, 'application' ], + [ true, [ '.mp3', '.zip' ] ], + [ true, [ '.mp3', 'application' ] ], + [ true, [ '.mp3', 'application/zip' ] ], + [ true, [ '.zip', 'application/zip' ] ], [ false, '.png' ], [ false, 'image/png' ], [ false, 'image' ], @@ -78,7 +70,7 @@ public static function provide_test_match() } #[DataProvider('provide_test_error_message')] - public function test_error_message($error, $expected) + public function test_error_message($error, $expected): void { $file = File::from([ File::OPTION_ERROR => $error ]); @@ -90,47 +82,44 @@ public function test_error_message($error, $expected) $message = $file->error_message; $this->assertInstanceOf(FormattedString::class, $message); - $this->assertStringStartsWith($expected, (string) $message); + $this->assertStringStartsWith($expected, (string)$message); } } - public static function provide_test_error_message() + public static function provide_test_error_message(): array { return [ - [ UPLOAD_ERR_OK, null ], - [ UPLOAD_ERR_INI_SIZE, "Maximum file size is" ], - [ UPLOAD_ERR_FORM_SIZE, "Maximum file size is" ], - [ UPLOAD_ERR_PARTIAL, "The uploaded file was only partially uploaded." ], - [ UPLOAD_ERR_NO_FILE, "No file was uploaded." ], + [ UPLOAD_ERR_OK, null ], + [ UPLOAD_ERR_INI_SIZE, "Maximum file size is" ], + [ UPLOAD_ERR_FORM_SIZE, "Maximum file size is" ], + [ UPLOAD_ERR_PARTIAL, "The uploaded file was only partially uploaded." ], + [ UPLOAD_ERR_NO_FILE, "No file was uploaded." ], [ UPLOAD_ERR_NO_TMP_DIR, "Missing a temporary folder." ], [ UPLOAD_ERR_CANT_WRITE, "Failed to write file to disk." ], - [ UPLOAD_ERR_EXTENSION, "A PHP extension stopped the file upload." ], - [ 123456, "An error has occurred."] + [ UPLOAD_ERR_EXTENSION, "A PHP extension stopped the file upload." ], + [ 123456, "An error has occurred." ] ]; } #[DataProvider('provide_test_to_array')] - public function test_to_array($properties, $expected) + public function test_to_array($properties, $expected): void { $this->assertSame($expected, File::from($properties)->to_array()); } - public static function provide_test_to_array() + public static function provide_test_to_array(): array { return [ [ [ - File::OPTION_PATHNAME => __FILE__ - ], [ - 'name' => basename(__FILE__), 'unsuffixed_name' => basename(__FILE__, '.php'), 'extension' => '.php', @@ -139,7 +128,6 @@ public static function provide_test_to_array() 'pathname' => __FILE__, 'error' => null, 'error_message' => null - ] ], @@ -147,14 +135,11 @@ public static function provide_test_to_array() [ [ - File::OPTION_PATHNAME => '/path/to/image.png', File::OPTION_SIZE => 1234 - ], [ - 'name' => 'image.png', 'unsuffixed_name' => 'image', 'extension' => '.png', @@ -163,7 +148,6 @@ public static function provide_test_to_array() 'pathname' => '/path/to/image.png', 'error' => null, 'error_message' => null - ] ], @@ -171,13 +155,10 @@ public static function provide_test_to_array() [ [ - File::OPTION_ERROR => UPLOAD_ERR_NO_FILE - ], [ - 'name' => null, 'unsuffixed_name' => null, 'extension' => null, @@ -186,7 +167,6 @@ public static function provide_test_to_array() 'pathname' => null, 'error' => UPLOAD_ERR_NO_FILE, 'error_message' => "No file was uploaded." - ] ] @@ -205,7 +185,7 @@ public function test_write_readonly_properties(string $property) } #[DataProvider('provide_readonly_properties')] - public function test_read_readonly_properties(string $property) + public function test_read_readonly_properties(string $property): void { $file = File::from([ File::OPTION_PATHNAME => __FILE__, @@ -215,17 +195,17 @@ public function test_read_readonly_properties(string $property) $this->assertNotNull($file->$property); } - public static function provide_readonly_properties() + public static function provide_readonly_properties(): array { $properties = 'error error_message extension is_uploaded is_valid name pathname size type' - . ' unsuffixed_name'; + . ' unsuffixed_name'; return array_map(function ($v) { - return (array) $v; + return (array)$v; }, explode(' ', $properties)); } - public function test_fake_file() + public function test_fake_file(): void { $sandbox = __DIR__ . DIRECTORY_SEPARATOR . 'sandbox' . DIRECTORY_SEPARATOR; $pathname = $sandbox . uniqid() . '.php'; @@ -251,7 +231,7 @@ public function test_fake_file() unlink($file->pathname); } - public function test_empty_slot() + public function test_empty_slot(): void { $file = File::from('example'); @@ -265,7 +245,7 @@ public function test_empty_slot() $this->assertFalse($file->is_uploaded); } - public function test_should_get_defined_type() + public function test_should_get_defined_type(): void { $expected = 'application/x-bytes'; @@ -279,7 +259,7 @@ public function test_should_get_defined_type() $this->assertEquals($expected, $file->type); } - public function test_should_get_defined_size() + public function test_should_get_defined_size(): void { $expected = 123456; @@ -293,7 +273,7 @@ public function test_should_get_defined_size() $this->assertEquals($expected, $file->size); } - public function test_move_overwrite() + public function test_move_overwrite(): void { $file1 = create_file(); $file2 = create_file(); @@ -305,7 +285,7 @@ public function test_move_overwrite() $file->move($file2); } - public function test_move_overwrite_force() + public function test_move_overwrite_force(): void { $file1 = create_file(); $file2 = create_file(); diff --git a/tests/ForceRedirectTest.php b/tests/ForceRedirectTest.php index 71210a5..7d53143 100644 --- a/tests/ForceRedirectTest.php +++ b/tests/ForceRedirectTest.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\HTTP; use ICanBoogie\HTTP\ForceRedirect; diff --git a/tests/HeadersTest.php b/tests/HeadersTest.php index 969b28a..bfa98bd 100644 --- a/tests/HeadersTest.php +++ b/tests/HeadersTest.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\HTTP; use DateTimeZone; @@ -25,7 +16,7 @@ final class HeadersTest extends TestCase { - public function testDateTimeFromDateTime() + public function testDateTimeFromDateTime(): void { $datetime = new \DateTime(); $headers_datetime = new DateHeader($datetime); @@ -37,7 +28,7 @@ public function testDateTimeFromDateTime() /** * @throws Exception */ - public function testDateTimeFromDateTimeString() + public function testDateTimeFromDateTimeString(): void { $datetime = new \DateTime('now', new DateTimeZone('GMT')); @@ -57,7 +48,7 @@ public function testDateTimeFromDateTimeString() ); } - public function test_cache_control() + public function test_cache_control(): void { $headers = new Headers(); $this->assertInstanceOf(Headers\CacheControl::class, $headers['Cache-Control']); @@ -73,7 +64,7 @@ public function test_cache_control() $this->assertTrue($headers->cache_control->no_transform); } - public function test_content_disposition() + public function test_content_disposition(): void { $headers = new Headers(); $this->assertInstanceOf(Headers\ContentDisposition::class, $headers['Content-Disposition']); @@ -83,7 +74,7 @@ public function test_content_disposition() $this->assertEquals('test.txt', $headers->content_disposition->filename); } - public function test_content_length() + public function test_content_length(): void { $headers = new Headers(); $this->assertNull($headers['Content-Length']); @@ -96,7 +87,7 @@ public function test_content_length() $this->assertEquals(123, $headers->content_length); } - public function test_content_type() + public function test_content_type(): void { $headers = new Headers(); $this->assertInstanceOf(Headers\ContentType::class, $headers['Content-Type']); @@ -130,7 +121,7 @@ public function test_etag(): void $this->assertNull($headers->etag); } - public function test_last_modified() + public function test_last_modified(): void { $headers = new Headers(); $this->assertInstanceOf(Headers\Date::class, $headers->last_modified); @@ -239,7 +230,7 @@ public static function provide_getters(): array } #[DataProvider('provide_test_empty_date')] - public function test_empty_date(string $field) + public function test_empty_date(string $field): void { $headers = new Headers(); diff --git a/tests/MethodNotAllowedTest.php b/tests/MethodNotAllowedTest.php index f5ab9dd..e26551e 100644 --- a/tests/MethodNotAllowedTest.php +++ b/tests/MethodNotAllowedTest.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\HTTP; use ICanBoogie\HTTP\MethodNotAllowed; @@ -16,7 +7,7 @@ final class MethodNotAllowedTest extends TestCase { - public function test_get_method() + public function test_get_method(): void { $method = 'UNSUPPORTED'; $exception = new MethodNotAllowed($method); diff --git a/tests/PermissionRequiredTest.php b/tests/PermissionRequiredTest.php index 6d594a0..1863de8 100644 --- a/tests/PermissionRequiredTest.php +++ b/tests/PermissionRequiredTest.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\HTTP; use ICanBoogie\HTTP\PermissionRequired; diff --git a/tests/RedirectResponseTest.php b/tests/RedirectResponseTest.php index ce1359f..bcc551c 100644 --- a/tests/RedirectResponseTest.php +++ b/tests/RedirectResponseTest.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\HTTP; use ICanBoogie\HTTP\RedirectResponse; diff --git a/tests/RequestMethodTest.php b/tests/RequestMethodTest.php index df7f815..abcb67e 100644 --- a/tests/RequestMethodTest.php +++ b/tests/RequestMethodTest.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\HTTP; use ICanBoogie\HTTP\RequestMethod; diff --git a/tests/RequestRangeTest.php b/tests/RequestRangeTest.php index 0ac4335..56cafd8 100644 --- a/tests/RequestRangeTest.php +++ b/tests/RequestRangeTest.php @@ -1,27 +1,21 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ICanBoogie\HTTP; +namespace Test\ICanBoogie\HTTP; +use ICanBoogie\HTTP\Headers; +use ICanBoogie\HTTP\RequestRange; use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\TestCase; -class RequestRangeTest extends \PHPUnit\Framework\TestCase +class RequestRangeTest extends TestCase { #[DataProvider('provide_invalid_range')] - public function test_should_return_null_when_undefined_or_modified($headers, $total, $etag) + public function test_should_return_null_when_undefined_or_modified($headers, $total, $etag): void { $this->assertNull(RequestRange::from(new Headers($headers), $total, $etag)); } - public static function provide_invalid_range() + public static function provide_invalid_range(): array { $etag = uniqid(); @@ -37,7 +31,7 @@ public static function provide_invalid_range() } #[DataProvider('provide_unsatisfiable')] - public function test_should_be_unsatisfiable(string $range) + public function test_should_be_unsatisfiable(string $range): void { $etag = uniqid(); $headers = new Headers([ 'Range' => $range, 'If-Range' => $etag ]); @@ -45,7 +39,7 @@ public function test_should_be_unsatisfiable(string $range) $this->assertFalse(RequestRange::from($headers, 10000, $etag)->is_satisfiable); } - public static function provide_unsatisfiable() + public static function provide_unsatisfiable(): array { return [ @@ -57,7 +51,7 @@ public static function provide_unsatisfiable() } #[DataProvider('provide_valid_range')] - public function test_should_return_range(string $range, string $expected) + public function test_should_return_range(string $range, string $expected): void { $etag = uniqid(); $headers = new Headers([ 'Range' => $range, 'If-Range' => $etag ]); @@ -67,7 +61,7 @@ public function test_should_return_range(string $range, string $expected) $this->assertEquals($expected, (string) $range); } - public static function provide_valid_range() + public static function provide_valid_range(): array { return [ @@ -80,7 +74,7 @@ public static function provide_valid_range() } #[DataProvider('provide_test_is_total')] - public function test_is_total($range, $expected) + public function test_is_total($range, $expected): void { $etag = uniqid(); $headers = new Headers([ 'Range' => $range, 'If-Range' => $etag ]); @@ -88,7 +82,7 @@ public function test_is_total($range, $expected) $this->assertEquals($expected, RequestRange::from($headers, 10000, $etag)->is_total); } - public static function provide_test_is_total() + public static function provide_test_is_total(): array { return [ @@ -102,7 +96,7 @@ public static function provide_test_is_total() } #[DataProvider('provide_test_length')] - public function test_length($range, $expected) + public function test_length($range, $expected): void { $etag = uniqid(); $headers = new Headers([ 'Range' => $range, 'If-Range' => $etag ]); @@ -110,7 +104,7 @@ public function test_length($range, $expected) $this->assertEquals($expected, RequestRange::from($headers, 10000, $etag)->length); } - public static function provide_test_length() + public static function provide_test_length(): array { return [ @@ -124,7 +118,7 @@ public static function provide_test_length() } #[DataProvider('provide_test_max_length')] - public function test_max_length($range, $expected) + public function test_max_length($range, $expected): void { $etag = uniqid(); $headers = new Headers([ 'Range' => $range, 'If-Range' => $etag ]); @@ -132,7 +126,7 @@ public function test_max_length($range, $expected) $this->assertEquals($expected, RequestRange::from($headers, 10000, $etag)->max_length); } - public static function provide_test_max_length() + public static function provide_test_max_length(): array { return [ @@ -147,7 +141,7 @@ public static function provide_test_max_length() } #[DataProvider('provide_test_offset')] - public function test_offset($range, $expected) + public function test_offset($range, $expected): void { $etag = uniqid(); $headers = new Headers([ 'Range' => $range, 'If-Range' => $etag ]); @@ -155,7 +149,7 @@ public function test_offset($range, $expected) $this->assertEquals($expected, RequestRange::from($headers, 10000, $etag)->offset); } - public static function provide_test_offset() + public static function provide_test_offset(): array { return [ diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 2fde3ca..8389ff3 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\HTTP; use ICanBoogie\HTTP\File; diff --git a/tests/RescueEventTest.php b/tests/RescueEventTest.php index 155f6e8..5b95691 100644 --- a/tests/RescueEventTest.php +++ b/tests/RescueEventTest.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\HTTP; use Exception; diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index d880ddc..9374dd2 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\HTTP; use ICanBoogie\DateTime; @@ -28,7 +19,7 @@ public static function setupBeforeClass(): void self::$response = new Response(); } - public function test_clone() + public function test_clone(): void { $response = new Response(); $clone = clone $response; @@ -37,7 +28,7 @@ public function test_clone() $this->assertNotSame($clone->status, $response->status); } - public function test_should_set_content_type() + public function test_should_set_content_type(): void { $expected = 'application/json'; $response = new Response(); @@ -48,14 +39,14 @@ public function test_should_set_content_type() } #[DataProvider('provide_test_write_readonly_properties')] - public function test_write_readonly_properties(string $property) + public function test_write_readonly_properties(string $property): void { $this->expectException(PropertyNotWritable::class); self::$response->$property = null; } - public static function provide_test_write_readonly_properties() + public static function provide_test_write_readonly_properties(): array { $properties = 'is_validateable is_cacheable is_fresh'; @@ -64,7 +55,7 @@ public static function provide_test_write_readonly_properties() }, explode(' ', $properties)); } - public function test_age() + public function test_age(): void { $response = new Response(); $this->assertEquals(0, $response->age); @@ -79,7 +70,7 @@ public function test_age() $this->assertSame(123, $response->age); } - public function test_expires() + public function test_expires(): void { $response = new Response(); $this->assertInstanceOf(Date::class, $response->expires); @@ -126,14 +117,14 @@ public static function provide_test_no_content_length(): array ]; } - public function test_auto_content_length_with_null() + public function test_auto_content_length_with_null(): void { $response = new Response(); $this->assertEquals("HTTP/1.1 200 OK\r\nDate: {$response->headers->date}\r\n\r\n", (string) $response); } - public function test_preserve_content_length() + public function test_preserve_content_length(): void { $response = new Response(null, Response::STATUS_OK, [ @@ -144,7 +135,7 @@ public function test_preserve_content_length() $this->assertEquals("HTTP/1.1 200 OK\r\nContent-Length: 123\r\nDate: {$response->headers->date}\r\n\r\n", (string) $response); } - public function test_is_validateable() + public function test_is_validateable(): void { $response = new Response(); $this->assertFalse($response->is_validateable); @@ -164,7 +155,7 @@ public function test_is_cacheable(Response $response, bool $expected): void $this->assertEquals($expected, $response->is_cacheable); } - public static function provide_test_is_cacheable() + public static function provide_test_is_cacheable(): array { return [ @@ -181,7 +172,7 @@ public static function provide_test_is_cacheable() ]; } - public function test_invoke() + public function test_invoke(): void { $body = uniqid(); @@ -215,7 +206,7 @@ public function test_invoke() $response(); } - public function test_invoke_empty_body() + public function test_invoke_empty_body(): void { $body = null; @@ -249,7 +240,7 @@ public function test_invoke_empty_body() $response(); } - public function test_to_string_with_exception() + public function test_to_string_with_exception(): void { $body = uniqid(); diff --git a/tests/StatusCodeNotValidTest.php b/tests/StatusCodeNotValidTest.php index 94cb335..d2f6aff 100644 --- a/tests/StatusCodeNotValidTest.php +++ b/tests/StatusCodeNotValidTest.php @@ -1,17 +1,11 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ +namespace Test\ICanBoogie\HTTP; -namespace ICanBoogie\HTTP; +use ICanBoogie\HTTP\StatusCodeNotValid; +use PHPUnit\Framework\TestCase; -class StatusCodeNotValidTest extends \PHPUnit\Framework\TestCase +class StatusCodeNotValidTest extends TestCase { public function test_get_status_code() { diff --git a/tests/StatusTest.php b/tests/StatusTest.php index 0a93c8b..3dc8474 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -1,14 +1,5 @@ - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - namespace Test\ICanBoogie\HTTP; use ICanBoogie\HTTP\ResponseStatus; @@ -20,24 +11,24 @@ final class StatusTest extends TestCase { - public function test_constructor() + public function test_constructor(): void { $status = new Status(ResponseStatus::STATUS_MOVED_PERMANENTLY, "Over the rainbow"); $this->assertEquals(ResponseStatus::STATUS_MOVED_PERMANENTLY, $status->code); $this->assertEquals("Over the rainbow", $status->message); - $this->assertEquals("301 Over the rainbow", (string) $status); + $this->assertEquals("301 Over the rainbow", (string)$status); $status->message = null; $this->assertEquals("Moved Permanently", $status->message); - $this->assertEquals("301 Moved Permanently", (string) $status); + $this->assertEquals("301 Moved Permanently", (string)$status); } #[DataProvider('provide_test_from')] public function test_from(mixed $source, string $expected): void { $status = Status::from($source); - $this->assertEquals($expected, (string) $status); + $this->assertEquals($expected, (string)$status); } public static function provide_test_from(): array @@ -65,14 +56,14 @@ public function test_from_invalid_status_code(): void Status::from("987 Invalid"); } - public function test_constructor_with_invalid_code() + public function test_constructor_with_invalid_code(): void { $this->expectException(StatusCodeNotValid::class); new Status(987); } - public function test_set_code_invalid() + public function test_set_code_invalid(): void { $status = new Status(); @@ -81,14 +72,14 @@ public function test_set_code_invalid() $status->code = 12345; } - public function test_set_code() + public function test_set_code(): void { $status = new Status(); $status->code = ResponseStatus::STATUS_NOT_FOUND; $this->assertEquals(ResponseStatus::STATUS_NOT_FOUND, $status->code); } - public function test_is_valid() + public function test_is_valid(): void { $status = new Status(ResponseStatus::STATUS_OK); $this->assertTrue($status->is_valid); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index af41288..7bae773 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ICanBoogie\HTTP; +namespace Test\ICanBoogie\HTTP; use function random_bytes;