Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple HTTP requests in Laravel 5 integration tests

We are developing our projects in Laravel 4. One of our integration tests performs two consecutive HTTP requests to the same controller:

public function testFetchingPaginatedEntities() {
    $response = $this->call('GET', "foos?page=1&page_size=1");
    // assertions

    $response = $this->call('GET', "foos");
    // some more assertions
}

As you can see, the second request does not carry any query string parameters. However, we noticed that our controller was receiving page and page_size in both requests.

We were able to fix this by restarting the test client between calls (as explained in Laravel 4 controller tests - ErrorException after too many $this->call() - why?):

public function testFetchingPaginatedEntities() {
    $response = $this->call('GET', "foos?page=1&page_size=1");
    // assertions

    $this->client->restart();

    $response = $this->call('GET', "foos");
    // some more assertions
}

We are now considering porting our project to Laravel 5, but it looks like $this->client is no longer available in tests since L5 no longer uses Illuminate\Foundation\Testing\Client.

Could anybody provide an alternative for resetting the test client? Or maybe a way to avoid restarting it at all?

like image 533
cafonso Avatar asked Oct 20 '22 17:10

cafonso


1 Answers

$this->refreshApplication();

between calls solved the issue for me on Laravel 5.4.

like image 159
alexeydemin Avatar answered Oct 27 '22 19:10

alexeydemin