使用重定向测试操作会在yii2中提供可预期的行为 [英] Testing action with redirect gives uexpectable behavior in yii2

查看:109
本文介绍了使用重定向测试操作会在yii2中提供可预期的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用代码接收来测试我的应用程序,但是所有LoginCept.php都在此密码上中断了

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');
    }
}

正如我在php-buildin-server的日志中看到的那样,应用程序内重定向后,它会到达实际的入口点 index.php 而不是 index-test.php

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?

推荐答案

需要将URI包装到 Url :: to() 中,以添加yii2使用的所有内容.所以功能调用应该看起来像这样

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'));

这篇关于使用重定向测试操作会在yii2中提供可预期的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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