Skip to content

Commit d3e22bd

Browse files
authored
Merge pull request #11 from Nejcc/dev
update enum http status code
2 parents 918b122 + af4c1ac commit d3e22bd

File tree

4 files changed

+567
-0
lines changed

4 files changed

+567
-0
lines changed

Tests/HttpStatusCodeTest.php

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
3+
namespace Nejcc\PhpDatatypes\Tests;
4+
5+
6+
7+
use Nejcc\PhpDatatypes\Enums\Http\HttpStatusCode;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class HttpStatusCodeTest extends TestCase
11+
{
12+
public function testIsInformational()
13+
{
14+
$this->assertTrue(HttpStatusCode::CONTINUE->isInformational());
15+
$this->assertFalse(HttpStatusCode::OK->isInformational());
16+
}
17+
18+
public function testIsSuccess()
19+
{
20+
$this->assertTrue(HttpStatusCode::OK->isSuccess());
21+
$this->assertFalse(HttpStatusCode::BAD_REQUEST->isSuccess());
22+
}
23+
24+
public function testIsRedirection()
25+
{
26+
$this->assertTrue(HttpStatusCode::MOVED_PERMANENTLY->isRedirection());
27+
$this->assertFalse(HttpStatusCode::NOT_FOUND->isRedirection());
28+
}
29+
30+
public function testIsClientError()
31+
{
32+
$this->assertTrue(HttpStatusCode::NOT_FOUND->isClientError());
33+
$this->assertFalse(HttpStatusCode::OK->isClientError());
34+
}
35+
36+
public function testIsServerError()
37+
{
38+
$this->assertTrue(HttpStatusCode::INTERNAL_SERVER_ERROR->isServerError());
39+
$this->assertFalse(HttpStatusCode::BAD_REQUEST->isServerError());
40+
}
41+
42+
public function testGetMessage()
43+
{
44+
$this->assertEquals('OK', HttpStatusCode::OK->getMessage());
45+
$this->assertEquals('Not Found', HttpStatusCode::NOT_FOUND->getMessage());
46+
$this->assertEquals('Internal Server Error', HttpStatusCode::INTERNAL_SERVER_ERROR->getMessage());
47+
}
48+
49+
public function testGetSuggestion()
50+
{
51+
$this->assertEquals(
52+
'Check the request parameters and try again.',
53+
HttpStatusCode::BAD_REQUEST->getSuggestion()
54+
);
55+
$this->assertEquals(
56+
'The server is currently down for maintenance. Try again later.',
57+
HttpStatusCode::SERVICE_UNAVAILABLE->getSuggestion()
58+
);
59+
$this->assertEquals(
60+
'No specific suggestion.',
61+
HttpStatusCode::OK->getSuggestion()
62+
);
63+
}
64+
65+
public function testBuildResponse()
66+
{
67+
$response = HttpStatusCode::OK->buildResponse(
68+
data: ['message' => 'Success'],
69+
headers: ['Content-Type' => 'application/json']
70+
);
71+
72+
$expectedResponse = [
73+
'status' => 200,
74+
'message' => 'OK',
75+
'data' => ['message' => 'Success'],
76+
'headers' => ['Content-Type' => 'application/json'],
77+
];
78+
79+
$this->assertEquals($expectedResponse, $response);
80+
}
81+
82+
public function testGetSuccessCodes()
83+
{
84+
$successCodes = HttpStatusCode::getSuccessCodes();
85+
$this->assertContains(HttpStatusCode::OK, $successCodes);
86+
$this->assertNotContains(HttpStatusCode::BAD_REQUEST, $successCodes);
87+
}
88+
89+
public function testGetClientErrorCodes()
90+
{
91+
$clientErrorCodes = HttpStatusCode::getClientErrorCodes();
92+
$this->assertContains(HttpStatusCode::NOT_FOUND, $clientErrorCodes);
93+
$this->assertNotContains(HttpStatusCode::INTERNAL_SERVER_ERROR, $clientErrorCodes);
94+
}
95+
}

0 commit comments

Comments
 (0)