Skip to content

Commit 38a2e4d

Browse files
committed
test: update test code
1 parent fe0b5f5 commit 38a2e4d

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

tests/system/HTTP/IncomingRequestTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\HTTP;
1313

14+
use CodeIgniter\Config\Factories;
1415
use CodeIgniter\Exceptions\ConfigException;
1516
use CodeIgniter\HTTP\Exceptions\HTTPException;
1617
use CodeIgniter\HTTP\Files\UploadedFile;
@@ -973,7 +974,8 @@ public function testGetIPAddressThruProxy()
973974
'10.0.1.200' => 'X-Forwarded-For',
974975
'192.168.5.0/24' => 'X-Forwarded-For',
975976
];
976-
$this->request = new Request($config);
977+
Factories::injectMock('config', App::class, $config);
978+
$this->request = new Request();
977979
$this->request->populateHeaders();
978980

979981
// we should see the original forwarded address
@@ -990,7 +992,8 @@ public function testGetIPAddressThruProxyIPv6()
990992
$config->proxyIPs = [
991993
'2001:db8::2:1' => 'X-Forwarded-For',
992994
];
993-
$this->request = new Request($config);
995+
Factories::injectMock('config', App::class, $config);
996+
$this->request = new Request();
994997
$this->request->populateHeaders();
995998

996999
// we should see the original forwarded address
@@ -1075,7 +1078,8 @@ public function testGetIPAddressThruProxySubnet()
10751078

10761079
$config = new App();
10771080
$config->proxyIPs = ['192.168.5.0/24' => 'X-Forwarded-For'];
1078-
$this->request = new Request($config);
1081+
Factories::injectMock('config', App::class, $config);
1082+
$this->request = new Request();
10791083
$this->request->populateHeaders();
10801084

10811085
// we should see the original forwarded address
@@ -1090,7 +1094,8 @@ public function testGetIPAddressThruProxySubnetIPv6()
10901094

10911095
$config = new App();
10921096
$config->proxyIPs = ['2001:db8:1234::/48' => 'X-Forwarded-For'];
1093-
$this->request = new Request($config);
1097+
Factories::injectMock('config', App::class, $config);
1098+
$this->request = new Request();
10941099
$this->request->populateHeaders();
10951100

10961101
// we should see the original forwarded address
@@ -1166,7 +1171,8 @@ public function testGetIPAddressThruProxyInvalidConfigArray()
11661171

11671172
$config = new App();
11681173
$config->proxyIPs = ['192.168.5.0/28'];
1169-
$this->request = new Request($config);
1174+
Factories::injectMock('config', App::class, $config);
1175+
$this->request = new Request();
11701176
$this->request->populateHeaders();
11711177

11721178
$this->request->getIPAddress();

tests/system/HTTP/RequestTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\HTTP;
1313

14+
use CodeIgniter\Config\Factories;
1415
use CodeIgniter\Test\CIUnitTestCase;
1516
use Config\App;
1617

@@ -616,7 +617,8 @@ public function testGetIPAddressThruProxy()
616617
'10.0.1.200' => 'X-Forwarded-For',
617618
'192.168.5.0/24' => 'X-Forwarded-For',
618619
];
619-
$this->request = new Request($config);
620+
Factories::injectMock('config', App::class, $config);
621+
$this->request = new Request();
620622
$this->request->populateHeaders();
621623

622624
// we should see the original forwarded address
@@ -667,7 +669,8 @@ public function testGetIPAddressThruProxySubnet()
667669

668670
$config = new App();
669671
$config->proxyIPs = ['192.168.5.0/24' => 'X-Forwarded-For'];
670-
$this->request = new Request($config);
672+
Factories::injectMock('config', App::class, $config);
673+
$this->request = new Request();
671674
$this->request->populateHeaders();
672675

673676
// we should see the original forwarded address

0 commit comments

Comments
 (0)