我试着做功能测试,比如在Yii的权威指南中举例。
这是我在tbl_showcase.php中的fixture:
return array(
'sample1'=>array(
'title'=>'Welcome',
'content'=>'A main page test',
'row_type'=>1,
),
'sample2'=>array(
'title'=>'About',
'content'=>'An about page test',
'row_type'=>2,
),
);这是我的测试类:
class ShowcaseTest extends WebTestCase
{
public $fixtures = array('showcase'=>'Showcase');
public function testIndex()
{
$this->open('/');
$this->assertTextPresent($this->showcase['sample1']['title']);
$this->assertTextPresent('Welcome');
$this->assertTextPresent($this->showcase['sample1']['content']);
$this->assertTextPresent('A main page test');
}
}我开始测试
phpunit functional/ShowcaseTest.php并获取下一个错误:
Time: 8 seconds, Memory: 6.25Mb
There was 1 error:
1) ShowcaseTest::testIndex
Exception: Unknown property 'name' for class 'ShowcaseTest'.
/home/myfolder/web/yii/framework/test/CWebTestCase.php:48
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.发布于 2012-02-25 20:50:32
您可以通过显式地将name属性赋予ShowcaseTest类来绕过它,如下所示:
public $fixtures = array('showcase'=>'Showcase');
public $name = 'Something Meaningful';或者查看fixtures文件本身,其中定义了属性。
https://stackoverflow.com/questions/9443372
复制相似问题