assertRedirectedToRoute在Laravel 5.1中不起作用 [英] assertRedirectedToRoute not working in Laravel 5.1
问题描述
控制器代码:
return redirect()->route('admin.patient.edit', $patientId);
测试代码:
$this->visit(route('admin.patient.edit', $this->patient->id))
->press('Update');
$this->assertRedirectedToRoute('admin.patient.edit', [$this->patient->id]);
我得到的错误是:
Failed asserting that Illuminate\Http\Response Object (...) is an instance of class
"Illuminate\Http\RedirectResponse".
我已经从测试内部和控制器内部打印出了响应,实际上它是一个RedirectReponse对象.有什么想法吗?
I've printed out the response from the inside the test and inside the controller and it is in fact a RedirectReponse Object. Any ideas?
推荐答案
尝试替换
$this->assertRedirectedToRoute('admin.patient.edit', [$this->patient->id]);
与
$this->assertRedirectedToAction('MyController@myMethod');
您已经在路线admin.patient.edit
一条路由应该是对edit
方法的GET请求,而另一条路由应该是对update()
方法的post
请求.您正在重定向到相同的确切路由(即GET路由). admin.patient.update
将是该路线的更好名称
One route should be a GET request for the edit
method, and the other should be a post
request for the update()
method. You are redirecting to the same exact route (i.e the GET route). admin.patient.update
would be a better name for that route
这篇关于assertRedirectedToRoute在Laravel 5.1中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!