Yii固定装置---例外:类'ProjectTest'的未知属性'projects' [英] Yii Fixtures --- Exception: Unknown property 'projects' for class 'ProjectTest'
问题描述
我正在学习使用yii 1.1和php5进行敏捷Web应用程序开发"这本书,并且正在使用夹具测试"部分.我遵循了他们的代码,但是我无法使用灯具...
I'm following the "Agile web application development with yii 1.1 and php5" book and i'm at the testing with fixtures section. I followed their code but i can't access to the fixture...
我正在用phpunit运行测试,并且返回了这个信息
I'm running my tests with phpunit and it returns me this
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 \ protected \ tests \ fixtures \ tbl_project.php
my fixture: C:\wamp\www\agileBook\protected\tests\fixtures\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 \ protected \ tests \ unit \ ProjectTest.php
my Project test class: C:\wamp\www\agileBook\protected\tests\unit\ProjectTest.php
我将$ this-> projects('project1')更改为$ this-> projects ['project1'],因为我在论坛上看到项目是数组而不是方法. /p>
I changed $this->projects('project1') (from the book) for $this->projects['project1'], cause i see in a forum post that projects is an array and not a method.
<?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 \ protected \ config \ test.php
my test config: C:\wamp\www\agileBook\protected\config\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',
),
),
)
);
推荐答案
我发现了错误...
public $fixtures = array('projects'=>'Project');
灯具需要一个"S"
希望它能帮助到某人
这篇关于Yii固定装置---例外:类'ProjectTest'的未知属性'projects'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!