我继“敏捷Web应用开发与谊1.1和PHP5”的书,我在用夹具部分进行测试。 我跟着他们的代码,但我不能访问到灯具...
我跑我的测试使用PHPUnit并返回我这个
c:\wamp\www\agileBook\protected\tests>phpunit unit/ProjectTest.php
PHPUnit 3.6.11 by Sebastian Bergmann.
Configuration read from C:\wamp\www\agileBook\protected\tests\phpunit.xml
←[31;1mE←[0m
Time: 0 seconds, Memory: 5.75Mb
There was 1 error:
1) ProjectTest::testRead
Exception: Unknown property 'projects' for class 'ProjectTest'.
C:\wamp\yii\framework\test\CDbTestCase.php:63
C:\wamp\www\agileBook\protected\tests\unit\ProjectTest.php:11
C:\wamp\bin\php\php5.3.13\phpunit:46
←[37;41m←[2KFAILURES!
←[0m←[37;41m←[2KTests: 1, Assertions: 0, Errors: 1.
←[0m←[2K
我怎样才能使它发挥作用?
谢谢您的帮助
我的灯具:C:\ WAMP \ WWW \ agileBook \保护\测试\灯具\ tbl_project.php
<?php
return array(
'project1' => array(
'name' => 'Test Project 1',
'description' =>'This is test project 1',
'create_time' =>'',
'create_user_id' =>'',
'update_time' =>'',
'update_user_id' =>'',
),
'project2' => array(
'name' => 'Test Project 2',
'description' =>'This is test project 2',
'create_time' =>'',
'create_user_id' =>'',
'update_time' =>'',
'update_user_id' =>'',
),
),
?>
我的项目测试类:C:\ WAMP \ WWW \ agileBook \保护\测试\单位\ ProjectTest.php
我这 - >项目(“PROJECT1”)(从书)公司招聘$>项目[“PROJECT1”]改变$,因为我在一个论坛帖子投射是一个数组,而不是一个方法见。
<?php
class ProjectTest extends CDbTestCase{
public $fixture = array('projects'=>'Project');
public function testRead(){
// READ the new project
$receivedProject = $this->projects['project1'];
$this->assertTrue($receivedProject instanceof Project);
$this->assertEquals($receivedProject->name,'Test Project 1');
}
}
?>
我的测试配置:C:\ WAMP \ WWW \ agileBook \保护\设置\ test.php的
<?php
return CMap::mergeArray(
require(dirname(__FILE__).'/main.php'),
array(
'components'=>array(
'fixture'=>array(
'class'=>'system.test.CDbFixtureManager',
),
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=trackstar_test',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
),
)
);