Yii灯具问题? [英] Yii Fixtures Issue?

查看:92
本文介绍了Yii灯具问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎对Yii的灯具有问题.问题似乎如下,

I seem to be having a problem with fixtures in Yii. The problem seems to be the following,

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

模型Project存在,并且我在测试的fixtures文件夹中的文件名为tbl_project.php包含了灯具,而我的表名为tbl_project.夹具文件中的内容如下.

The model Project exists and I have the fixtures in a file name tbl_project.php in the fixtures folder of tests and my table name is called tbl_project. Inside the fixtures file is the following.

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' => '',
         ),
        'project3' => array(
            'name' => 'Test Project 3',
            'description' => 'This is test project 3',
            'create_time' => '',
            'create_user_id' => '',
            'update_time' => '',
            'update_user_id' => '',
         ),
    );       

这实际上是《用Yii进行敏捷Web应用程序开发》一书中的内容.当我运行测试用例时,我得到以下内容,而没有任何测试结果信息.

This is actually from the book "Agile Web Application Development with Yii". When I run the test case I get the following with no test result information.

PHPUnit 3.6.10 by Sebastian Bergmann.

Configuration read from ETC/protected/tests/phpunit.xml

如果从顶部移除固定装置阵列,则会得到以下内容.

If I remove the fixtures array from the top I get the following.

Time: 0 seconds, Memory: 9.25Mb

There was 1 error:

1) ProjectTest::testRead
Exception: Unknown method 'projects' for class 'ProjectTest'. 

这显然是有道理的.我不知道我在做什么错.

Which obviously makes sense. I dont know what Im doing wrong.

推荐答案

  1. 确保测试类看起来像这样


    class ProjectTest extends CDbTestCase{

    protected $fixtures = array(
                'projects' => 'Project',
            );

    public function testRead(){

        $receivedProject = $this->projects('Project1');
        $this->assertTrue($receivedProject instanceof Project);
        $this->assertEquals($receivedProject->name,'test 1');
    }
    ...`

  1. 在protected/config/test.php中检查灯具配置...应该看起来像...



    ...
    'components'=>array(
            'fixture'=>array(
                'class'=>'system.test.CDbFixtureManager',
            ),
                        'db'=>array(
                            'connectionString' =>'mysql:host=localhost;dbname=your_db_name',
                            'emulatePrepare' => true,
                            'username' => 'username',
                            'password' => 'passwd',
                            'charset' => 'utf8',
                        ),
    ....

  1. 最终检查设备文件的权限,以确保可以读取

这篇关于Yii灯具问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆