assertRedirectedToRoute在Laravel 5.1中不起作用 [英] assertRedirectedToRoute not working in Laravel 5.1

查看:74
本文介绍了assertRedirectedToRoute在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆