Welcome Guest, Not a member yet? Register   Sign In
Feature test http responses interfere between tests

(This post was last modified: 09-07-2021, 11:08 AM by Taras.)

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

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

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

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.

Theme © iAndrew 2016 - Forum software by © MyBB