配置/ test.php的
'components'=>array(
'fixture'=>array(
'class'=>'system.test.CDbFxtureManager'
),
),
Run Code Online (Sandbox Code Playgroud)
tests/unit/EntityTest.php(扩展CDbTestCase)
public $fixtures = array('entities'=>'Entity'),
Run Code Online (Sandbox Code Playgroud)
测试/夹具/ Entity.php
return array(
'entity1'=>array('slug'=>'slug1', 'title'=>'title1'),
'entity2'=>array('slug'=>'slug2', 'title'=>'title2'),
);
Run Code Online (Sandbox Code Playgroud)
现在,在EntityTest类中,我尝试获取我的实体
$entities = $this->entities;
$entity = $this->entities('entity1');
Run Code Online (Sandbox Code Playgroud)
输出是'Unknown property'实体"for class"EntityTest"'.测试类是'Entity',数据库中的表名是'tbl_entity','tablebrefix'选项'CDbConnection'组件设置为'tbl_'