CodeIgniter Forums
Feature test http responses interfere between tests - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Feature test http responses interfere between tests (/showthread.php?tid=80052)



Feature test http responses interfere between tests - Taras - 09-07-2021

Hello
I am writing feature tests that access post and get endpoints.
PHP Code:
public function testAbc()
{
    $data = ['a' => 'a'];
    $response $this->post('abc'$data);
    $response->assertRedirect();
}

public function 
testDef()
{
    $response $this->get('def'$data);
    $response->assertNotRedirect();


Second assertion fails also controller does not have redirect. When I am dupming response value into console it looks sometimes fine or may contain previous response it some cases. It looks like response has data from the previous test for some reason. Why this happens? How it should be cleared?
Test class is defined like this:
PHP Code:
class MyFeatureTestCase extends CIUnitTestCase
{
    use DatabaseTestTraitFeatureTestTrait



RE: Feature test http responses interfere between tests - Taras - 09-09-2021

It turned out that issue was caused by redirect in controller in post action:
PHP Code:
        return $this->response->redirect(route_to('abc.view'$id)); 
I replaced it with:
PHP Code:
        return redirect()->to(route_to('abc.view'$id)); 
Now all tests pass fine.
Can anybody please explain what is the difference between them and why first one fails? Is it wrong to use it? In browser all works fine.