diff --git a/system/Test/FeatureResponse.php b/system/Test/FeatureResponse.php index b69af9a40a74..6c919b7638eb 100644 --- a/system/Test/FeatureResponse.php +++ b/system/Test/FeatureResponse.php @@ -91,15 +91,17 @@ public function __construct(ResponseInterface $response = null) */ public function isOK(): bool { + $status = $this->response->getStatusCode(); + // Only 200 and 300 range status codes // are considered valid. - if ($this->response->getStatusCode() >= 400 || $this->response->getStatusCode() < 200) + if ($status >= 400 || $status < 200) { return false; } - // Empty bodies are not considered valid. - if (empty($this->response->getBody())) + // Empty bodies are not considered valid, unless in redirects + if ($status < 300 && empty($this->response->getBody())) { return false; } diff --git a/tests/system/Test/FeatureTestCaseTest.php b/tests/system/Test/FeatureTestCaseTest.php index c152304c8d58..b0f98b5e749b 100644 --- a/tests/system/Test/FeatureTestCaseTest.php +++ b/tests/system/Test/FeatureTestCaseTest.php @@ -296,4 +296,21 @@ public function testOpenCliRoutesFromHttpGot404($from, $to, $httpGet) ]); $this->get($httpGet); } + + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/3072 + */ + public function testIsOkWithRedirects() + { + $this->withRoutes([ + [ + 'get', + 'home', + '\Tests\Support\Controllers\Popcorn::goaway', + ], + ]); + $response = $this->get('home'); + $this->assertTrue($response->isRedirect()); + $this->assertTrue($response->isOK()); + } }