5

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?

Community
  • 1
  • 1
cafonso
  • 909
  • 11
  • 18
  • 1
    Might be related to this - https://github.com/laravel/framework/issues/6373 - i reported it a while ago - still not fixed. – Laurence Feb 10 '15 at 07:06
  • Thank you, i'll keep an eye on it. – cafonso Feb 10 '15 at 07:35
  • 1
    @TheShiftExchange fyi, I opened an issue in Github and it looks like they have already fixed it: https://github.com/laravel/framework/pull/7380 – cafonso Feb 10 '15 at 19:09
  • @cafonso: so, this means that `$this->client->restart()` is not needed anymore? – spacek33z Mar 10 '15 at 19:53
  • @spacek33z Haven't really tried because we stayed on L4 for the time being, but yeah, it should not be needed anymore. IIRC, this is the specific commit which fixed the issue: https://github.com/laravel/framework/commit/7861640f4d5c55b066f0ac5f017006d972e20b14 – cafonso Mar 11 '15 at 08:03

1 Answers1

5
$this->refreshApplication();

between calls solved the issue for me on Laravel 5.4.

alexeydemin
  • 2,672
  • 3
  • 27
  • 26