ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 从单一测试中调用路由 你可以使用 call 方法,轻易地调用你的任何一个路由来测试: ~~~ $response = $this->call('GET', 'user/profile'); $response = $this->call($method, $uri, $parameters, $cookies, $files, $server, $content); ~~~ 接着你可以检查 Illuminate\Http\Response 对象: ~~~ $this->assertEquals('Hello World', $response->getContent()); ~~~ ## 从测试调用控制器 你也可以从测试调用控制器: ~~~ $response = $this->action('GET', 'HomeController@index'); $response = $this->action('GET', 'UserController@profile', ['user' => 1]); ~~~ `注意: 当使用 action 方法的时候,你不需要指定完整的控制器命名空间。只需要指定 App\Http\Controllers 命名空间后面的类名称部分。` getContent 方法会返回求值后的字串内容响应。如果你的路由返回一个 View,你可以通过 original 属性访问它: ~~~ $view = $response->original; $this->assertEquals('John', $view['name']); ~~~ 你可以使用 callSecure 方法去调用 HTTPS 路由: ~~~ $response = $this->callSecure('GET', 'foo/bar'); ~~~