diff --git a/system/Config/Services.php b/system/Config/Services.php index 3878911c8cbf..6e641b4e1d28 100644 --- a/system/Config/Services.php +++ b/system/Config/Services.php @@ -198,6 +198,8 @@ public static function csp(?CSPConfig $config = null, bool $getShared = true) * The CURL Request class acts as a simple HTTP client for interacting * with other servers, typically through APIs. * + * @todo v4.8.0 Remove $config parameter since unused + * * @return CURLRequest */ public static function curlrequest(array $options = [], ?ResponseInterface $response = null, ?App $config = null, bool $getShared = true) @@ -207,7 +209,7 @@ public static function curlrequest(array $options = [], ?ResponseInterface $resp } $config ??= config(App::class); - $response ??= new Response($config); + $response ??= new Response(); return new CURLRequest( $config, @@ -576,6 +578,8 @@ public static function incomingrequest(?App $config = null, bool $getShared = tr /** * The Response class models an HTTP response. * + * @todo v4.8.0 Remove $config parameter since unused + * * @return ResponseInterface */ public static function response(?App $config = null, bool $getShared = true) @@ -584,14 +588,14 @@ public static function response(?App $config = null, bool $getShared = true) return static::getSharedInstance('response', $config); } - $config ??= config(App::class); - - return new Response($config); + return new Response(); } /** * The Redirect class provides nice way of working with redirects. * + * @todo v4.8.0 Remove $config parameter since unused + * * @return RedirectResponse */ public static function redirectresponse(?App $config = null, bool $getShared = true) @@ -600,8 +604,7 @@ public static function redirectresponse(?App $config = null, bool $getShared = t return static::getSharedInstance('redirectresponse', $config); } - $config ??= config(App::class); - $response = new RedirectResponse($config); + $response = new RedirectResponse(); $response->setProtocolVersion(AppServices::get('request')->getProtocolVersion()); return $response; diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 29516a094a86..2f34c5d393fb 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -115,7 +115,11 @@ class CURLRequest extends OutgoingRequest * - timeout * - any other request options to use as defaults. * + * @todo v4.8.0 Remove $config parameter since unused + * * @param array $options + * + * @phpstan-ignore-next-line constructor.unusedParameter */ public function __construct(App $config, URI $uri, ?ResponseInterface $response = null, array $options = []) { @@ -125,7 +129,7 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response parent::__construct(Method::GET, $uri); - $this->responseOrig = $response ?? new Response($config); + $this->responseOrig = $response ?? new Response(); // Remove the default Content-Type header. $this->responseOrig->removeHeader('Content-Type'); diff --git a/system/HTTP/DownloadResponse.php b/system/HTTP/DownloadResponse.php index 4d0850ecc4d1..4273d8fe1413 100644 --- a/system/HTTP/DownloadResponse.php +++ b/system/HTTP/DownloadResponse.php @@ -15,7 +15,6 @@ use CodeIgniter\Exceptions\DownloadException; use CodeIgniter\Files\File; -use Config\App; use Config\Mimes; /** @@ -64,12 +63,9 @@ class DownloadResponse extends Response implements NonBufferedResponseInterface */ protected $statusCode = 200; - /** - * Constructor. - */ public function __construct(string $filename, bool $setMime) { - parent::__construct(config(App::class)); + parent::__construct(); $this->filename = $filename; $this->setMime = $setMime; diff --git a/system/HTTP/Response.php b/system/HTTP/Response.php index 3c59f2e9800d..0df154848f39 100644 --- a/system/HTTP/Response.php +++ b/system/HTTP/Response.php @@ -16,7 +16,6 @@ use CodeIgniter\Cookie\Cookie; use CodeIgniter\Cookie\CookieStore; use CodeIgniter\HTTP\Exceptions\HTTPException; -use Config\App; use Config\Cookie as CookieConfig; /** @@ -141,16 +140,7 @@ class Response extends Message implements ResponseInterface */ protected $pretend = false; - /** - * Constructor - * - * @param App $config - * - * @todo Recommend removing reliance on config injection - * - * @deprecated 4.5.0 The param $config is no longer used. - */ - public function __construct($config) // @phpstan-ignore-line + public function __construct() { // Default to a non-caching page. // Also ensures that a Cache-control header exists. diff --git a/system/HTTP/SSEResponse.php b/system/HTTP/SSEResponse.php index 7d41f6bb94f8..1137b8805283 100644 --- a/system/HTTP/SSEResponse.php +++ b/system/HTTP/SSEResponse.php @@ -14,7 +14,6 @@ namespace CodeIgniter\HTTP; use Closure; -use Config\App; use JsonException; /** @@ -31,7 +30,7 @@ class SSEResponse extends Response implements NonBufferedResponseInterface */ public function __construct(private readonly Closure $callback) { - parent::__construct(config(App::class)); + parent::__construct(); } /** diff --git a/tests/system/API/ResponseTraitTest.php b/tests/system/API/ResponseTraitTest.php index 432d254abd40..ef85f5f07988 100644 --- a/tests/system/API/ResponseTraitTest.php +++ b/tests/system/API/ResponseTraitTest.php @@ -112,7 +112,7 @@ private function createRequestAndResponse(string $routePath = '', array $userHea null, new UserAgent(), ); - $this->response = new MockResponse($config); + $this->response = new MockResponse(); } $headers = array_merge(['Accept' => 'text/html'], $userHeaders); @@ -625,7 +625,7 @@ public function testFormatByRequestNegotiateIfFormatIsNotJsonOrXML(): void $this->createCookieConfig(); $request = new MockIncomingRequest($config, new SiteURI($config), null, new UserAgent()); - $response = new MockResponse($config); + $response = new MockResponse(); $controller = new class ($request, $response) { use ResponseTrait; diff --git a/tests/system/Cache/ResponseCacheTest.php b/tests/system/Cache/ResponseCacheTest.php index a05d37d96f54..73cc3e5a7a78 100644 --- a/tests/system/Cache/ResponseCacheTest.php +++ b/tests/system/Cache/ResponseCacheTest.php @@ -87,7 +87,7 @@ public function testCachePageIncomingRequest(): void { $pageCache = $this->createResponseCache(); - $response = new Response(new App()); + $response = new Response(); $response->setHeader('ETag', 'abcd1234'); $response->setBody('The response body.'); @@ -97,7 +97,7 @@ public function testCachePageIncomingRequest(): void )); // Check cache with a request with the same URI path. - $cachedResponse = $pageCache->get($this->createIncomingRequest('foo/bar'), new Response(new App())); + $cachedResponse = $pageCache->get($this->createIncomingRequest('foo/bar'), new Response()); $this->assertInstanceOf(ResponseInterface::class, $cachedResponse); $this->assertSame('The response body.', $cachedResponse->getBody()); $this->assertSame('abcd1234', $cachedResponse->getHeaderLine('ETag')); @@ -105,14 +105,14 @@ public function testCachePageIncomingRequest(): void // Check cache with a request with the same URI path and different query string. $cachedResponse = $pageCache->get( $this->createIncomingRequest('foo/bar', ['foo' => 'bar', 'bar' => 'baz']), - new Response(new App()), + new Response(), ); $this->assertInstanceOf(ResponseInterface::class, $cachedResponse); $this->assertSame('The response body.', $cachedResponse->getBody()); $this->assertSame('abcd1234', $cachedResponse->getHeaderLine('ETag')); // Check cache with another request with the different URI path. - $cachedResponse = $pageCache->get($this->createIncomingRequest('another'), new Response(new App())); + $cachedResponse = $pageCache->get($this->createIncomingRequest('another'), new Response()); $this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse); } @@ -120,14 +120,14 @@ public function testCachePageIncomingRequestWithStatus(): void { $pageCache = $this->createResponseCache(); - $response = new Response(new App()); + $response = new Response(); $response->setStatusCode(432, 'Foo Bar'); $response->setBody('The response body.'); $this->assertTrue($pageCache->make($this->createIncomingRequest('foo/bar'), $response)); // Check cached response status - $cachedResponse = $pageCache->get($this->createIncomingRequest('foo/bar'), new Response(new App())); + $cachedResponse = $pageCache->get($this->createIncomingRequest('foo/bar'), new Response()); $this->assertInstanceOf(ResponseInterface::class, $cachedResponse); $this->assertSame(432, $cachedResponse->getStatusCode()); $this->assertSame('Foo Bar', $cachedResponse->getReasonPhrase()); @@ -143,7 +143,7 @@ public function testCachePageIncomingRequestWithCacheQueryString(): void $request = $this->createIncomingRequest('foo/bar', ['foo' => 'bar', 'bar' => 'baz']); - $response = new Response(new App()); + $response = new Response(); $response->setHeader('ETag', 'abcd1234'); $response->setBody('The response body.'); @@ -152,7 +152,7 @@ public function testCachePageIncomingRequestWithCacheQueryString(): void // Check cache with a request with the same URI path and same query string. $cachedResponse = $pageCache->get( $this->createIncomingRequest('foo/bar', ['foo' => 'bar', 'bar' => 'baz']), - new Response(new App()), + new Response(), ); $this->assertInstanceOf(ResponseInterface::class, $cachedResponse); $this->assertSame('The response body.', $cachedResponse->getBody()); @@ -161,12 +161,12 @@ public function testCachePageIncomingRequestWithCacheQueryString(): void // Check cache with a request with the same URI path and different query string. $cachedResponse = $pageCache->get( $this->createIncomingRequest('foo/bar', ['xfoo' => 'bar', 'bar' => 'baz']), - new Response(new App()), + new Response(), ); $this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse); // Check cache with another request with the different URI path. - $cachedResponse = $pageCache->get($this->createIncomingRequest('another'), new Response(new App())); + $cachedResponse = $pageCache->get($this->createIncomingRequest('another'), new Response()); $this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse); } @@ -174,7 +174,7 @@ public function testCachePageIncomingRequestWithHttpMethods(): void { $pageCache = $this->createResponseCache(); - $response = new Response(new App()); + $response = new Response(); $response->setBody('The response body.'); $this->assertTrue($pageCache->make($this->createIncomingRequest('foo/bar'), $response)); @@ -182,7 +182,7 @@ public function testCachePageIncomingRequestWithHttpMethods(): void // Check cache with a request with the same URI path and different HTTP method $cachedResponse = $pageCache->get( $this->createIncomingRequest('foo/bar')->withMethod('POST'), - new Response(new App()), + new Response(), ); $this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse); } @@ -191,18 +191,18 @@ public function testCachePageCLIRequest(): void { $pageCache = $this->createResponseCache(); - $response = new Response(new App()); + $response = new Response(); $response->setBody('The response body.'); $this->assertTrue($pageCache->make($this->createCLIRequest(['foo', 'bar']), $response)); // Check cache with a request with the same params. - $cachedResponse = $pageCache->get($this->createCLIRequest(['foo', 'bar']), new Response(new App())); + $cachedResponse = $pageCache->get($this->createCLIRequest(['foo', 'bar']), new Response()); $this->assertInstanceOf(ResponseInterface::class, $cachedResponse); $this->assertSame('The response body.', $cachedResponse->getBody()); // Check cache with another request with the different params. - $cachedResponse = $pageCache->get($this->createCLIRequest(['baz']), new Response(new App())); + $cachedResponse = $pageCache->get($this->createCLIRequest(['baz']), new Response()); $this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse); } @@ -217,7 +217,7 @@ public function testUnserializeError(): void $request = $this->createIncomingRequest('foo/bar'); - $response = new Response(new App()); + $response = new Response(); $response->setHeader('ETag', 'abcd1234'); $response->setBody('The response body.'); @@ -229,7 +229,7 @@ public function testUnserializeError(): void $mockCache->save($cacheKey, 'Invalid data'); // Check cache with a request with the same URI path. - $pageCache->get($request, new Response(new App())); + $pageCache->get($request, new Response()); } public function testInvalidCacheError(): void @@ -243,7 +243,7 @@ public function testInvalidCacheError(): void $request = $this->createIncomingRequest('foo/bar'); - $response = new Response(new App()); + $response = new Response(); $response->setHeader('ETag', 'abcd1234'); $response->setBody('The response body.'); @@ -255,6 +255,6 @@ public function testInvalidCacheError(): void $mockCache->save($cacheKey, serialize(['a' => '1'])); // Check cache with a request with the same URI path. - $pageCache->get($request, new Response(new App())); + $pageCache->get($request, new Response()); } } diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 7f79b07381fd..d437f985ebd5 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -448,7 +448,7 @@ public function testOldInput(): void 'zibble' => 'fritz', ]); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $response->withInput(); $this->assertSame('bar', old('foo')); // regular parameter @@ -482,7 +482,7 @@ public function testOldInputSerializeData(): void 'zibble' => serialize('fritz'), ]); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $response->withInput(); // serialized parameters are only HTML-escaped. @@ -522,7 +522,7 @@ public function testOldInputArray(): void $superglobals->setGetArray([]); $superglobals->setPostArray(['location' => $locations]); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $response->withInput(); $this->assertSame($locations, old('location')); diff --git a/tests/system/Config/ServicesTest.php b/tests/system/Config/ServicesTest.php index 7eef9818a727..0917ba79a8ca 100644 --- a/tests/system/Config/ServicesTest.php +++ b/tests/system/Config/ServicesTest.php @@ -46,7 +46,6 @@ use CodeIgniter\Validation\Validation; use CodeIgniter\View\Cell; use CodeIgniter\View\Parser; -use Config\App; use Config\Database as DatabaseConfig; use Config\Exceptions; use Config\Security as SecurityConfig; @@ -334,11 +333,11 @@ public function testCallStaticDirectly(): void #[RunInSeparateProcess] public function testMockInjection(): void { - Services::injectMock('response', new MockResponse(new App())); + Services::injectMock('response', new MockResponse()); $response = service('response'); $this->assertInstanceOf(MockResponse::class, $response); - Services::injectMock('response', new MockResponse(new App())); + Services::injectMock('response', new MockResponse()); $response2 = service('response'); $this->assertInstanceOf(MockResponse::class, $response2); @@ -354,13 +353,13 @@ public function testMockInjection(): void #[RunInSeparateProcess] public function testReset(): void { - Services::injectMock('response', new MockResponse(new App())); + Services::injectMock('response', new MockResponse()); $response = service('response'); $this->assertInstanceOf(MockResponse::class, $response); Services::reset(true); // reset mocks & shared instances - Services::injectMock('response', new MockResponse(new App())); + Services::injectMock('response', new MockResponse()); $response2 = service('response'); $this->assertInstanceOf(MockResponse::class, $response2); @@ -371,7 +370,7 @@ public function testReset(): void #[RunInSeparateProcess] public function testResetSingle(): void { - Services::injectMock('response', new MockResponse(new App())); + Services::injectMock('response', new MockResponse()); Services::injectMock('security', new MockSecurity(new SecurityConfig())); $response = service('response'); $security = service('security'); @@ -391,7 +390,7 @@ public function testResetSingle(): void public function testResetSingleCaseInsensitive(): void { - Services::injectMock('response', new MockResponse(new App())); + Services::injectMock('response', new MockResponse()); $someService = service('response'); $this->assertInstanceOf(MockResponse::class, $someService); @@ -404,7 +403,7 @@ public function testResetSingleCaseInsensitive(): void #[RunInSeparateProcess] public function testResetServiceCache(): void { - Services::injectMock('response', new MockResponse(new App())); + Services::injectMock('response', new MockResponse()); $response = service('response'); $this->assertInstanceOf(MockResponse::class, $response); service('response')->setStatusCode(200); diff --git a/tests/system/ControllerTest.php b/tests/system/ControllerTest.php index 113b02c14deb..6e012acfe570 100644 --- a/tests/system/ControllerTest.php +++ b/tests/system/ControllerTest.php @@ -59,7 +59,7 @@ protected function setUp(): void $config = new App(); $this->request = new IncomingRequest($config, new SiteURI($config), null, new UserAgent()); - $this->response = new Response($config); + $this->response = new Response(); $this->logger = service('logger'); } diff --git a/tests/system/Filters/PageCacheTest.php b/tests/system/Filters/PageCacheTest.php index baf46fc28cac..7a45cc3641be 100644 --- a/tests/system/Filters/PageCacheTest.php +++ b/tests/system/Filters/PageCacheTest.php @@ -48,21 +48,21 @@ public function testDefaultConfigCachesAllStatusCodes(): void $request = $this->createRequest(); - $response200 = new Response(new App()); + $response200 = new Response(); $response200->setStatusCode(200); $response200->setBody('Success'); $result = $filter->after($request, $response200); $this->assertInstanceOf(Response::class, $result); - $response404 = new Response(new App()); + $response404 = new Response(); $response404->setStatusCode(404); $response404->setBody('Not Found'); $result = $filter->after($request, $response404); $this->assertInstanceOf(Response::class, $result); - $response500 = new Response(new App()); + $response500 = new Response(); $response500->setStatusCode(500); $response500->setBody('Server Error'); @@ -79,7 +79,7 @@ public function testRestrictedConfigOnlyCaches200Responses(): void $request = $this->createRequest(); // Test 200 response - should be cached - $response200 = new Response(new App()); + $response200 = new Response(); $response200->setStatusCode(200); $response200->setBody('Success'); @@ -87,7 +87,7 @@ public function testRestrictedConfigOnlyCaches200Responses(): void $this->assertInstanceOf(Response::class, $result); // Test 404 response - should NOT be cached - $response404 = new Response(new App()); + $response404 = new Response(); $response404->setStatusCode(404); $response404->setBody('Not Found'); @@ -95,7 +95,7 @@ public function testRestrictedConfigOnlyCaches200Responses(): void $this->assertNotInstanceOf(ResponseInterface::class, $result); // Test 500 response - should NOT be cached - $response500 = new Response(new App()); + $response500 = new Response(); $response500->setStatusCode(500); $response500->setBody('Server Error'); @@ -111,21 +111,21 @@ public function testCustomCacheStatusCodes(): void $request = $this->createRequest(); - $response200 = new Response(new App()); + $response200 = new Response(); $response200->setStatusCode(200); $response200->setBody('Success'); $result = $filter->after($request, $response200); $this->assertInstanceOf(Response::class, $result); - $response404 = new Response(new App()); + $response404 = new Response(); $response404->setStatusCode(404); $response404->setBody('Not Found'); $result = $filter->after($request, $response404); $this->assertInstanceOf(Response::class, $result); - $response410 = new Response(new App()); + $response410 = new Response(); $response410->setStatusCode(410); $response410->setBody('Gone'); @@ -133,7 +133,7 @@ public function testCustomCacheStatusCodes(): void $this->assertInstanceOf(Response::class, $result); // Test 500 response - should NOT be cached (not in whitelist) - $response500 = new Response(new App()); + $response500 = new Response(); $response500->setStatusCode(500); $response500->setBody('Server Error'); @@ -163,7 +163,7 @@ public function testRedirectResponseNotCached(): void $request = $this->createRequest(); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $response->redirect('/new-url'); $result = $filter->after($request, $response); diff --git a/tests/system/HTTP/CURLRequestShareOptionsTest.php b/tests/system/HTTP/CURLRequestShareOptionsTest.php index 6e52a345e32a..9716351f486e 100644 --- a/tests/system/HTTP/CURLRequestShareOptionsTest.php +++ b/tests/system/HTTP/CURLRequestShareOptionsTest.php @@ -34,8 +34,7 @@ final class CURLRequestShareOptionsTest extends CURLRequestTest */ protected function getRequest(array $options = [], ?array $shareConnectionOptions = null): MockCURLRequest { - $uri = isset($options['baseURI']) ? new URI($options['baseURI']) : new URI(); - $app = new App(); + $uri = new URI($options['baseURI'] ?? null); $config = new ConfigCURLRequest(); $config->shareOptions = true; @@ -46,7 +45,7 @@ protected function getRequest(array $options = [], ?array $shareConnectionOption Factories::injectMock('config', 'CURLRequest', $config); - return new MockCURLRequest(($app), $uri, new Response($app), $options); + return new MockCURLRequest(new App(), $uri, new Response(), $options); } public function testHeaderContentLengthNotSharedBetweenRequests(): void diff --git a/tests/system/HTTP/CURLRequestTest.php b/tests/system/HTTP/CURLRequestTest.php index 792304e8087a..d654cac08675 100644 --- a/tests/system/HTTP/CURLRequestTest.php +++ b/tests/system/HTTP/CURLRequestTest.php @@ -52,8 +52,7 @@ protected function setUp(): void */ protected function getRequest(array $options = [], ?array $shareConnectionOptions = null): MockCURLRequest { - $uri = isset($options['baseURI']) ? new URI($options['baseURI']) : new URI(); - $app = new App(); + $uri = new URI($options['baseURI'] ?? null); $config = new ConfigCURLRequest(); $config->shareOptions = false; @@ -64,7 +63,7 @@ protected function getRequest(array $options = [], ?array $shareConnectionOption Factories::injectMock('config', 'CURLRequest', $config); - return new MockCURLRequest(($app), $uri, new Response($app), $options); + return new MockCURLRequest(new App(), $uri, new Response(), $options); } /** diff --git a/tests/system/HTTP/ContentSecurityPolicyTest.php b/tests/system/HTTP/ContentSecurityPolicyTest.php index beafa54ce164..048e681b00f7 100644 --- a/tests/system/HTTP/ContentSecurityPolicyTest.php +++ b/tests/system/HTTP/ContentSecurityPolicyTest.php @@ -49,11 +49,10 @@ private function prepare(bool $CSPEnabled = true): void { $this->resetServices(); - $config = config(App::class); + // Needed by CSP + config(App::class)->CSPEnabled = $CSPEnabled; - $config->CSPEnabled = $CSPEnabled; - - $this->response = new Response($config); + $this->response = new Response(); $this->response->pretend(false); $this->csp = $this->response->getCSP(); @@ -181,7 +180,7 @@ public function testConfigSetsListAsDirectivesValues(): void $csp = new ContentSecurityPolicy($config); - $response = new Response(new App()); + $response = new Response(); $response->pretend(true); $response->setBody('Blah blah blah blah'); @@ -738,7 +737,7 @@ public function testBodyScriptNonceCustomScriptTag(): void $config->scriptNonceTag = '{custom-script-nonce-tag}'; $csp = new ContentSecurityPolicy($config); - $response = new Response(new App()); + $response = new Response(); $response->pretend(true); $body = 'Blah blah {custom-script-nonce-tag} blah blah'; $response->setBody($body); @@ -754,7 +753,7 @@ public function testBodyScriptNonceDisableAutoNonce(): void $config->autoNonce = false; $csp = new ContentSecurityPolicy($config); - $response = new Response(new App()); + $response = new Response(); $response->pretend(true); $body = 'Blah blah {csp-script-nonce} blah blah'; $response->setBody($body); @@ -773,7 +772,7 @@ public function testBodyStyleNonceDisableAutoNonce(): void $config->autoNonce = false; $csp = new ContentSecurityPolicy($config); - $response = new Response(new App()); + $response = new Response(); $response->pretend(true); $body = 'Blah blah {csp-style-nonce} blah blah'; $response->setBody($body); @@ -817,7 +816,7 @@ public function testBodyStyleNonceCustomStyleTag(): void $config->styleNonceTag = '{custom-style-nonce-tag}'; $csp = new ContentSecurityPolicy($config); - $response = new Response(new App()); + $response = new Response(); $response->pretend(true); $body = 'Blah blah {custom-style-nonce-tag} blah blah'; $response->setBody($body); diff --git a/tests/system/HTTP/RedirectResponseTest.php b/tests/system/HTTP/RedirectResponseTest.php index 2ea700c03d88..6483f2562493 100644 --- a/tests/system/HTTP/RedirectResponseTest.php +++ b/tests/system/HTTP/RedirectResponseTest.php @@ -70,7 +70,7 @@ protected function setUp(): void public function testRedirectToFullURI(): void { - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $response = $response->to('http://example.com/foo'); @@ -80,7 +80,7 @@ public function testRedirectToFullURI(): void public function testRedirectRoute(): void { - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $this->routes->add('exampleRoute', 'Home::index'); @@ -102,7 +102,7 @@ public function testRedirectRouteBadNamedRoute(): void $this->expectException(HTTPException::class); $this->expectExceptionMessage('The route for "differentRoute" cannot be found.'); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $this->routes->add('exampleRoute', 'Home::index'); @@ -114,7 +114,7 @@ public function testRedirectRouteBadControllerMethod(): void $this->expectException(HTTPException::class); $this->expectExceptionMessage('The route for "Bad::badMethod" cannot be found.'); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $this->routes->add('exampleRoute', 'Home::index'); @@ -123,8 +123,7 @@ public function testRedirectRouteBadControllerMethod(): void public function testRedirectRelativeConvertsToFullURI(): void { - $response = new RedirectResponse($this->config); - + $response = new RedirectResponse(); $response = $response->to('/foo'); $this->assertTrue($response->hasHeader('Location')); @@ -139,7 +138,7 @@ public function testWithInput(): void service('superglobals')->setGet('foo', 'bar'); service('superglobals')->setPost('bar', 'baz'); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $returned = $response->withInput(); @@ -155,7 +154,7 @@ public function testWithValidationErrors(): void { $_SESSION = []; - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $validation = $this->createMock(Validation::class); $validation->method('getErrors')->willReturn(['foo' => 'bar']); @@ -173,7 +172,7 @@ public function testWith(): void { $_SESSION = []; - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $returned = $response->with('foo', 'bar'); @@ -190,7 +189,7 @@ public function testRedirectBack(): void $this->request = new MockIncomingRequest($this->config, new SiteURI($this->config), null, new UserAgent()); Services::injectMock('request', $this->request); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $returned = $response->back(); $this->assertSame('http://somewhere.com', $returned->header('location')->getValue()); @@ -202,7 +201,7 @@ public function testRedirectBackMissing(): void { $_SESSION = []; - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $returned = $response->back(); @@ -223,7 +222,7 @@ public function testRedirectRouteBaseUrl(): void $request = new MockIncomingRequest($config, new SiteURI($config), null, new UserAgent()); Services::injectMock('request', $request); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $this->routes->add('exampleRoute', 'Home::index'); @@ -242,7 +241,7 @@ public function testWithCookies(): void $baseResponse = service('response'); $baseResponse->setCookie('foo', 'bar'); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $this->assertFalse($response->hasCookie('foo', 'bar')); $response = $response->withCookies(); @@ -255,7 +254,7 @@ public function testWithCookiesWithEmptyCookies(): void { $_SESSION = []; - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $response = $response->withCookies(); $this->assertEmpty($response->getCookies()); @@ -268,7 +267,7 @@ public function testWithHeaders(): void $baseResponse = service('response'); $baseResponse->setHeader('foo', 'bar'); - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $this->assertFalse($response->hasHeader('foo')); $response = $response->withHeaders(); @@ -289,7 +288,7 @@ public function testWithHeadersWithEmptyHeaders(): void $baseResponse->removeHeader($key); } - $response = new RedirectResponse(new App()); + $response = new RedirectResponse(); $response->withHeaders(); $this->assertEmpty($baseResponse->headers()); diff --git a/tests/system/HTTP/ResponseCookieTest.php b/tests/system/HTTP/ResponseCookieTest.php index 6fb03d516a9f..700af9044bbc 100644 --- a/tests/system/HTTP/ResponseCookieTest.php +++ b/tests/system/HTTP/ResponseCookieTest.php @@ -18,7 +18,6 @@ use CodeIgniter\Cookie\CookieStore; use CodeIgniter\Cookie\Exceptions\CookieException; use CodeIgniter\Test\CIUnitTestCase; -use Config\App; use Config\Cookie as CookieConfig; use PHPUnit\Framework\Attributes\Group; @@ -45,7 +44,7 @@ public function testCookiePrefixed(): void { $config = config('Cookie'); $config->prefix = 'mine'; - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar'); $this->assertInstanceOf(Cookie::class, $response->getCookie('foo')); @@ -58,7 +57,7 @@ public function testCookiePrefixed(): void public function testCookiesAll(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar'); $response->setCookie('bee', 'bop'); @@ -70,7 +69,7 @@ public function testCookiesAll(): void public function testSetCookieObject(): void { $cookie = new Cookie('foo', 'bar'); - $response = new Response(new App()); + $response = new Response(); $response->setCookie($cookie); @@ -80,7 +79,7 @@ public function testSetCookieObject(): void public function testCookieGet(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar'); $response->setCookie('bee', 'bop'); @@ -90,7 +89,7 @@ public function testCookieGet(): void public function testCookieDomain(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar'); $cookie = $response->getCookie('foo'); @@ -102,7 +101,7 @@ public function testCookieDomain(): void $config = config('Cookie'); $config->domain = 'mine.com'; - $response = new Response(new App()); + $response = new Response(); $response->setCookie('alu', 'la'); $cookie = $response->getCookie('alu'); $this->assertSame('mine.com', $cookie->getDomain()); @@ -110,7 +109,7 @@ public function testCookieDomain(): void public function testCookiePath(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar'); $cookie = $response->getCookie('foo'); @@ -123,7 +122,7 @@ public function testCookiePath(): void public function testCookieSecure(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar'); $cookie = $response->getCookie('foo'); @@ -136,7 +135,7 @@ public function testCookieSecure(): void public function testCookieHTTPOnly(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar'); $cookie = $response->getCookie('foo'); @@ -149,18 +148,18 @@ public function testCookieHTTPOnly(): void public function testCookieExpiry(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar'); $cookie = $response->getCookie('foo'); $this->assertTrue($cookie->isExpired()); - $response = new Response(new App()); + $response = new Response(); $response->setCookie(['name' => 'bee', 'value' => 'bop', 'expire' => 1000]); $cookie = $response->getCookie('bee'); $this->assertFalse($cookie->isExpired()); - $response = new Response(new App()); + $response = new Response(); $response->setCookie(['name' => 'bee', 'value' => 'bop', 'expire' => -1000]); $cookie = $response->getCookie('bee'); $this->assertSame(0, $cookie->getExpiresTimestamp()); @@ -168,7 +167,7 @@ public function testCookieExpiry(): void public function testCookieDelete(): void { - $response = new Response(new App()); + $response = new Response(); // foo is already expired, bee will stick around $response->setCookie('foo', 'bar'); @@ -177,20 +176,20 @@ public function testCookieDelete(): void $this->assertFalse($cookie->isExpired()); // delete cookie manually - $response = new Response(new App()); + $response = new Response(); $response->setCookie(['name' => 'bee', 'value' => 'bop', 'expire' => '']); $cookie = $response->getCookie('bee'); $this->assertTrue($cookie->isExpired(), $cookie->getExpiresTimestamp() . ' should be less than ' . time()); // delete with no effect - $response = new Response(new App()); + $response = new Response(); $response->setCookie(['name' => 'bee', 'value' => 'bop', 'expire' => 1000]); $response->deleteCookie(); $cookie = $response->getCookie('bee'); $this->assertFalse($cookie->isExpired()); // delete cookie for real - $response = new Response(new App()); + $response = new Response(); $response->setCookie(['name' => 'bee', 'value' => 'bop', 'expire' => 1000]); $response->deleteCookie('bee'); $cookie = $response->getCookie('bee'); @@ -199,7 +198,7 @@ public function testCookieDelete(): void $config = config('Cookie'); // delete cookie for real, with prefix $config->prefix = 'mine'; - $response = new Response(new App()); + $response = new Response(); $response->setCookie(['name' => 'bee', 'value' => 'bop', 'expire' => 1000]); $response->deleteCookie('bee'); $cookie = $response->getCookie('bee'); @@ -207,7 +206,7 @@ public function testCookieDelete(): void // delete cookie with wrong prefix? $config->prefix = 'mine'; - $response = new Response(new App()); + $response = new Response(); $response->setCookie(['name' => 'bee', 'value' => 'bop', 'expire' => 1000]); $response->deleteCookie('bee', '', '', 'wrong'); $cookie = $response->getCookie('bee'); @@ -218,7 +217,7 @@ public function testCookieDelete(): void // delete cookie with wrong domain? $config->domain = '.mine.com'; - $response = new Response(new App()); + $response = new Response(); $response->setCookie(['name' => 'bees', 'value' => 'bop', 'expire' => 1000]); $response->deleteCookie('bees', 'wrong', '', ''); $cookie = $response->getCookie('bees'); @@ -230,7 +229,7 @@ public function testCookieDelete(): void public function testCookieDefaultSetSameSite(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie([ 'name' => 'bar', 'value' => 'foo', @@ -246,7 +245,7 @@ public function testCookieStrictSetSameSite(): void { $config = config('Cookie'); $config->samesite = 'Strict'; - $response = new Response(new App()); + $response = new Response(); $response->setCookie([ 'name' => 'bar', 'value' => 'foo', @@ -263,7 +262,7 @@ public function testCookieBlankSetSameSite(): void /** @var CookieConfig $config */ $config = config('Cookie'); $config->samesite = ''; - $response = new Response(new App()); + $response = new Response(); $response->setCookie([ 'name' => 'bar', 'value' => 'foo', @@ -279,7 +278,7 @@ public function testCookieWithoutSameSite(): void { $config = new CookieConfig(); unset($config->samesite); - $response = new Response(new App()); + $response = new Response(); $response->setCookie([ 'name' => 'bar', 'value' => 'foo', @@ -293,7 +292,7 @@ public function testCookieWithoutSameSite(): void public function testCookieStrictSameSite(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie([ 'name' => 'bar', 'value' => 'foo', @@ -308,7 +307,7 @@ public function testCookieStrictSameSite(): void public function testCookieInvalidSameSite(): void { - $response = new Response(new App()); + $response = new Response(); $this->expectException(CookieException::class); $this->expectExceptionMessage(lang('Cookie.invalidSameSite', ['Invalid'])); @@ -334,7 +333,7 @@ public function testSetCookieConfigCookieIsUsed(): void 'value' => 'foo', 'expire' => 9999, ]; - $response = new Response(new App()); + $response = new Response(); $response->setCookie($cookieAttr); $cookie = $response->getCookie('bar'); @@ -346,7 +345,7 @@ public function testSetCookieConfigCookieIsUsed(): void public function testGetCookieStore(): void { - $response = new Response(new App()); + $response = new Response(); $this->assertInstanceOf(CookieStore::class, $response->getCookieStore()); } } diff --git a/tests/system/HTTP/ResponseSendTest.php b/tests/system/HTTP/ResponseSendTest.php index 211d806ba487..befa6bf785be 100644 --- a/tests/system/HTTP/ResponseSendTest.php +++ b/tests/system/HTTP/ResponseSendTest.php @@ -51,7 +51,7 @@ final class ResponseSendTest extends CIUnitTestCase #[WithoutErrorHandler] public function testHeadersMissingDate(): void { - $response = new Response(new App()); + $response = new Response(); $response->pretend(false); $body = 'Hello'; @@ -87,9 +87,9 @@ public function testHeadersWithCSP(): void $this->resetFactories(); $this->resetServices(); - $config = config('App'); - $config->CSPEnabled = true; - $response = new Response($config); + config(App::class)->CSPEnabled = true; + + $response = new Response(); $response->pretend(false); $body = 'Hello'; @@ -122,7 +122,7 @@ public function testRedirectResponseCookies(): void { $loginTime = time(); - $response = new Response(new App()); + $response = new Response(); $response->pretend(false); $routes = service('routes'); @@ -161,7 +161,7 @@ public function testDoNotSendUnSecureCookie(): void $request->method('isSecure')->willReturn(false); Services::injectMock('request', $request); - $response = new Response(new App()); + $response = new Response(); $response->pretend(false); $body = 'Hello'; $response->setBody($body); @@ -189,7 +189,7 @@ public function testDoNotSendUnSecureCookie(): void #[WithoutErrorHandler] public function testHeaderOverride(): void { - $response = new Response(new App()); + $response = new Response(); $response->pretend(false); $body = 'Hello'; diff --git a/tests/system/HTTP/ResponseTest.php b/tests/system/HTTP/ResponseTest.php index 38c349117cbb..f68047228513 100644 --- a/tests/system/HTTP/ResponseTest.php +++ b/tests/system/HTTP/ResponseTest.php @@ -52,8 +52,7 @@ protected function tearDown(): void public function testCanSetStatusCode(): void { - $response = new Response(new App()); - + $response = new Response(); $response->setStatusCode(200); $this->assertSame(200, $response->getStatusCode()); @@ -61,25 +60,15 @@ public function testCanSetStatusCode(): void public function testSetStatusCodeThrowsExceptionForBadCodes(): void { - $response = new Response(new App()); + $response = new Response(); $this->expectException(HTTPException::class); $response->setStatusCode(54322); } - public function testConstructWithCSPEnabled(): void - { - $config = new App(); - $config->CSPEnabled = true; - $response = new Response($config); - - $this->assertInstanceOf(Response::class, $response); - } - public function testSetStatusCodeSetsReason(): void { - $response = new Response(new App()); - + $response = new Response(); $response->setStatusCode(200); $this->assertSame('OK', $response->getReasonPhrase()); @@ -87,8 +76,7 @@ public function testSetStatusCodeSetsReason(): void public function testCanSetCustomReasonCode(): void { - $response = new Response(new App()); - + $response = new Response(); $response->setStatusCode(200, 'Not the mama'); $this->assertSame('Not the mama', $response->getReasonPhrase()); @@ -96,7 +84,7 @@ public function testCanSetCustomReasonCode(): void public function testRequiresMessageWithUnknownStatusCode(): void { - $response = new Response(new App()); + $response = new Response(); $this->expectException(HTTPException::class); $this->expectExceptionMessage(lang('HTTP.unknownStatusCode', [115])); @@ -105,7 +93,7 @@ public function testRequiresMessageWithUnknownStatusCode(): void public function testRequiresMessageWithSmallStatusCode(): void { - $response = new Response(new App()); + $response = new Response(); $this->expectException(HTTPException::class); $this->expectExceptionMessage(lang('HTTP.invalidStatusCode', [95])); @@ -114,7 +102,7 @@ public function testRequiresMessageWithSmallStatusCode(): void public function testRequiresMessageWithLargeStatusCode(): void { - $response = new Response(new App()); + $response = new Response(); $this->expectException(HTTPException::class); $this->expectExceptionMessage(lang('HTTP.invalidStatusCode', [695])); @@ -123,8 +111,7 @@ public function testRequiresMessageWithLargeStatusCode(): void public function testSetStatusCodeInterpretsReason(): void { - $response = new Response(new App()); - + $response = new Response(); $response->setStatusCode(300); $this->assertSame('Multiple Choices', $response->getReasonPhrase()); @@ -132,8 +119,7 @@ public function testSetStatusCodeInterpretsReason(): void public function testSetStatusCodeSavesCustomReason(): void { - $response = new Response(new App()); - + $response = new Response(); $response->setStatusCode(300, 'My Little Pony'); $this->assertSame('My Little Pony', $response->getReasonPhrase()); @@ -141,14 +127,14 @@ public function testSetStatusCodeSavesCustomReason(): void public function testGetReasonDefaultsToOK(): void { - $response = new Response(new App()); + $response = new Response(); $this->assertSame('OK', $response->getReasonPhrase()); } public function testSetDateRemembersDateInUTC(): void { - $response = new Response(new App()); + $response = new Response(); $datetime = DateTime::createFromFormat('!Y-m-d', '2000-03-10'); $response->setDate($datetime); @@ -170,7 +156,7 @@ public function testSetLink(): void $this->resetServices(); - $response = new Response($config); + $response = new Response(); $pager = service('pager'); $pager->store('default', 3, 10, 200); @@ -200,8 +186,7 @@ public function testSetLink(): void public function testSetContentType(): void { - $response = new Response(new App()); - + $response = new Response(); $response->setContentType('text/json'); $this->assertSame('text/json; charset=UTF-8', $response->getHeaderLine('Content-Type')); @@ -209,8 +194,7 @@ public function testSetContentType(): void public function testNoCache(): void { - $response = new Response(new App()); - + $response = new Response(); $response->noCache(); $this->assertSame('no-store, max-age=0, no-cache', $response->getHeaderLine('Cache-control')); @@ -218,7 +202,7 @@ public function testNoCache(): void public function testSetCache(): void { - $response = new Response(new App()); + $response = new Response(); $date = date('r'); @@ -238,18 +222,15 @@ public function testSetCache(): void public function testSetCacheNoOptions(): void { - $response = new Response(new App()); - - $options = []; - - $response->setCache($options); + $response = new Response(); + $response->setCache([]); $this->assertSame('no-store, max-age=0, no-cache', $response->getHeaderLine('Cache-Control')); } public function testSetLastModifiedWithDateTimeObject(): void { - $response = new Response(new App()); + $response = new Response(); $datetime = DateTime::createFromFormat('Y-m-d', '2000-03-10'); $response->setLastModified($datetime); @@ -264,8 +245,7 @@ public function testSetLastModifiedWithDateTimeObject(): void public function testRedirectSetsDefaultCodeAndLocationHeader(): void { - $response = new Response(new App()); - + $response = new Response(); $response->redirect('example.com'); $this->assertTrue($response->hasHeader('location')); @@ -286,7 +266,7 @@ public function testRedirect( ->setServer('SERVER_PROTOCOL', $protocol) ->setServer('REQUEST_METHOD', $method); - $response = new Response(new App()); + $response = new Response(); $response->redirect('example.com', 'auto', $code); $this->assertTrue($response->hasHeader('location')); @@ -330,7 +310,7 @@ public function testRedirectWithIIS( ->setServer('SERVER_PROTOCOL', 'HTTP/1.1') ->setServer('REQUEST_METHOD', 'POST'); - $response = new Response(new App()); + $response = new Response(); $response->redirect('example.com', 'auto', $code); $this->assertSame('0;url=example.com', $response->getHeaderLine('Refresh')); @@ -353,14 +333,14 @@ public static function provideRedirectWithIIS(): iterable public function testSetCookieFails(): void { - $response = new Response(new App()); + $response = new Response(); $this->assertFalse($response->hasCookie('foo')); } public function testSetCookieMatch(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar'); $this->assertTrue($response->hasCookie('foo')); @@ -369,7 +349,7 @@ public function testSetCookieMatch(): void public function testSetCookieFailDifferentPrefix(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar', '', '', '', 'ack'); $this->assertFalse($response->hasCookie('foo')); @@ -377,7 +357,7 @@ public function testSetCookieFailDifferentPrefix(): void public function testSetCookieSuccessOnPrefix(): void { - $response = new Response(new App()); + $response = new Response(); $response->setCookie('foo', 'bar', '', '', '', 'ack'); $this->assertTrue($response->hasCookie('foo', null, 'ack')); @@ -396,7 +376,7 @@ public function testJSONWithArray(): void ]; $expected = service('format')->getFormatter('application/json')->format($body); - $response = new Response(new App()); + $response = new Response(); $response->setJSON($body); $this->assertSame($expected, $response->getJSON()); @@ -415,7 +395,7 @@ public function testJSONGetFromNormalBody(): void ]; $expected = service('format')->getFormatter('application/json')->format($body); - $response = new Response(new App()); + $response = new Response(); $response->setBody($body); $this->assertSame($expected, $response->getJSON()); @@ -433,7 +413,7 @@ public function testXMLWithArray(): void ]; $expected = service('format')->getFormatter('application/xml')->format($body); - $response = new Response(new App()); + $response = new Response(); $response->setXML($body); $this->assertSame($expected, $response->getXML()); @@ -452,7 +432,7 @@ public function testXMLGetFromNormalBody(): void ]; $expected = service('format')->getFormatter('application/xml')->format($body); - $response = new Response(new App()); + $response = new Response(); $response->setBody($body); $this->assertSame($expected, $response->getXML()); @@ -460,7 +440,7 @@ public function testXMLGetFromNormalBody(): void public function testGetDownloadResponseByData(): void { - $response = new Response(new App()); + $response = new Response(); $actual = $response->download('unit-test.txt', 'data'); @@ -478,7 +458,7 @@ public function testGetDownloadResponseByData(): void public function testGetDownloadResponseByFilePath(): void { - $response = new Response(new App()); + $response = new Response(); $actual = $response->download(__FILE__, null); @@ -496,7 +476,7 @@ public function testGetDownloadResponseByFilePath(): void public function testVagueDownload(): void { - $response = new Response(new App()); + $response = new Response(); $actual = $response->download(); @@ -505,7 +485,7 @@ public function testVagueDownload(): void public function testPretendMode(): void { - $response = new MockResponse(new App()); + $response = new MockResponse(); $response->pretend(true); $this->assertTrue($response->getPretend()); $response->pretend(false); @@ -514,7 +494,7 @@ public function testPretendMode(): void public function testMisbehaving(): void { - $response = new MockResponse(new App()); + $response = new MockResponse(); $response->misbehave(); $this->expectException(HTTPException::class); @@ -526,7 +506,7 @@ public function testTemporaryRedirectHTTP11(): void service('superglobals') ->setServer('SERVER_PROTOCOL', 'HTTP/1.1') ->setServer('REQUEST_METHOD', 'POST'); - $response = new Response(new App()); + $response = new Response(); $response->setProtocolVersion('HTTP/1.1'); $response->redirect('/foo'); @@ -539,7 +519,7 @@ public function testTemporaryRedirectGetHTTP11(): void service('superglobals') ->setServer('SERVER_PROTOCOL', 'HTTP/1.1') ->setServer('REQUEST_METHOD', 'GET'); - $response = new Response(new App()); + $response = new Response(); $response->setProtocolVersion('HTTP/1.1'); $response->redirect('/foo'); @@ -553,7 +533,7 @@ public function testRedirectResponseCookies(): void { $loginTime = time(); - $response = new Response(new App()); + $response = new Response(); $answer1 = $response->redirect('/login') ->setCookie('foo', 'bar', YEAR) ->setCookie('login_time', (string) $loginTime, YEAR); @@ -565,7 +545,7 @@ public function testRedirectResponseCookies(): void // Make sure we don't blow up if pretending to send headers public function testPretendOutput(): void { - $response = new Response(new App()); + $response = new Response(); $response->pretend(true); $response->setBody('Happy days'); @@ -580,10 +560,7 @@ public function testPretendOutput(): void public function testSendRemovesDefaultNoncePlaceholdersWhenCSPDisabled(): void { - $config = new App(); - $config->CSPEnabled = false; - - $response = new Response($config); + $response = new Response(); $response->pretend(true); $body = ''; @@ -603,9 +580,6 @@ public function testSendRemovesDefaultNoncePlaceholdersWhenCSPDisabled(): void public function testSendRemovesCustomNoncePlaceholdersWhenCSPDisabled(): void { - $appConfig = new App(); - $appConfig->CSPEnabled = false; - // Create custom CSP config with custom nonce tags $cspConfig = new \Config\ContentSecurityPolicy(); $cspConfig->scriptNonceTag = '{custom-script-tag}'; @@ -613,7 +587,7 @@ public function testSendRemovesCustomNoncePlaceholdersWhenCSPDisabled(): void Services::injectMock('csp', new ContentSecurityPolicy($cspConfig)); - $response = new Response($appConfig); + $response = new Response(); $response->pretend(true); $body = ''; @@ -633,10 +607,7 @@ public function testSendRemovesCustomNoncePlaceholdersWhenCSPDisabled(): void public function testSendNoEffectWhenBodyEmptyAndCSPDisabled(): void { - $config = new App(); - $config->CSPEnabled = false; - - $response = new Response($config); + $response = new Response(); $response->pretend(true); $body = ''; @@ -652,10 +623,7 @@ public function testSendNoEffectWhenBodyEmptyAndCSPDisabled(): void public function testSendNoEffectWithNoPlaceholdersAndCSPDisabled(): void { - $config = new App(); - $config->CSPEnabled = false; - - $response = new Response($config); + $response = new Response(); $response->pretend(true); $body = 'Test

No placeholders here

'; @@ -672,10 +640,7 @@ public function testSendNoEffectWithNoPlaceholdersAndCSPDisabled(): void public function testSendRemovesMultiplePlaceholdersWhenCSPDisabled(): void { - $config = new App(); - $config->CSPEnabled = false; - - $response = new Response($config); + $response = new Response(); $response->pretend(true); $body = ''; @@ -697,16 +662,13 @@ public function testSendRemovesMultiplePlaceholdersWhenCSPDisabled(): void public function testSendRemovesPlaceholdersWhenBothCSPAndAutoNonceAreDisabled(): void { - $appConfig = new App(); - $appConfig->CSPEnabled = false; - // Create custom CSP config with custom nonce tags $cspConfig = new \Config\ContentSecurityPolicy(); $cspConfig->autoNonce = false; Services::injectMock('csp', new ContentSecurityPolicy($cspConfig)); - $response = new Response($appConfig); + $response = new Response(); $response->pretend(true); $body = ''; diff --git a/tests/system/Helpers/CookieHelperTest.php b/tests/system/Helpers/CookieHelperTest.php index abbc291ceb38..6ef4e2f5064f 100644 --- a/tests/system/Helpers/CookieHelperTest.php +++ b/tests/system/Helpers/CookieHelperTest.php @@ -51,7 +51,7 @@ protected function setUp(): void $this->value = 'hello world'; $this->expire = 9999; - Services::injectMock('response', new MockResponse(new App())); + Services::injectMock('response', new MockResponse()); $this->response = service('response'); $request = new IncomingRequest(new App(), new SiteURI(new App()), null, new UserAgent()); Services::injectMock('request', $request); diff --git a/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php b/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php index 73461c3c96ed..9f67dd885d27 100644 --- a/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php +++ b/tests/system/Log/Handlers/ChromeLoggerHandlerTest.php @@ -16,7 +16,6 @@ use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockLogger as LoggerConfig; use CodeIgniter\Test\Mock\MockResponse; -use Config\App; use Config\Services; use PHPUnit\Framework\Attributes\Group; use stdClass; @@ -77,7 +76,7 @@ public function testSetDateFormat(): void public function testChromeLoggerHeaderSent(): void { - Services::injectMock('response', new MockResponse(new App())); + Services::injectMock('response', new MockResponse()); $response = service('response'); $config = new LoggerConfig(); diff --git a/tests/system/RESTful/ResourceControllerTest.php b/tests/system/RESTful/ResourceControllerTest.php index c51e4ae39174..21ad97975867 100644 --- a/tests/system/RESTful/ResourceControllerTest.php +++ b/tests/system/RESTful/ResourceControllerTest.php @@ -323,7 +323,7 @@ public function testJSONFormatOutput(): void $agent = new UserAgent(); $request = new IncomingRequest($config, $uri, '', $agent); - $response = new Response($config); + $response = new Response(); $logger = new NullLogger(); $resource->initController($request, $response, $logger); @@ -351,7 +351,7 @@ public function testXMLFormatOutput(): void $agent = new UserAgent(); $request = new IncomingRequest($config, $uri, '', $agent); - $response = new Response($config); + $response = new Response(); $logger = new NullLogger(); $resource->initController($request, $response, $logger); diff --git a/tests/system/Test/TestCaseEmissionsTest.php b/tests/system/Test/TestCaseEmissionsTest.php index 8ebcdcc28d92..567b5daa8ddf 100644 --- a/tests/system/Test/TestCaseEmissionsTest.php +++ b/tests/system/Test/TestCaseEmissionsTest.php @@ -14,7 +14,6 @@ namespace CodeIgniter\Test; use CodeIgniter\HTTP\Response; -use Config\App; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\Attributes\PreserveGlobalState; use PHPUnit\Framework\Attributes\RunInSeparateProcess; @@ -49,7 +48,7 @@ final class TestCaseEmissionsTest extends CIUnitTestCase #[WithoutErrorHandler] public function testHeadersEmitted(): void { - $response = new Response(new App()); + $response = new Response(); $response->pretend(false); $body = 'Hello'; @@ -76,7 +75,7 @@ public function testHeadersEmitted(): void #[WithoutErrorHandler] public function testHeadersNotEmitted(): void { - $response = new Response(new App()); + $response = new Response(); $response->pretend(false); $body = 'Hello'; diff --git a/tests/system/Test/TestResponseTest.php b/tests/system/Test/TestResponseTest.php index dc175897b870..442d5239b713 100644 --- a/tests/system/Test/TestResponseTest.php +++ b/tests/system/Test/TestResponseTest.php @@ -15,7 +15,6 @@ use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\HTTP\Response; -use Config\App; use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Group; @@ -154,7 +153,7 @@ public function testAssertRedirectFail(): void public function testAssertRedirectSuccess(): void { $this->getTestResponse('

Hello World

'); - $this->testResponse->setResponse(new RedirectResponse(new App())); + $this->testResponse->setResponse(new RedirectResponse()); $this->assertInstanceOf(RedirectResponse::class, $this->testResponse->response()); $this->assertTrue($this->testResponse->isRedirect()); @@ -175,7 +174,7 @@ public function testAssertRedirectSuccessWithoutRedirectResponse(): void public function testGetRedirectUrlReturnsUrl(): void { $this->getTestResponse('

Hello World

'); - $this->testResponse->setResponse(new RedirectResponse(new App())); + $this->testResponse->setResponse(new RedirectResponse()); $this->testResponse->response()->redirect('foo/bar'); $this->assertSame('foo/bar', $this->testResponse->getRedirectUrl()); @@ -191,7 +190,7 @@ public function testGetRedirectUrlReturnsNull(): void public function testRedirectToSuccess(): void { $this->getTestResponse('

Hello World

'); - $this->testResponse->setResponse(new RedirectResponse(new App())); + $this->testResponse->setResponse(new RedirectResponse()); $this->testResponse->response()->redirect('foo/bar'); $this->testResponse->assertRedirectTo('foo/bar'); @@ -200,7 +199,7 @@ public function testRedirectToSuccess(): void public function testRedirectToSuccessFullURL(): void { $this->getTestResponse('

Hello World

'); - $this->testResponse->setResponse(new RedirectResponse(new App())); + $this->testResponse->setResponse(new RedirectResponse()); $this->testResponse->response()->redirect('http://foo.com/bar'); $this->testResponse->assertRedirectTo('http://foo.com/bar'); @@ -209,7 +208,7 @@ public function testRedirectToSuccessFullURL(): void public function testRedirectToSuccessMixedURL(): void { $this->getTestResponse('

Hello World

'); - $this->testResponse->setResponse(new RedirectResponse(new App())); + $this->testResponse->setResponse(new RedirectResponse()); $this->testResponse->response()->redirect('bar'); $this->testResponse->assertRedirectTo('http://example.com/index.php/bar'); @@ -434,7 +433,7 @@ public function testAssertJsonExactString(): void protected function getTestResponse(?string $body = null, array $responseOptions = [], array $headers = []): void { - $this->response = new Response(new App()); + $this->response = new Response(); $this->response->setBody($body); foreach ($responseOptions as $key => $value) { diff --git a/user_guide_src/source/changelogs/v4.8.0.rst b/user_guide_src/source/changelogs/v4.8.0.rst index 026744fbe8f1..375fcd56773a 100644 --- a/user_guide_src/source/changelogs/v4.8.0.rst +++ b/user_guide_src/source/changelogs/v4.8.0.rst @@ -62,10 +62,15 @@ Libraries Helpers and Functions ===================== -Others -====== +HTTP +==== - Added ``SSEResponse`` class for streaming Server-Sent Events (SSE) over HTTP. See :ref:`server-sent-events`. +- ``Response`` and its child classes no longer require ``Config\App`` passed to their constructors. + Consequently, ``CURLRequest``'s ``$config`` parameter is unused and will be removed in a future release. + +Others +====== *************** Message Changes