致命错误:找不到类“CDbTestCase" yii 框架 [英] Fatal error: Class 'CDbTestCase' not found yii framework

查看:28
本文介绍了致命错误:找不到类“CDbTestCase" yii 框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注使用 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 配置夹具后,我正在第 6 章运行我的单元测试,它返回给我这个

I'm running my unit test at chapter 6 after configuring fixture with PHPunit and it returns me this

Last login: Sat Oct  6 20:09:36 on ttys000
xyz-MacBook-Pro:~ inganious$ /usr/local/bin/phpunit/phpunit /Applications/MAMP/htdocs/trackstar/protected/tests/unit/ProjectTest.php

Fatal error: Class 'CDbTestCase' not found in /Applications/MAMP/htdocs/trackstar/protected/tests/unit/ProjectTest.php on line 3
xyz-MacBook-Pro:~ inganious$ 

这是我的 ProjectTest.php 文件

Here is my ProjectTest.php file

class ProjectTest extends CDbTestCase
{

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

    public function testCreate()
      {
        //CREATE a new Project
        $newProject=new Project;
        $newProjectName = 'Test Project Creation';
        $newProject->setAttributes(array(
        'name' => $newProjectName,
        'description' => 'This is a test for new project creation',
        'createTime' => '2009-09-09 00:00:00',
        'createUser' => '1',
        'updateTime' => '2009-09-09 00:00:00',
        'updateUser' => '1',
        )
      );
        $this->assertTrue($newProject->save(false));
        //READ back the newly created Project to ensure the creation worked

        $retrievedProject=Project::model()->findByPk($newProject->id);
        $this->assertTrue($retrievedProject instanceof Project);
        $this->assertEquals($newProjectName,$retrievedProject->name);
      }
        public function testRead()
      {
        $retrievedProject = $this->projects('project1');
        $this->assertTrue($retrievedProject instanceof Project);
        $this->assertEquals('Test Project 1',$retrievedProject->name);
      }
        public function testUpdate()
      {
        $project = $this->projects('project2');
        $updatedProjectName = 'Updated Test Project 2';
        $project->name = $updatedProjectName;
        $this->assertTrue($project->save(false));
        //read back the record again to ensure the update worked
        $updatedProject=Project::model()->findByPk($project->id);
        $this->assertTrue($updatedProject instanceof Project);
        $this->assertEquals($updatedProjectName,$updatedProject->name);
      }
        public function testDelete()
      {
        $project = $this->projects('project2');
        $savedProjectId = $project->id;
        $this->assertTrue($project->delete());
        $deletedProject=Project::model()->findByPk($savedProjectId);
        $this->assertEquals(NULL,$deletedProject);
    }
}

有人可以帮忙吗?

推荐答案

检查 pŕotected/tests 中的引导程序文件是否指向正确的路径,并检查同一文件夹中的 WebTastCase.php 文件是否指向正确的路径 'TEST_BASE_URL',类似于:

check if you bootstrap file in pŕotected/tests is pointing to the right paths and check if the WebTastCase.php file in the same folder is poiting to the right 'TEST_BASE_URL', something like:

define('TEST_BASE_URL','http://localhost/my_app/index-test.php/');

并尝试从 protected/tests 文件夹中运行 phpunit

and try to run phpunit from inside the protected/tests folder

这篇关于致命错误:找不到类“CDbTestCase" yii 框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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