如何在 Yii 1.1 中运行 php 单元测试

How to run php unit tests in Yii 1.1

请帮忙。我已经在这里好几天了。

PHPUnit 版本:4.4.0

每当我尝试运行单元测试时,我都会收到此错误:

PHP Fatal error: Uncaught exception 'CException' with message 'CHttpRequest is unable to determine the request URI.' in /var/www/framework/web/CHttpRequest.php:519

我的 bootstrap 文件:

// change the following paths if necessary
set_include_path(get_include_path() . PATH_SEPARATOR . '/var/www/protected/config/vendor/phpunit/phpunit-selenium');
$yiit=dirname(__FILE__).'/../../framework/yiit.php';
$config=dirname(__FILE__).'/../config/test.php';

require_once($yiit);
require_once(dirname(__FILE__).'/WebTestCase.php');

Yii::createWebApplication($config);

错误堆栈跟踪:

#0 /vagrant/black-box/framework/web/CHttpRequest.php(431): CHttpRequest->getRequestUri()
#1 /vagrant/black-box/framework/web/CUrlManager.php(364): CHttpRequest->getPathInfo()
#2 /vagrant/black-box/protected/extensions/yii-debug-toolbar/YiiDebugToolbarRoute.php(113): CUrlManager->parseUrl(Object(CHttpRequest))
#3 /vagrant/black-box/framework/logging/CLogRouter.php(66): YiiDebugToolbarRoute->init()
#4 /vagrant/black-box/framework/base/CModule.php(387): CLogRouter->init()
#5 /vagrant/black-box/framework/base/CModule.php(523): CModule->getComponent('log')
#6 /vagrant/black-box/framework/base/CApplication.php(164): CModule->preloadComponents()
#7 /vagrant/black-box/framework/YiiBase.php(125): CApplication->__construct('/vagrant/black-...')
#8 /vagrant/black-box/framework/YiiBase.php(98): YiiBase::createApplication('CWebApplication', '/vagrant/blac in /vagrant/black-box/framework/web/CHttpRequest.php on line 519

看起来您已经在配置中配置了 YiiDebugToolbarRoute。 这仅在 web 环境中有用,并且会在此处引起问题。

从测试环境中的应用程序配置中删除日志记录配置。