douduikai0562 2012-06-13 21:34
浏览 48
已采纳

Yii - 模块中的功能单元测试时出现CHttpRequest错误

When I'm trying to execute a functional unittest of a module within my Yii code, I keep receiving the following error:

CException: CHttpRequest is unable to determine the request URI.

At first, I though it was because it couldn't find the module. However, If I change the url to a wrong one, I get a correct error,s tating it couldn't find the view.

This is how my testing code looks like

public function testViewControllerModule()
{
    ob_start();
    Yii::app()->runController('module/controller/view');
}

Any ideas on what I might be missing?

  • 写回答

2条回答 默认 最新

  • dsb238100 2012-06-21 03:03
    关注

    I think it's because you haven't set any server variables, i.e $_SERVER and you might be doing something like this in your controller:

    Yii::app()->request ....
    

    So before you run your test, make sure you use a fixture for the server variables also. I think this should suffice for now:

    $_SERVER=array(
        'REQUEST_URI'=>'index.php', // the other fields should follow
    );
    

    However to run functional tests i would recommend using SeleniumRC, you won't have to do these workarounds then, and can simulate user clicks also, i think.

    Read the initial guide to Functional Testing , read the selenium rc phpunit guide, and also the CWebTestCase documentation.

    Notes: You might still have to use fixtures for some variables, and i don't have much experience in testing(which is bad), so i'm not very sure if i am completely correct about selenium.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!