Yii Framework Forum: Unknown method 'setAttributes' for class 'Project' - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Unknown method 'setAttributes' for class 'Project' Rate Topic: -----

#1 User is offline   paul0001 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 21-July 11

Posted 21 July 2011 - 11:46 PM

I follow the steps in the chapter 5 of the book 'Agile Web Application Development with Yii 1.1 and PHP5' published by Packtpub. It's about generate an AR for a simple table 'tbl_project' (using sqlite). When I test it with phpunit, it prints the following error:

PHPUnit 3.5.14 by Sebastian Bergmann.

.E

Time: 0 seconds, Memory: 8.75Mb

There was 1 error:

1) Project::testCRUB
Exception: Unknown method 'setAttributes' for class 'Project'.

/var/www/html/yii/framework/test/CDbTestCase.php:76
/var/www/html/trackstar/protected/tests/unit/ProjectTest.php:18
/var/www/html/trackstar/protected/tests/unit/ProjectTest.php:18

Code used for testing:
class Project extends CDbTestCase
{
        public function testCRUB()
        {
                // Create a new project
                $newProject = new Project;
                $newProjectName = 'Test Project 1';
                $newProject->setAttributes(
                        array(
                                'name' => $newProjectName,
                                'description' => 'Test project number one',
                                'create_time' => '2011-01-01 00:00:00',
                                'create_user_id' => 1,
                                'update_time' => '2011-01-02 00:00:00',
                                'update_user_id' => 1,
                        )
                );
                $this->assertTrue($newProject->save(false));
        }
}

But I have no problem when using PDO to access the sqlite file.

Any help is appreciated.
0

#2 User is offline   phtamas 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 529
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 22 July 2011 - 10:47 AM

There's a naming collision between the test case class and the model class (both are called "Project"). Rename test case to "ProjectTest".
0

#3 User is offline   paul0001 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 21-July 11

Posted 23 July 2011 - 02:25 PM

What a stupid typo!

Thank you very much, phtamas.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users