When setting a status code, e.g. 404 it will be overwritten by this line
Edit: To illustrate, here, have some code:
class SomeController extends CI_Controller {
/** @var bool To indicate the routing to stop executing any functions because the startup failed already. */
private $startup_failed = false;
public function __construct() {
parent::__construct();
if (true) { // some pre checks
$this->output->set_status_header(404);
echo("OH GAWD!");
$startup_failed = true;
}
}
public function _remap($object_called, $arguments = []) {
if ($this->startup_failed) {
return;
}
parent::_remap($object_called, $arguments);
}
}
class SomeTest extends TestCase {
public function test_response() {
$output = $this->request("GET", "route/to/somecontroller", []);
$expected = "OH GAWD!";
$this->assertEquals($expected, $output); // works correctly
$this->assertResponseCode(404, "not found"); // fails
}
}
Basically an workaround for using exit() before.
Noticably assertResponseCode(404) fails because the code is overwritten to 200.
When setting a status code, e.g.
404it will be overwritten by this lineEdit: To illustrate, here, have some code:
Basically an workaround for using
exit()before.Noticably
assertResponseCode(404)fails because the code is overwritten to200.