简体   繁体   English

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

[英]Multiple HTTP requests in Laravel 5 integration tests

We are developing our projects in Laravel 4. One of our integration tests performs two consecutive HTTP requests to the same controller: 我们正在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
}

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. 但是,我们注意到我们的控制器在两个请求中都接收到pagepage_size

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? ): 我们能够通过在调用之间重新启动测试客户端来解决这个问题(如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
}

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 . 我们现在正在考虑将我们的项目移植到Laravel 5,但看起来$this->client在测试中不再可用,因为L5不再使用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();

在电话之间解决了Laravel 5.4上的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM