想要學好測試,就要先了解測試工具是如何使用,如前二天所說: Laravel 是個可測試的 Framework 所以我們就來看看 Laravel 提供了哪些好用的測試工具吧。(只講些我常用的部份)
取消所有 middleware 或者 $middleware 可用陣列帶入取消多個特定 middleware
$this->withoutMiddleware($middleware = null);
加入特定 middleware
$this->withMiddleware($middleware);
模擬使用者已登入的狀態
$this->actingAs(UserContract $user, $driver = null);
$response = $this->get($uri, array $headers = []);
$response = $this->post($uri, array $data = [], array $headers = []);
$response = $this->put($uri, array $data = [], array $headers = []);
$response = $this->delete($uri, array $data = [], array $headers = []);
$response = $this->getJson($uri, array $headers = []);
$response = $this->postJson($uri, array $data = [], array $headers = []);
$response = $this->putJson($uri, array $data = [], array $headers = []);
$response = $this->deleteJson($uri, array $data = [], array $headers = []);