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条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失