Unknown method 'setAttributes' for class 'Project'

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.

There’s a naming collision between the test case class and the model class (both are called “Project”). Rename test case to “ProjectTest”.

What a stupid typo!

Thank you very much, phtamas.