多个HTTP请求测试

问题描述:

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

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

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

正如你所看到的,第二个请求不带任何查询字符串参数。但是,我们注意到我们的控制器在两个请求中都收到了pagepage_size

我们能够通过重新启动之间的通话测试客户端(如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 
} 

现在我们正在考虑移植我们的项目到Laravel 5,但它看起来像$this->client不再由于L5不再使用Illuminate\Foundation\Testing\Client,因此可以在测试中使用。

任何人都可以提供重置测试客户端的替代方案吗?或者也许有办法避免重新启动它?

+1

可能与此有关 - https://github.com/laravel/framework/issues/6373 - 我刚才报道 - 仍然没有修复。 – Laurence 2015-02-10 07:06:45

+0

谢谢,我会密切关注它。 – cafonso 2015-02-10 07:35:59

+1

@TheShiftExchange fyi,我在Github上打开了一个问题,看起来他们已经修复了它:https://github.com/laravel/framework/pull/7380 – cafonso 2015-02-10 19:09:34

$this->refreshApplication() ; 

调用之间解决了我在Laravel 5.4上的问题。