Skip to content

Commit

Permalink
Fixed FeatureTest isOK to return true for redirects. Fixes #3072
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnieezell committed Jun 13, 2020
1 parent e1c2b5c commit ee697d9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 5 additions & 3 deletions system/Test/FeatureResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/system/Test/FeatureTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit ee697d9

Please sign in to comment.