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

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集