W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
你可以使用 call 方法,輕易地調(diào)用你的任何一個(gè)路由來測試:
$response = $this->call('GET', 'user/profile');
$response = $this->call($method, $uri, $parameters, $cookies, $files, $server, $content);
接著你可以檢查 Illuminate\Http\Response 對(duì)象:
$this->assertEquals('Hello World', $response->getContent());
你也可以從測試調(diào)用控制器:
$response = $this->action('GET', 'HomeController@index');
$response = $this->action('GET', 'UserController@profile', ['user' => 1]);
注意: 當(dāng)使用 action 方法的時(shí)候,你不需要指定完整的控制器命名空間。只需要指定 App\Http\Controllers 命名空間后面的類名稱部分。
getContent 方法會(huì)返回求值后的字串內(nèi)容響應(yīng)。如果你的路由返回一個(gè) View,你可以通過 original 屬性訪問它:
$view = $response->original;
$this->assertEquals('John', $view['name']);
你可以使用 callSecure 方法去調(diào)用 HTTPS 路由:
$response = $this->callSecure('GET', 'foo/bar');
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: