所以我正在尝试测试我的 laravel 中间件,它将返回重定向。如果请求不满足中间件的要求,则该请求将被重定向redirect()->route('name')我尝试像这样从中间件获取返回值$response = $middleware->handle($request, function ($req) { return $req; }, 'server:summary:view:edit');\Log::info($response);是$response的实例Illuminate\Http\RedirectResponse。当我这样做时,\Log::info($response);我得到这个结果。HTTP/1.0 302 FoundCache-Control: no-cache, privateDate: Mon, 13 Jul 2020 08:12:27 GMTLocation: https://myrandomurl.test/name<!DOCTYPE html><html> <head> <meta charset="UTF-8" /> <meta http-equiv="refresh" content="0;url='https://myrandomurl.test/name" /> <title>Redirecting to https://myrandomurl.test/name</title> </head> <body> Redirecting to <a href="https://myrandomurl.test/name">https://myrandomurl.test/named</a>. </body></html>那么如何从 Location 标签获取 url 呢?或者如何从 laravel redirectResponse 获取重定向网址?我尝试浏览https://laravel.com/api/5.8/Illuminate/Http/RedirectResponse.html#method_content上的文档,但没有显示重定向路由的方法。我需要路线来断言它以获得成功的测试结果。
1 回答
翻翻过去那场雪
TA贡献2065条经验 获得超13个赞
继承有方法的Illuminate\Http\RedirectResponse
类:Symfony\Component\HttpFoundation\RedirectResponse
getTargetUrl
$response->getTargetUrl();
相反,您可以将其用于assertRedirect
测试目的。
- 1 回答
- 0 关注
- 148 浏览
添加回答
举报
0/150
提交
取消