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?
$this->refreshApplication();
between calls solved the issue for me on Laravel 5.4.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With