我们正在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
}
正如您所看到的,第二个请求不携带任何查询字符串参数。然而,我们注意到我们的控制器在两个请求中都接收到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
}
我们现在正在考虑将我们的项目移植到Laravel 5,但由于L5不再使用Illuminate'Foundation'Testing'Client
,$this->client
在测试中似乎不再可用。
有人能提供重置测试客户端的替代方案吗?或者可能是一种避免重新启动的方法?
$this->refreshApplication();
两次通话之间为我解决了Laravel 5.4的问题。