【问题标题】:Class 'CDbTestCase' not found error in phpunit with yii使用 yii 在 phpunit 中找不到类“CDbTestCase”错误
【发布时间】:2016-04-16 17:47:51
【问题描述】:

我正在尝试使用 yii 实现单元测试。我去 protected\tests\unit 文件夹并运行 phpunit\AccountTest

我得到错误 Class 'CDbTestCase' not found in ......tests\unit\AccountTest.php

我是单元测试的新手,我不确定我是否正确设置它。谁能告诉我我做错了什么?

【问题讨论】:

    标签: yii phpunit


    【解决方案1】:

    如果您的 bootstrap.php 脚本中的路径不正确,就会发生这种情况。

    您的 protected/tests/bootstrap.php 文件应如下所示:

    <?php
    
    // change the following paths if necessary
    $yiit=dirname(__FILE__).'/../../../framework/yiit.php';
    $config=dirname(__FILE__).'/../config/test.php';
    
    require_once($yiit);
    require_once(dirname(__FILE__).'/WebTestCase.php');
    
    Yii::createWebApplication($config);
    

    注意第 4-5 行。路径将根据您安装 Yii 和应用程序的方式而有所不同。查看文件的位置,并确保这些路径指向正确的位置。

    我还建议从 protected/tests 内部运行 PHPUnit,而不是 protected/tests/unit。例如:

    cd protected\tests
    phpunit unit\AccountTest.php
    

    如果从unit 文件夹内运行,PHPUnit 有时无法正确引导。

    【讨论】:

    • 非常感谢。现在我明白了。 “PHP 警告:require_once(PHPUnit/Extensions/SeleniumTestCase.php):无法打开流:没有这样的文件或目录...”我知道我必须单独安装 Selenium。但不知道如何做到这一点。我正在使用窗户。有人说不支持梨安装等等等等。
    • 可能是您需要在 PATH 环境变量中添加一些内容,或者可能是 phpunit.bat 中的文件路径不正确。 Yii 论坛的这个帖子看起来可能会有所帮助:yiiframework.com/forum/index.php/topic/…
    猜你喜欢
    • 1970-01-01
    • 2015-08-16
    • 2016-02-17
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    • 2013-06-10
    • 2012-12-21
    • 2022-01-02
    相关资源
    最近更新 更多