【发布时间】: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
}
如您所见,第二个请求没有携带任何查询字符串参数。但是,我们注意到我们的控制器在两个请求中都收到了page 和page_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。
谁能提供重置测试客户端的替代方法?或者可能是一种完全避免重新启动它的方法?
【问题讨论】:
-
可能与此有关 - github.com/laravel/framework/issues/6373 - 我前段时间报告过 - 仍未修复。
-
谢谢,我会留意的。
-
@TheShiftExchange 仅供参考,我在 Github 中打开了一个问题,看起来他们已经修复了它:github.com/laravel/framework/pull/7380
-
@cafonso:所以,这意味着
$this->client->restart()不再需要了? -
@spacek33z 还没有真正尝试过,因为我们暂时停留在 L4,但是,是的,它应该不再需要了。 IIRC,这是解决问题的具体提交:github.com/laravel/framework/commit/…
标签: php integration-testing laravel-5