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