背景
我使用Yii框架,刚刚开始为我的项目创建一些单元测试。我试图通过命令行运行我的测试。
$cd www/site/webapp/protected/tests
$phpunit --verbose --colors unit/TaxRateTest.php
问题
我一直得到一个奇怪的回答,我不确定,我不知道如何解决。它似乎没有运行我的测试而是调用Yii命令运行器。
Yii command runner (based on Yii v1.1.14-dev)
Usage: /usr/local/bin/phpunit <command-name> [parameters...]
The following commands are available:
- message
- migrate
- shell
- webapp
To see individual command help, use the following:
/usr/local/bin/phpunit help <command-name>
单元测试类
class TaxRateTest extends CDbTestCase {
public $fixtures = array(
'organisation' => 'Organisation',
);
public function testPopulateTaxRateTable() {
$organisation = New Organisation();
$organisation->display_name = "Test Organisation";
$organisation->country_id = 1;
$organisation->plan_id = Yii::app()->params['default_plan_id'];
$organisation->save();
$tax_rates = TaxRate::model()->findAllByAttributes(array('organisation_id'=>$organisation->id));
$this->assertEquals(count(TaxAccounts::$accounts), count($tax_rates));
//setup the default tax accounts
//TaxAccounts::initialize($this->id);
}
}
问题
我做错了什么? 我应该如何运行我的测试?
答案 0 :(得分:1)
问题出在tests / bootstrap.php上。我更新了$ yiit变量的路径,并将其指向/packages/yiisoft/yii/framework/yiic.php而不是/packages/yiisoft/yii/framework/yiit.php。
我的bootstrap.php文件现在看起来像这样:
<?php
// change the following paths if necessary
$yiit=dirname(__FILE__).'/../packages/yiisoft/yii/framework/yiit.php';
$config=dirname(__FILE__).'/../config/test.php';
require_once($yiit);
require_once(dirname(__FILE__).'/WebTestCase.php');
Yii::createWebApplication($config);