Yii Framework Forum: [SOLVED]Fixture problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[SOLVED]Fixture problem help

#1 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 299
  • Joined: 05-November 10

Posted 19 November 2010 - 03:41 AM

why does my PHPUnit is complaining that 'projects' is an unknown method, when it's not a method at all

Posted Image


here's my test.php file code inside the config folder

<?php

return CMap::mergeArray(
	require(dirname(__FILE__).'/main.php'),
	array(
		'components'=>array(
			'fixture'=>array(
				'class'=>'system.test.CDbFixtureManager',
			),
			//* uncomment the following to provide test database connection
			'db'=>array(
				'connectionString'=>'mysql:host=localhost;dbname=yiitddtest',
                'emulatePrepare' => true,
                'username' => 'root',
                'password' => 'password',
                'charset' => 'utf8',
                'tablePrefix' => 'tbl_'
			),
			
		),
	)
);


here's the ProjectTest.php

<?php
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' => '2010-11-19 00:00:00',
            'createUser' => '1',
            'updateTime' => '2010-11-19 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;
        $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);
    }
    
}


and here's the tbl_project.php from the fixtures folder


<?php

    return array(
        'project1' => array(
            'name'  => 'Test Project 1',
            'description' => 'This is test project1',
            'create_time' => '',
            'create_user_id' => '',
            'update_time' => '',
            'update_user_id' => '',
        ),
        
        'projeect2' => 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' => '',
        ),
    );



did i missed something ?
0

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 19 November 2010 - 04:11 AM

It fails because you have a typo in:
'projeect2' => array(

;)
"Less noise - more signal"
1

#3 User is offline   sasori 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 299
  • Joined: 05-November 10

Posted 19 November 2010 - 04:12 AM

argh, thanks for pointing that out, problem solved
0

#4 User is offline   Daninus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 10-January 11

Posted 10 January 2011 - 01:33 AM

Hi, I'm actually getting the same error, but I checked my code and couldn't find any typos. Could you please help?


Here is my ProjectTest.php

<?php
class ProjectTest extends CDbTestCase
{
	public $fixtures = array(
		'projects' => 'Project', 
    );
	
	/*
	public function testCRUD() 
	{ 
		
		$prjs = $this->projects;
		
		
		//Create a new project 
		$newProject=new Project; 
		$newProjectName = 'Test Project 1'; 
		$newProject->setAttributes(
								array( 
		                        	'name' => $newProjectName, 
		                            'description' => 'Test project number one', 
		                            'create_time' => '2010-01-01 00:00:00', 
		                            'create_user_id' => 1, 
		                            'update_time' => '2010-01-01 00:00:00', 
		                            'update_user_id' => 1, 
		                            )
								); 
		$this->assertTrue($newProject->save(false)); 
		
		//READ back the newly created project 
		$retrievedProject=Project::model()->findByPk($newProject->id); 
		$this->assertTrue($retrievedProject instanceof Project); 
		$this->assertEquals($newProjectName,$retrievedProject->name); 
		
		//UPDATE the newly created project  
		$updatedProjectName = 'Updated Test Project 1'; 
		$newProject->name = $updatedProjectName; 
		$this->assertTrue($newProject->save(false)); 

		//read back the record again to ensure the update worked   
		$updatedProject=Project::model()->findByPk($newProject->id); 
		$this->assertTrue($updatedProject instanceof Project); 
		$this->assertEquals($updatedProjectName,$updatedProject->name); 

		//DELETE the project  
		$newProjectId = $newProject->id; 
		$this->assertTrue($newProject->delete()); 
		$deletedProject=Project::model()->findByPk($newProjectId); 
		$this->assertEquals(NULL,$deletedProject); 
		
		
		
	}
	*/
	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); 
	              } 
				  
				  public function testGetUserOptions(){
						$project = $this->projects('project1');
						$options = $project->userOptions;
						$this->assertTrue(is_array($options));
				  }
	
	
	
} 






Here is my tbl_project.php

<?php
return array(
	'project1'=>array(
		'name' => 'Test Project 1',
		'description' => 'This is test project 1',
		'create_time' => '2009-09-09 00:00:00',
		'create_user_id' => '',
		'update_time' => '2009-09-09 00:00:00',
		'update_user_id' => '',
	),
	'project2'=>array(
		'name' => 'Test Project 2',
		'description' => 'This is test project 2',
		'create_time' => '2009-09-09 00:00:00',
		'create_user_id' => '',
		'update_time' => '2009-09-09 00:00:00',
		'update_user_id' => '',
	),
	'project3'=>array(
		'name' => 'Test Project 3',
		'description' => 'This is test project 3',
		'create_time' => '2009-09-09 00:00:00',
		'create_user_id' => '',
		'update_time' => '2009-09-09 00:00:00', 
		'update_user_id' => '',
	),
);
?>


I would really appreciate your help!

Thank you in advance
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

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