【问题标题】:Running unit test with the Yii framework使用 Yii 框架运行单元测试
【发布时间】:2013-08-03 03:58:06
【问题描述】:

背景

我正在使用 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);
    }

}

问题

我做错了什么? 我应该如何运行我的测试?

【问题讨论】:

    标签: php yii phpunit


    【解决方案1】:

    问题出在测试/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);
    

    【讨论】:

      猜你喜欢
      • 2012-04-09
      • 2011-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      相关资源
      最近更新 更多