1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Utility - Collection of various PHP utility functions. |
7
|
|
|
* |
8
|
|
|
* @author Eric Sizemore <[email protected]> |
9
|
|
|
* @version 2.0.0 |
10
|
|
|
* @copyright (C) 2017 - 2024 Eric Sizemore |
11
|
|
|
* @license The MIT License (MIT) |
12
|
|
|
* |
13
|
|
|
* Copyright (C) 2017 - 2024 Eric Sizemore <https://www.secondversion.com>. |
14
|
|
|
* |
15
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
16
|
|
|
* of this software and associated documentation files (the "Software"), to |
17
|
|
|
* deal in the Software without restriction, including without limitation the |
18
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
19
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is |
20
|
|
|
* furnished to do so, subject to the following conditions: |
21
|
|
|
* |
22
|
|
|
* The above copyright notice and this permission notice shall be included in |
23
|
|
|
* all copies or substantial portions of the Software. |
24
|
|
|
* |
25
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
26
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
27
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
28
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
29
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
30
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
31
|
|
|
* THE SOFTWARE. |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
namespace Esi\Utility\Tests\Enums\Http; |
35
|
|
|
|
36
|
|
|
use Esi\Utility\Enums\Http\StatusCodes; |
37
|
|
|
use PHPUnit\Framework\TestCase; |
38
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* StatusCodes enum tests. |
42
|
|
|
*/ |
43
|
|
|
#[CoversClass(StatusCodes::class)] |
44
|
|
|
class StatusCodesTest extends TestCase |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* Holds all cases of the StatusCodes enum. |
48
|
|
|
* |
49
|
|
|
* @var array<int, StatusCodes> |
50
|
|
|
*/ |
51
|
|
|
protected array $codes; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Build the $codes array. |
55
|
|
|
*/ |
56
|
|
|
#[\Override] |
57
|
|
|
public function setUp(): void |
58
|
|
|
{ |
59
|
|
|
$this->codes = StatusCodes::cases(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Simple, perhaps unnecessary, test to make sure no empty values and all returned values are type int. |
64
|
|
|
*/ |
65
|
|
|
public function testNoneEmptyIsInt(): void |
66
|
|
|
{ |
67
|
|
|
self::assertNotEmpty($this->codes); |
68
|
|
|
|
69
|
|
|
foreach ($this->codes as $code) { |
70
|
|
|
self::assertNotEmpty($code->getValue()); |
71
|
|
|
self::assertIsInt($code->getValue()); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Simple, perhaps unnecessary, test to make sure all returned values are within range of 100, 511. |
77
|
|
|
*/ |
78
|
|
|
public function testWithinRange(): void |
79
|
|
|
{ |
80
|
|
|
self::assertNotEmpty($this->codes); |
81
|
|
|
|
82
|
|
|
foreach ($this->codes as $code) { |
83
|
|
|
self::assertGreaterThanOrEqual(100, $code->getValue()); |
84
|
|
|
self::assertLessThanOrEqual(511, $code->getValue()); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Test the getMessage() method. |
90
|
|
|
*/ |
91
|
|
|
public function testGetMessage(): void |
92
|
|
|
{ |
93
|
|
|
self::assertNotEmpty($this->codes); |
94
|
|
|
|
95
|
|
|
foreach ($this->codes as $code) { |
96
|
|
|
self::assertNotEmpty($code->getMessage()); |
97
|
|
|
self::assertIsString($code->getMessage()); |
98
|
|
|
self::assertSame(match ($code->getName()) { |
99
|
|
|
'Non_Authoritative_Information' => 'Non-authoritative Information', |
100
|
|
|
'Multi_Status' => 'Multi-Status', |
101
|
|
|
'Im_A_Teapot' => "I'm A Teapot", |
102
|
|
|
'Request_URI_Too_Long' => 'Request-URI Too Long', |
103
|
|
|
default => str_replace('_', ' ', $code->getName()), |
104
|
|
|
}, $code->getMessage()); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Test the getCategory() method. |
110
|
|
|
*/ |
111
|
|
|
public function testGetCategory(): void |
112
|
|
|
{ |
113
|
|
|
self::assertNotEmpty($this->codes); |
114
|
|
|
|
115
|
|
|
foreach ($this->codes as $code) { |
116
|
|
|
self::assertSame(str_replace(' ', '', $code->getCategory()->getValue()), $code->getCategory()->getName()); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|