diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php index fe478105d43b..90e6c7d57e90 100644 --- a/tests/system/HTTP/IncomingRequestTest.php +++ b/tests/system/HTTP/IncomingRequestTest.php @@ -29,7 +29,6 @@ use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\Attributes\WithoutErrorHandler; -use TypeError; /** * @internal @@ -38,7 +37,7 @@ #[Group('SeparateProcess')] final class IncomingRequestTest extends CIUnitTestCase { - private Request $request; + private IncomingRequest $request; #[WithoutErrorHandler] protected function setUp(): void @@ -59,7 +58,7 @@ protected function setUp(): void $this->request = $this->createRequest($config); } - private function createRequest(?App $config = null, $body = null, ?string $path = null): IncomingRequest + private function createRequest(?App $config = null, false|string|null $body = null, ?string $path = null): IncomingRequest { $config ??= new App(); $path ??= ''; @@ -635,6 +634,9 @@ public function testCanGrabGetRawInputVar($rawstring, $var, $expected, $filter, $this->assertSame($expected, $request->getRawInputVar($var, $filter, $flag)); } + /** + * @return iterable + */ public static function provideCanGrabGetRawInputVar(): iterable { return [ @@ -729,6 +731,9 @@ public function testIsHTTPMethodLowerCase(string $value): void $this->assertTrue($request->is(strtolower($value))); } + /** + * @return iterable + */ public static function provideIsHTTPMethods(): iterable { yield from [ @@ -756,7 +761,6 @@ public function testIsInvalidValue(): void $this->expectExceptionMessage('Unknown type: invalid'); $request = $this->request->withMethod('GET'); - $request->is('invalid'); } @@ -764,6 +768,7 @@ public function testIsJson(): void { $request = $this->request->setHeader('Content-Type', 'application/json'); + $this->assertInstanceOf(IncomingRequest::class, $request); $this->assertTrue($request->is('json')); } @@ -771,6 +776,7 @@ public function testIsWithAjax(): void { $request = $this->request->setHeader('X-Requested-With', 'XMLHttpRequest'); + $this->assertInstanceOf(IncomingRequest::class, $request); $this->assertTrue($request->is('ajax')); } @@ -950,6 +956,7 @@ public function testGetFile(): void ]); $gotit = $this->request->getFile('userfile'); + $this->assertInstanceOf(UploadedFile::class, $gotit); $this->assertSame(124, $gotit->getSize()); } @@ -1047,12 +1054,12 @@ public function testGetIPAddressNormal(): void $expected = '123.123.123.123'; service('superglobals')->setServer('REMOTE_ADDR', $expected); - $this->request = new Request(new App()); - $this->request->populateHeaders(); + $request = new Request(new App()); + $request->populateHeaders(); - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); // call a second time to exercise the initial conditional block in getIPAddress() - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxy(): void @@ -1068,11 +1075,11 @@ public function testGetIPAddressThruProxy(): void '192.168.5.0/24' => 'X-Forwarded-For', ]; Factories::injectMock('config', App::class, $config); - $this->request = new Request(); - $this->request->populateHeaders(); + $request = new Request(); + $request->populateHeaders(); // we should see the original forwarded address - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxyIPv6(): void @@ -1087,11 +1094,11 @@ public function testGetIPAddressThruProxyIPv6(): void '2001:db8::2:1' => 'X-Forwarded-For', ]; Factories::injectMock('config', App::class, $config); - $this->request = new Request(); - $this->request->populateHeaders(); + $request = new Request(); + $request->populateHeaders(); // we should see the original forwarded address - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxyInvalidIPAddress(): void @@ -1105,11 +1112,11 @@ public function testGetIPAddressThruProxyInvalidIPAddress(): void '10.0.1.200' => 'X-Forwarded-For', '192.168.5.0/24' => 'X-Forwarded-For', ]; - $this->request = new Request($config); - $this->request->populateHeaders(); + $request = new Request($config); + $request->populateHeaders(); // spoofed address invalid - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxyInvalidIPAddressIPv6(): void @@ -1122,11 +1129,11 @@ public function testGetIPAddressThruProxyInvalidIPAddressIPv6(): void $config->proxyIPs = [ '2001:db8::2:1' => 'X-Forwarded-For', ]; - $this->request = new Request($config); - $this->request->populateHeaders(); + $request = new Request($config); + $request->populateHeaders(); // spoofed address invalid - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxyNotWhitelisted(): void @@ -1140,11 +1147,11 @@ public function testGetIPAddressThruProxyNotWhitelisted(): void '10.0.1.200' => 'X-Forwarded-For', '192.168.5.0/24' => 'X-Forwarded-For', ]; - $this->request = new Request($config); - $this->request->populateHeaders(); + $request = new Request($config); + $request->populateHeaders(); // spoofed address invalid - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxyNotWhitelistedIPv6(): void @@ -1157,11 +1164,11 @@ public function testGetIPAddressThruProxyNotWhitelistedIPv6(): void $config->proxyIPs = [ '2001:db8::2:1' => 'X-Forwarded-For', ]; - $this->request = new Request($config); - $this->request->populateHeaders(); + $request = new Request($config); + $request->populateHeaders(); // spoofed address invalid - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxySubnet(): void @@ -1173,11 +1180,11 @@ public function testGetIPAddressThruProxySubnet(): void $config = new App(); $config->proxyIPs = ['192.168.5.0/24' => 'X-Forwarded-For']; Factories::injectMock('config', App::class, $config); - $this->request = new Request(); - $this->request->populateHeaders(); + $request = new Request(); + $request->populateHeaders(); // we should see the original forwarded address - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxySubnetIPv6(): void @@ -1189,11 +1196,11 @@ public function testGetIPAddressThruProxySubnetIPv6(): void $config = new App(); $config->proxyIPs = ['2001:db8:1234::/48' => 'X-Forwarded-For']; Factories::injectMock('config', App::class, $config); - $this->request = new Request(); - $this->request->populateHeaders(); + $request = new Request(); + $request->populateHeaders(); // we should see the original forwarded address - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxyOutOfSubnet(): void @@ -1204,11 +1211,11 @@ public function testGetIPAddressThruProxyOutOfSubnet(): void $config = new App(); $config->proxyIPs = ['192.168.5.0/28' => 'X-Forwarded-For']; - $this->request = new Request($config); - $this->request->populateHeaders(); + $request = new Request($config); + $request->populateHeaders(); // we should see the original forwarded address - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxyOutOfSubnetIPv6(): void @@ -1219,11 +1226,11 @@ public function testGetIPAddressThruProxyOutOfSubnetIPv6(): void $config = new App(); $config->proxyIPs = ['2001:db8:1234::/48' => 'X-Forwarded-For']; - $this->request = new Request($config); - $this->request->populateHeaders(); + $request = new Request($config); + $request->populateHeaders(); // we should see the original forwarded address - $this->assertSame($expected, $this->request->getIPAddress()); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxyBothIPv4AndIPv6(): void @@ -1237,23 +1244,11 @@ public function testGetIPAddressThruProxyBothIPv4AndIPv6(): void '192.168.5.0/28' => 'X-Forwarded-For', '2001:db8:1234::/48' => 'X-Forwarded-For', ]; - $this->request = new Request($config); - $this->request->populateHeaders(); + $request = new Request($config); + $request->populateHeaders(); // we should see the original forwarded address - $this->assertSame($expected, $this->request->getIPAddress()); - } - - public function testGetIPAddressThruProxyInvalidConfigString(): void - { - $this->expectException(TypeError::class); - - $config = new App(); - $config->proxyIPs = '192.168.5.0/28'; - $this->request = new Request($config); - $this->request->populateHeaders(); - - $this->request->getIPAddress(); + $this->assertSame($expected, $request->getIPAddress()); } public function testGetIPAddressThruProxyInvalidConfigArray(): void @@ -1264,12 +1259,12 @@ public function testGetIPAddressThruProxyInvalidConfigArray(): void ); $config = new App(); - $config->proxyIPs = ['192.168.5.0/28']; + $config->proxyIPs = ['192.168.5.0/28']; // @phpstan-ignore assign.propertyType (deliberately keyless, to assert the ConfigException) Factories::injectMock('config', App::class, $config); - $this->request = new Request(); - $this->request->populateHeaders(); + $request = new Request(); + $request->populateHeaders(); - $this->request->getIPAddress(); + $request->getIPAddress(); } // @TODO getIPAddress should have more testing, to 100% code coverage diff --git a/utils/phpstan-baseline/assign.propertyType.neon b/utils/phpstan-baseline/assign.propertyType.neon index e0569c49cd73..e782ea998087 100644 --- a/utils/phpstan-baseline/assign.propertyType.neon +++ b/utils/phpstan-baseline/assign.propertyType.neon @@ -1,4 +1,4 @@ -# total 28 errors +# total 26 errors parameters: ignoreErrors: @@ -57,16 +57,6 @@ parameters: count: 4 path: ../../tests/system/Filters/HoneypotTest.php - - - message: '#^Property Config\\App\:\:\$proxyIPs \(array\\) does not accept array\\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Property Config\\App\:\:\$proxyIPs \(array\\) does not accept string\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - message: '#^Property CodeIgniter\\Helpers\\CookieHelperTest\:\:\$response \(CodeIgniter\\HTTP\\Response\) does not accept CodeIgniter\\HTTP\\ResponseInterface\.$#' count: 1 diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 58a8f091d28e..57a1c5ee9257 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 1434 errors +# total 1381 errors includes: - argument.type.neon diff --git a/utils/phpstan-baseline/method.notFound.neon b/utils/phpstan-baseline/method.notFound.neon index 8ced93d9ad27..f0497ca809ae 100644 --- a/utils/phpstan-baseline/method.notFound.neon +++ b/utils/phpstan-baseline/method.notFound.neon @@ -1,4 +1,4 @@ -# total 80 errors +# total 33 errors parameters: ignoreErrors: @@ -42,91 +42,6 @@ parameters: count: 3 path: ../../tests/system/Debug/ExceptionHandlerTest.php - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getCookie\(\)\.$#' - count: 2 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getDefaultLocale\(\)\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getFileMultiple\(\)\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getFile\(\)\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getFiles\(\)\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getGetPost\(\)\.$#' - count: 6 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getGet\(\)\.$#' - count: 2 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getLocale\(\)\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getOldInput\(\)\.$#' - count: 9 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getPostGet\(\)\.$#' - count: 6 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getPost\(\)\.$#' - count: 2 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:getVar\(\)\.$#' - count: 2 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:isAJAX\(\)\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:isCLI\(\)\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:isSecure\(\)\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:is\(\)\.$#' - count: 5 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\Request\:\:negotiate\(\)\.$#' - count: 5 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - message: '#^Call to an undefined method CodeIgniter\\HTTP\\URI\:\:getRoutePath\(\)\.$#' count: 1 diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index dd6c35e453d0..518e931c13d8 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 1131 errors +# total 1129 errors parameters: ignoreErrors: @@ -4467,16 +4467,6 @@ parameters: count: 1 path: ../../tests/system/Filters/InvalidCharsTest.php - - - message: '#^Method CodeIgniter\\HTTP\\IncomingRequestTest\:\:provideCanGrabGetRawInputVar\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Method CodeIgniter\\HTTP\\IncomingRequestTest\:\:provideIsHTTPMethods\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - message: '#^Method CodeIgniter\\HTTP\\MessageTest\:\:provideArrayHeaderValue\(\) return type has no value type specified in iterable type iterable\.$#' count: 1 diff --git a/utils/phpstan-baseline/missingType.parameter.neon b/utils/phpstan-baseline/missingType.parameter.neon index 3512e2769b9f..0e1decdda219 100644 --- a/utils/phpstan-baseline/missingType.parameter.neon +++ b/utils/phpstan-baseline/missingType.parameter.neon @@ -1,4 +1,4 @@ -# total 31 errors +# total 30 errors parameters: ignoreErrors: @@ -72,11 +72,6 @@ parameters: count: 1 path: ../../tests/system/HTTP/Files/FileMovingTest.php - - - message: '#^Method CodeIgniter\\HTTP\\IncomingRequestTest\:\:createRequest\(\) has parameter \$body with no type specified\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - message: '#^Method CodeIgniter\\Helpers\\URLHelper\\CurrentUrlTest\:\:createRequest\(\) has parameter \$body with no type specified\.$#' count: 1