Skip to content

Commit 41b4747

Browse files
committed
apply fluent api
1 parent 85639d3 commit 41b4747

File tree

8 files changed

+138
-125
lines changed

8 files changed

+138
-125
lines changed

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,9 @@ public function testSpoofing(): void
859859
*/
860860
public function testGetPostEmpty(): void
861861
{
862-
service('superglobals')->setPost('TEST', '5');
863-
service('superglobals')->setGet('TEST', '3');
862+
service('superglobals')
863+
->setPost('TEST', '5')
864+
->setGet('TEST', '3');
864865

865866
$this->assertSame(['TEST' => '5'], $this->request->getPostGet());
866867
$this->assertSame(['TEST' => '3'], $this->request->getGetPost());
@@ -882,8 +883,9 @@ public function testGetPostSecondStream(): void
882883

883884
public function testGetPostSecondStreams(): void
884885
{
885-
service('superglobals')->setGet('get', '3');
886-
service('superglobals')->setPost('post', '5');
886+
service('superglobals')
887+
->setGet('get', '3')
888+
->setPost('post', '5');
887889

888890
$this->assertSame(['get' => '3', 'post' => '5'], $this->request->getPostGet());
889891
$this->assertSame(['post' => '5', 'get' => '3'], $this->request->getGetPost());
@@ -910,8 +912,9 @@ public function testGetBodyWithZero(): void
910912
*/
911913
public function testGetPostIndexNotExists(): void
912914
{
913-
service('superglobals')->setPost('TEST', '5');
914-
service('superglobals')->setGet('TEST', '3');
915+
service('superglobals')
916+
->setPost('TEST', '5')
917+
->setGet('TEST', '3');
915918
$this->assertNull($this->request->getPostGet('gc'));
916919
$this->assertNull($this->request->getGetPost('gc'));
917920
}
@@ -950,8 +953,9 @@ public function testGetIPAddressNormal(): void
950953
public function testGetIPAddressThruProxy(): void
951954
{
952955
$expected = '123.123.123.123';
953-
service('superglobals')->setServer('HTTP_X_FORWARDED_FOR', $expected);
954-
service('superglobals')->setServer('REMOTE_ADDR', '10.0.1.200');
956+
service('superglobals')
957+
->setServer('HTTP_X_FORWARDED_FOR', $expected)
958+
->setServer('REMOTE_ADDR', '10.0.1.200');
955959

956960
$config = new App();
957961
$config->proxyIPs = [
@@ -969,8 +973,9 @@ public function testGetIPAddressThruProxy(): void
969973
public function testGetIPAddressThruProxyIPv6(): void
970974
{
971975
$expected = '123.123.123.123';
972-
service('superglobals')->setServer('HTTP_X_FORWARDED_FOR', $expected);
973-
service('superglobals')->setServer('REMOTE_ADDR', '2001:db8::2:1');
976+
service('superglobals')
977+
->setServer('HTTP_X_FORWARDED_FOR', $expected)
978+
->setServer('REMOTE_ADDR', '2001:db8::2:1');
974979

975980
$config = new App();
976981
$config->proxyIPs = [

tests/system/HTTP/RequestTest.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ protected function setUp(): void
4141

4242
public function testFetchGlobalsSingleValue(): void
4343
{
44-
service('superglobals')->setPost('foo', 'bar');
45-
service('superglobals')->setGet('bar', 'baz');
44+
service('superglobals')
45+
->setPost('foo', 'bar')
46+
->setGet('bar', 'baz');
4647

4748
$this->assertSame('bar', $this->request->fetchGlobal('post', 'foo'));
4849
$this->assertSame('baz', $this->request->fetchGlobal('get', 'bar'));
@@ -569,8 +570,9 @@ public function testGetIPAddressNormal(): void
569570
public function testGetIPAddressThruProxy(): void
570571
{
571572
$expected = '123.123.123.123';
572-
service('superglobals')->setServer('REMOTE_ADDR', '10.0.1.200');
573-
service('superglobals')->setServer('HTTP_X_FORWARDED_FOR', $expected);
573+
service('superglobals')
574+
->setServer('REMOTE_ADDR', '10.0.1.200')
575+
->setServer('HTTP_X_FORWARDED_FOR', $expected);
574576

575577
$config = new App();
576578
$config->proxyIPs = [
@@ -588,8 +590,9 @@ public function testGetIPAddressThruProxy(): void
588590
public function testGetIPAddressThruProxyInvalid(): void
589591
{
590592
$expected = '123.456.23.123';
591-
service('superglobals')->setServer('REMOTE_ADDR', '10.0.1.200');
592-
service('superglobals')->setServer('HTTP_X_FORWARDED_FOR', $expected);
593+
service('superglobals')
594+
->setServer('REMOTE_ADDR', '10.0.1.200')
595+
->setServer('HTTP_X_FORWARDED_FOR', $expected);
593596
$config = new App();
594597
$config->proxyIPs = [
595598
'10.0.1.200' => 'X-Forwarded-For',
@@ -606,8 +609,9 @@ public function testGetIPAddressThruProxyInvalid(): void
606609
public function testGetIPAddressThruProxyNotWhitelisted(): void
607610
{
608611
$expected = '123.456.23.123';
609-
service('superglobals')->setServer('REMOTE_ADDR', '10.10.1.200');
610-
service('superglobals')->setServer('HTTP_X_FORWARDED_FOR', $expected);
612+
service('superglobals')
613+
->setServer('REMOTE_ADDR', '10.10.1.200')
614+
->setServer('HTTP_X_FORWARDED_FOR', $expected);
611615

612616
$config = new App();
613617
$config->proxyIPs = [
@@ -624,8 +628,9 @@ public function testGetIPAddressThruProxyNotWhitelisted(): void
624628
public function testGetIPAddressThruProxySubnet(): void
625629
{
626630
$expected = '123.123.123.123';
627-
service('superglobals')->setServer('REMOTE_ADDR', '192.168.5.21');
628-
service('superglobals')->setServer('HTTP_X_FORWARDED_FOR', $expected);
631+
service('superglobals')
632+
->setServer('REMOTE_ADDR', '192.168.5.21')
633+
->setServer('HTTP_X_FORWARDED_FOR', $expected);
629634

630635
$config = new App();
631636
$config->proxyIPs = ['192.168.5.0/24' => 'X-Forwarded-For'];
@@ -640,8 +645,9 @@ public function testGetIPAddressThruProxySubnet(): void
640645
public function testGetIPAddressThruProxyOutofSubnet(): void
641646
{
642647
$expected = '123.123.123.123';
643-
service('superglobals')->setServer('REMOTE_ADDR', '192.168.5.21');
644-
service('superglobals')->setServer('HTTP_X_FORWARDED_FOR', $expected);
648+
service('superglobals')
649+
->setServer('REMOTE_ADDR', '192.168.5.21')
650+
->setServer('HTTP_X_FORWARDED_FOR', $expected);
645651

646652
$config = new App();
647653
$config->proxyIPs = ['192.168.5.0/28' => 'X-Forwarded-For'];

tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ private function createSiteURIFactory(array $server, ?App $appConfig = null): Si
4949
public function testDefault(): void
5050
{
5151
// /index.php/woot?code=good#pos
52-
service('superglobals')->setServer('REQUEST_URI', '/index.php/woot');
53-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
52+
service('superglobals')
53+
->setServer('REQUEST_URI', '/index.php/woot')
54+
->setServer('SCRIPT_NAME', '/index.php');
5455

5556
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
5657

@@ -61,8 +62,9 @@ public function testDefault(): void
6162
public function testDefaultEmpty(): void
6263
{
6364
// /
64-
service('superglobals')->setServer('REQUEST_URI', '/');
65-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
65+
service('superglobals')
66+
->setServer('REQUEST_URI', '/')
67+
->setServer('SCRIPT_NAME', '/index.php');
6668

6769
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
6870

@@ -73,8 +75,9 @@ public function testDefaultEmpty(): void
7375
public function testRequestURI(): void
7476
{
7577
// /index.php/woot?code=good#pos
76-
service('superglobals')->setServer('REQUEST_URI', '/index.php/woot');
77-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
78+
service('superglobals')
79+
->setServer('REQUEST_URI', '/index.php/woot')
80+
->setServer('SCRIPT_NAME', '/index.php');
7881

7982
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
8083

@@ -93,8 +96,9 @@ public function testRequestURINested(): void
9396
// So I don't remove this test case.
9497

9598
// /ci/index.php/woot?code=good#pos
96-
service('superglobals')->setServer('REQUEST_URI', '/index.php/woot');
97-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
99+
service('superglobals')
100+
->setServer('REQUEST_URI', '/index.php/woot')
101+
->setServer('SCRIPT_NAME', '/index.php');
98102

99103
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
100104

@@ -105,8 +109,9 @@ public function testRequestURINested(): void
105109
public function testRequestURISubfolder(): void
106110
{
107111
// /ci/index.php/popcorn/woot?code=good#pos
108-
service('superglobals')->setServer('REQUEST_URI', '/ci/index.php/popcorn/woot');
109-
service('superglobals')->setServer('SCRIPT_NAME', '/ci/index.php');
112+
service('superglobals')
113+
->setServer('REQUEST_URI', '/ci/index.php/popcorn/woot')
114+
->setServer('SCRIPT_NAME', '/ci/index.php');
110115

111116
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
112117

@@ -117,8 +122,9 @@ public function testRequestURISubfolder(): void
117122
public function testRequestURINoIndex(): void
118123
{
119124
// /sub/example
120-
service('superglobals')->setServer('REQUEST_URI', '/sub/example');
121-
service('superglobals')->setServer('SCRIPT_NAME', '/sub/index.php');
125+
service('superglobals')
126+
->setServer('REQUEST_URI', '/sub/example')
127+
->setServer('SCRIPT_NAME', '/sub/index.php');
122128

123129
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
124130

@@ -129,8 +135,9 @@ public function testRequestURINoIndex(): void
129135
public function testRequestURINginx(): void
130136
{
131137
// /ci/index.php/woot?code=good#pos
132-
service('superglobals')->setServer('REQUEST_URI', '/index.php/woot?code=good');
133-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
138+
service('superglobals')
139+
->setServer('REQUEST_URI', '/index.php/woot?code=good')
140+
->setServer('SCRIPT_NAME', '/index.php');
134141

135142
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
136143

@@ -141,8 +148,9 @@ public function testRequestURINginx(): void
141148
public function testRequestURINginxRedirecting(): void
142149
{
143150
// /?/ci/index.php/woot
144-
service('superglobals')->setServer('REQUEST_URI', '/?/ci/woot');
145-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
151+
service('superglobals')
152+
->setServer('REQUEST_URI', '/?/ci/woot')
153+
->setServer('SCRIPT_NAME', '/index.php');
146154

147155
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
148156

@@ -153,8 +161,9 @@ public function testRequestURINginxRedirecting(): void
153161
public function testRequestURISuppressed(): void
154162
{
155163
// /woot?code=good#pos
156-
service('superglobals')->setServer('REQUEST_URI', '/woot');
157-
service('superglobals')->setServer('SCRIPT_NAME', '/');
164+
service('superglobals')
165+
->setServer('REQUEST_URI', '/woot')
166+
->setServer('SCRIPT_NAME', '/');
158167

159168
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
160169

@@ -165,8 +174,9 @@ public function testRequestURISuppressed(): void
165174
public function testRequestURIGetPath(): void
166175
{
167176
// /index.php/fruits/banana
168-
service('superglobals')->setServer('REQUEST_URI', '/index.php/fruits/banana');
169-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
177+
service('superglobals')
178+
->setServer('REQUEST_URI', '/index.php/fruits/banana')
179+
->setServer('SCRIPT_NAME', '/index.php');
170180

171181
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
172182

@@ -176,8 +186,9 @@ public function testRequestURIGetPath(): void
176186
public function testRequestURIPathIsRelative(): void
177187
{
178188
// /sub/folder/index.php/fruits/banana
179-
service('superglobals')->setServer('REQUEST_URI', '/sub/folder/index.php/fruits/banana');
180-
service('superglobals')->setServer('SCRIPT_NAME', '/sub/folder/index.php');
189+
service('superglobals')
190+
->setServer('REQUEST_URI', '/sub/folder/index.php/fruits/banana')
191+
->setServer('SCRIPT_NAME', '/sub/folder/index.php');
181192

182193
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
183194

@@ -187,8 +198,9 @@ public function testRequestURIPathIsRelative(): void
187198
public function testRequestURIStoresDetectedPath(): void
188199
{
189200
// /fruits/banana
190-
service('superglobals')->setServer('REQUEST_URI', '/fruits/banana');
191-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
201+
service('superglobals')
202+
->setServer('REQUEST_URI', '/fruits/banana')
203+
->setServer('SCRIPT_NAME', '/index.php');
192204

193205
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
194206

@@ -199,8 +211,9 @@ public function testRequestURIStoresDetectedPath(): void
199211

200212
public function testRequestURIPathIsNeverRediscovered(): void
201213
{
202-
service('superglobals')->setServer('REQUEST_URI', '/fruits/banana');
203-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
214+
service('superglobals')
215+
->setServer('REQUEST_URI', '/fruits/banana')
216+
->setServer('SCRIPT_NAME', '/index.php');
204217

205218
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
206219

@@ -213,11 +226,11 @@ public function testRequestURIPathIsNeverRediscovered(): void
213226
public function testQueryString(): void
214227
{
215228
// /index.php?/ci/woot
216-
service('superglobals')->setServer('REQUEST_URI', '/index.php?/ci/woot');
217-
service('superglobals')->setServer('QUERY_STRING', '/ci/woot');
218-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
219-
220-
service('superglobals')->setGet('/ci/woot', '');
229+
service('superglobals')
230+
->setServer('REQUEST_URI', '/index.php?/ci/woot')
231+
->setServer('QUERY_STRING', '/ci/woot')
232+
->setServer('SCRIPT_NAME', '/index.php')
233+
->setGet('/ci/woot', '');
221234

222235
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
223236

@@ -228,11 +241,11 @@ public function testQueryString(): void
228241
public function testQueryStringWithQueryString(): void
229242
{
230243
// /index.php?/ci/woot?code=good#pos
231-
service('superglobals')->setServer('REQUEST_URI', '/index.php?/ci/woot?code=good');
232-
service('superglobals')->setServer('QUERY_STRING', '/ci/woot?code=good');
233-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
234-
235-
service('superglobals')->setGet('/ci/woot?code', 'good');
244+
service('superglobals')
245+
->setServer('REQUEST_URI', '/index.php?/ci/woot?code=good')
246+
->setServer('QUERY_STRING', '/ci/woot?code=good')
247+
->setServer('SCRIPT_NAME', '/index.php')
248+
->setGet('/ci/woot?code', 'good');
236249

237250
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
238251

@@ -245,8 +258,9 @@ public function testQueryStringWithQueryString(): void
245258
public function testQueryStringEmpty(): void
246259
{
247260
// /index.php?
248-
service('superglobals')->setServer('REQUEST_URI', '/index.php?');
249-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
261+
service('superglobals')
262+
->setServer('REQUEST_URI', '/index.php?')
263+
->setServer('SCRIPT_NAME', '/index.php');
250264

251265
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
252266

@@ -257,8 +271,9 @@ public function testQueryStringEmpty(): void
257271
public function testPathInfoUnset(): void
258272
{
259273
// /index.php/woot?code=good#pos
260-
service('superglobals')->setServer('REQUEST_URI', '/index.php/woot');
261-
service('superglobals')->setServer('SCRIPT_NAME', '/index.php');
274+
service('superglobals')
275+
->setServer('REQUEST_URI', '/index.php/woot')
276+
->setServer('SCRIPT_NAME', '/index.php');
262277

263278
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray());
264279

@@ -272,9 +287,10 @@ public function testPathInfoSubfolder(): void
272287
$appConfig->baseURL = 'http://localhost:8888/ci431/public/';
273288

274289
// http://localhost:8888/ci431/public/index.php/woot?code=good#pos
275-
service('superglobals')->setServer('PATH_INFO', '/woot');
276-
service('superglobals')->setServer('REQUEST_URI', '/ci431/public/index.php/woot?code=good');
277-
service('superglobals')->setServer('SCRIPT_NAME', '/ci431/public/index.php');
290+
service('superglobals')
291+
->setServer('PATH_INFO', '/woot')
292+
->setServer('REQUEST_URI', '/ci431/public/index.php/woot?code=good')
293+
->setServer('SCRIPT_NAME', '/ci431/public/index.php');
278294

279295
$factory = $this->createSiteURIFactory(service('superglobals')->getServerArray(), $appConfig);
280296

0 commit comments

Comments
 (0)