-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetTest.php
More file actions
231 lines (193 loc) · 5.28 KB
/
GetTest.php
File metadata and controls
231 lines (193 loc) · 5.28 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
/**
* @author : Jakiboy
* @package : FloatPHP
* @subpackage : Classes Http Component Tests
* @version : 1.5.x
* @copyright : (c) 2018 - 2025 Jihad Sinnaour <me@jihadsinnaour.com>
* @link : https://floatphp.com
* @license : MIT
*
* This file if a part of FloatPHP Framework.
*/
declare(strict_types=1);
namespace FloatPHP\Tests\Classes\Http;
use PHPUnit\Framework\TestCase;
use FloatPHP\Classes\Http\Get;
/**
* Get class tests.
*/
final class GetTest extends TestCase
{
protected function setUp(): void
{
// Clear GET data before each test
$_GET = [];
}
protected function tearDown(): void
{
// Clear GET data after each test
$_GET = [];
}
/**
* Test get GET value.
*/
public function testGetValue(): void
{
$_GET['test_key'] = 'test_value';
$value = Get::get('test_key');
$this->assertEquals('test_value', $value);
}
/**
* Test get all GET values.
*/
public function testGetAllValues(): void
{
$_GET['key1'] = 'value1';
$_GET['key2'] = 'value2';
$values = Get::get();
$this->assertIsArray($values);
$this->assertEquals('value1', $values['key1']);
$this->assertEquals('value2', $values['key2']);
}
/**
* Test get non-existent GET value.
*/
public function testGetNonExistentValue(): void
{
$value = Get::get('non_existent');
$this->assertNull($value);
}
/**
* Test get when no GET values exist.
*/
public function testGetWhenNoValuesExist(): void
{
$values = Get::get();
$this->assertNull($values);
}
/**
* Test set GET value.
*/
public function testSetValue(): void
{
Get::set('new_key', 'new_value');
$this->assertEquals('new_value', $_GET['new_key']);
}
/**
* Test set GET value with null.
*/
public function testSetValueWithNull(): void
{
Get::set('null_key');
$this->assertNull($_GET['null_key']);
}
/**
* Test set GET value with different types.
*/
public function testSetValueWithDifferentTypes(): void
{
Get::set('string_key', 'string_value');
Get::set('int_key', 123);
Get::set('bool_key', true);
Get::set('array_key', ['nested' => 'value']);
$this->assertEquals('string_value', $_GET['string_key']);
$this->assertEquals(123, $_GET['int_key']);
$this->assertTrue($_GET['bool_key']);
$this->assertIsArray($_GET['array_key']);
}
/**
* Test check if GET value is set.
*/
public function testIsSetted(): void
{
$_GET['test_key'] = 'test_value';
$this->assertTrue(Get::isSet('test_key'));
$this->assertFalse(Get::isSet('non_existent'));
}
/**
* Test check if any GET values are set.
*/
public function testIsSettedAny(): void
{
$this->assertFalse(Get::isSet());
$_GET['test_key'] = 'test_value';
$this->assertTrue(Get::isSet());
}
/**
* Test unset specific GET value.
*/
public function testUnsetSpecificValue(): void
{
$_GET['key1'] = 'value1';
$_GET['key2'] = 'value2';
Get::unset('key1');
$this->assertFalse(isset($_GET['key1']));
$this->assertTrue(isset($_GET['key2']));
}
/**
* Test unset all GET values.
*/
public function testUnsetAllValues(): void
{
$_GET['key1'] = 'value1';
$_GET['key2'] = 'value2';
Get::unset();
$this->assertEmpty($_GET);
}
/**
* Test GET value with empty string.
*/
public function testGetValueWithEmptyString(): void
{
$_GET['empty_key'] = '';
$value = Get::get('empty_key');
$this->assertEquals('', $value);
$this->assertTrue(Get::isSet('empty_key'));
}
/**
* Test GET value with zero.
*/
public function testGetValueWithZero(): void
{
$_GET['zero_key'] = 0;
$value = Get::get('zero_key');
$this->assertEquals(0, $value);
$this->assertTrue(Get::isSet('zero_key'));
}
/**
* Test GET value with false.
*/
public function testGetValueWithFalse(): void
{
$_GET['false_key'] = false;
$value = Get::get('false_key');
$this->assertFalse($value);
$this->assertTrue(Get::isSet('false_key'));
}
/**
* Test overwrite existing GET value.
*/
public function testOverwriteExistingValue(): void
{
$_GET['existing_key'] = 'old_value';
Get::set('existing_key', 'new_value');
$this->assertEquals('new_value', $_GET['existing_key']);
}
/**
* Test complex array structure.
*/
public function testComplexArrayStructure(): void
{
$complex = [
'level1' => [
'level2' => [
'level3' => 'deep_value'
]
]
];
Get::set('complex_key', $complex);
$retrieved = Get::get('complex_key');
$this->assertEquals('deep_value', $retrieved['level1']['level2']['level3']);
}
}