duandan9680 2012-07-29 19:08
浏览 33
已采纳

Yii Fixtures - 例外:类'ProjectTest'的未知属性'项目'

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...

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

How can i make it work?

Thank you for your help

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' =>'',
    ),

),

?>

my Project test class: C:\wamp\www\agileBook\protected\tests\unit\ProjectTest.php

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');

    }

}

?>

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',
        ),
    ),
)
);
  • 写回答

2条回答 默认 最新

  • douxiezha9319 2012-07-30 00:48
    关注

    I found the error...

    public $fixtures = array('projects'=>'Project'); 
    

    fixture need a "S"

    Hope it help someone

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘