Fixes
This commit is contained in:
28
tests/Libs/Enums/Http/MethodTest.php
Normal file
28
tests/Libs/Enums/Http/MethodTest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Libs\Enums\Http;
|
||||
|
||||
use App\Libs\Enums\Http\Method;
|
||||
use App\Libs\TestCase;
|
||||
|
||||
class MethodTest extends TestCase
|
||||
{
|
||||
public function test_expected_methods()
|
||||
{
|
||||
$methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];
|
||||
|
||||
foreach ($methods as $method) {
|
||||
if (null === ($enum = Method::tryfrom($method))) {
|
||||
$this->fail("HTTP Method '{$method}' not recognized.");
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$method,
|
||||
$enum->value,
|
||||
"The return value of 'Method::{$enum->name}' '{$enum->value}' is not the expected value of '{$method}'."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
tests/Libs/Enums/Http/StatusTest.php
Normal file
47
tests/Libs/Enums/Http/StatusTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Libs\Enums\Http;
|
||||
|
||||
use App\Libs\Enums\Http\Status;
|
||||
use App\Libs\TestCase;
|
||||
|
||||
class StatusTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* This test checks if the important status codes are recognized. However, we do not cover the
|
||||
* entire range of status codes as it is not feasible to test all of them.
|
||||
*/
|
||||
public function test_important_status_codes()
|
||||
{
|
||||
$statusCodes = [200, 201, 202, 204, 304, 400, 401, 403, 404, 405, 406, 409, 500, 503, 504, 505];
|
||||
|
||||
foreach ($statusCodes as $code) {
|
||||
if (null === ($enum = Status::tryfrom($code))) {
|
||||
$this->fail("Important HTTP status code '{$code}' not recognized.");
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$code,
|
||||
$enum->value,
|
||||
"The return value of 'Status::{$enum->name}' '{$enum->value}' is not the expected '{$code}' value."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test checks if the status code is within the boundary of 100 to 599.
|
||||
* This test is needed to trigger an error if the status code is out of the boundary. As some parts
|
||||
* of the codebase expect the status code to be within this boundary.
|
||||
*/
|
||||
public function test_status_code_boundary()
|
||||
{
|
||||
foreach (Status::cases() as $code) {
|
||||
$this->assertTrue(
|
||||
$code->value >= 100 && $code->value <= 599,
|
||||
"HTTP Status Code 'Status::{$code->name}' '{$code->value}' is out of boundary."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user