将phpunit与yii一起使用-无法识别父类
我为我在Yii中创建的模型编写了一个小测试用例,当我尝试运行测试时,它给出了:致命错误:类将phpunit与yii一起使用-无法识别父类,php,yii,phpunit,Php,Yii,Phpunit,我为我在Yii中创建的模型编写了一个小测试用例,当我尝试运行测试时,它给出了:致命错误:类 '.....\ActiveRecord' not found in Commissions.php' 现在,我的类(commissions.php)继承了Yii中的ActiveRecord类,但是我如何告诉PHPunit在哪里可以找到它呢?我已经尝试在Commissions.php中使用include语句,但是它找不到ActiveRecord继承的类,等等 <?php include_once(
'.....\ActiveRecord' not found in Commissions.php'
现在,我的类(commissions.php)继承了Yii中的ActiveRecord类,但是我如何告诉PHPunit在哪里可以找到它呢?我已经尝试在Commissions.php中使用include语句,但是它找不到ActiveRecord继承的类,等等
<?php
include_once('Commissions.php');
class CommissionsTest extends PHPUnit_Framework_TestCase
{
// Here, the idea would be to check one or two employees manually or based on the SQL query
// Or even a previous value using the function so that when any changes are made, the value
// remains the same while using the same arguments.
public function setUp()
{
$this->employee = new Commissions();
$this->employee->employeeId = 'V1S';
$this->employee->year = 2012;
$this->employee->period = 1;
}
public function testAttributes()
{
$this->assertEquals('V1S', $this->employee->employeeId);
$this->assertEquals(2012, $this->employee->year);
$this->assertEquals(1, $this->employee->period);
}
}
?>
在测试用例开始时,您应该拥有:
Yii:import('application.models.Commissions'); //or whatever your model is called
class CommissionsTest extends CDbTestCase { //Not PHPUnit_Framework_TestCase
您需要包括YII类加载器。谢谢您的评论。在这种情况下,我具体怎么做?我对使用这个框架非常陌生(我也是;)我已经看过这一章,可能会有所帮助:-他们的测试用例从一个Yii基本测试类扩展而来。我想他们会处理自动加载的问题。作为一个答案,这个评论看起来会很好我试着像医生说的那样使用
CDbTestCase
,但仍然有同样的问题:(