Testing action with redirect gives uexpectable behavior in yii2

一个人想着一个人 提交于 2019-12-13 05:51:15

问题


I try to test my app with codeception, but all LoginCept.php breaks on this aciton

class SiteController extends Controller {
    public function actionIndex() {
        $this->redirect('journal');
    }
}

As I can see in the php-buildin-server's logs, after in-app redirect it comes to actual entry point index.php instead of index-test.php

[Thu Jun  9 20:54:00 2016] 127.0.0.1:40472 [302]: /index-test.php/login
[Thu Jun  9 20:54:00 2016] 127.0.0.1:40496 [302]: /index-test.php << in-app redirect
[Thu Jun  9 20:54:00 2016] 127.0.0.1:40506 [500]: /journal

So test fails due to this unexpected behavior. How to enforce application's redirects to work at the same entry point script?


回答1:


Need to wrap URI into Url::to() to add all stuff, that yii2 uses. So funciton call should looks like this

$this->redirect(Url::to('to/something'));


来源:https://stackoverflow.com/questions/37727689/testing-action-with-redirect-gives-uexpectable-behavior-in-yii2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!