【发布时间】:2016-04-06 19:57:21
【问题描述】:
我有一个单元测试,我正在测试我的 Laravel 控制器。我正在对我的控制器操作执行 POST,该操作将返回带有参数的重定向。如何获取重定向 URL 位置并获取控制器和操作。我不关心参数,我只想确认正确的控制器和动作。
$crawler = $this->action('POST', 'ItemController@postItem', array(), $data);
$this->assertResponseStatus(302);
$redirecturl = $this->client->getResponse()->headers->get('Location');
// $redirecturl = http://localhost/item/{uid}/edit
// how do I get controller and action from url ???
// e.g. http://localhost/item/{uid}/edit = ItemController@getEdit from routes
谢谢。
【问题讨论】:
-
那么您需要遵循路线中的模式。比如
controller/actionName -
“那么你需要在路线中遵循一个模式”,这是我的问题,你是怎么做到的?