iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 3
0
Modern Web

Laravel Testing系列 第 3

第三天: HTTP Tests

想要學好測試,就要先了解測試工具是如何使用,如前二天所說: Laravel 是個可測試的 Framework 所以我們就來看看 Laravel 提供了哪些好用的測試工具吧。(只講些我常用的部份)

Middleware

withoutMiddleware

取消所有 middleware 或者 $middleware 可用陣列帶入取消多個特定 middleware

$this->withoutMiddleware($middleware = null);

withMiddleware

加入特定 middleware

$this->withMiddleware($middleware);

Authentication

actingAs

模擬使用者已登入的狀態

$this->actingAs(UserContract $user, $driver = null);

CRUD

GET

$response = $this->get($uri, array $headers = []);

POST

$response = $this->post($uri, array $data = [], array $headers = []);

PUT

$response = $this->put($uri, array $data = [], array $headers = []);

DELTE

$response = $this->delete($uri, array $data = [], array $headers = []);

JSON CRUD

GET

$response = $this->getJson($uri, array $headers = []);

POST

$response = $this->postJson($uri, array $data = [], array $headers = []);

PUT

$response = $this->putJson($uri, array $data = [], array $headers = []);

DELTE

$response = $this->deleteJson($uri, array $data = [], array $headers = []);

上一篇
第二天: 在 Laravel 如何快速建立測試?
系列文
Laravel Testing3
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言