Laravel 5集成测试中的多个HTTP请求

caf*_*nso 5 php integration-testing laravel-5

我们正在Laravel 4中开发我们的项目.我们的一个集成测试对同一个控制器执行两个连续的HTTP请求:

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

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

如您所见,第二个请求不携带任何查询字符串参数.然而,我们注意到,我们的控制器被接收page,并page_size在这两个请求.

我们能够通过在调用之间重新启动测试客户端来解决这个问题(如Laravel 4控制器测试中所述 - 在过多$ this-> call()之后出现ErrorException - 为什么?):

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
}
Run Code Online (Sandbox Code Playgroud)

我们现在正在考虑将我们的项目移植到Laravel 5,但是$this->client由于L5不再使用,它看起来不再适用于测试Illuminate\Foundation\Testing\Client.

有人可以提供重置测试客户端的替代方案吗?或者也许是一种避免重启它的方法?

ade*_*min 5

$this->refreshApplication();
Run Code Online (Sandbox Code Playgroud)

Between Calls 为我解决了 Laravel 5.4 上的问题。