From ee697d9181273fd5ba9973d5f36f82b3596204e6 Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Fri, 12 Jun 2020 22:43:44 -0500 Subject: [PATCH] Fixed FeatureTest isOK to return true for redirects. Fixes #3072 --- system/Test/FeatureResponse.php | 8 +++++--- tests/system/Test/FeatureTestCaseTest.php | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) 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()); + } }