【发布时间】:2016-04-16 17:47:51
【问题描述】:
我正在尝试使用 yii 实现单元测试。我去 protected\tests\unit 文件夹并运行 phpunit\AccountTest
我得到错误 Class 'CDbTestCase' not found in ......tests\unit\AccountTest.php
我是单元测试的新手,我不确定我是否正确设置它。谁能告诉我我做错了什么?
【问题讨论】:
我正在尝试使用 yii 实现单元测试。我去 protected\tests\unit 文件夹并运行 phpunit\AccountTest
我得到错误 Class 'CDbTestCase' not found in ......tests\unit\AccountTest.php
我是单元测试的新手,我不确定我是否正确设置它。谁能告诉我我做错了什么?
【问题讨论】:
如果您的 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 有时无法正确引导。
【讨论】: