【问题标题】:Multiple HTTP requests in Laravel 5 integration testsLaravel 5 集成测试中的多个 HTTP 请求
【发布时间】:2015-04-10 03:22:21
【问题描述】:

我们正在 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
}

如您所见,第二个请求没有携带任何查询字符串参数。但是,我们注意到我们的控制器在两个请求中都收到了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

谁能提供重置测试客户端的替代方法?或者可能是一种完全避免重新启动它的方法?

【问题讨论】:

标签: php integration-testing laravel-5


【解决方案1】:
$this->refreshApplication();

通话之间为我解决了 Laravel 5.4 上的问题。

【讨论】:

  • 如果您使用 sqlite :memory: 进行测试,这将不起作用
猜你喜欢
  • 1970-01-01
  • 2022-01-02
  • 2020-03-06
  • 2021-01-25
  • 2019-08-19
  • 2015-08-07
  • 2021-12-23
  • 1970-01-01
  • 2023-04-02
相关资源
最近更新 更多