Yii Framework Forum: PHPUnit problem with fixutre data - Yii Framework Forum

Jump to content

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

PHPUnit problem with fixutre data phpunit and fixtures problem

#1 User is offline   xdolving 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 01-October 10

Posted 29 October 2010 - 11:20 AM

Hi everyone,

I am currently working through the Yii book and every now and then I have problems with phpunit when testing.
I don't understand at all whats wrong, maybe one of you guys can give me directions what I am doing wrong

The errormessage from phpunit:

ProjectTest::testDelete
Failed asserting that Project Object
(
    [_md:CActiveRecord:private] => CActiveRecordMetaData Object
        (
            [tableSchema] => CMysqlTableSchema Object
                (
                    [schemaName] => 
                    [name] => tbl_project
                    [rawName] => `tbl_project`
                    [primaryKey] => id
                    [sequenceName] => 
                    [foreignKeys] => Array
                        (
                        )

                    [columns] => Array
                        (
                            [id] => CMysqlColumnSchema Object
                                (
                                    [name] => id
                                    [rawName] => `id`
                                    [allowNull] => 
                                    [dbType] => int(11)
                                    [type] => integer
                                    [defaultValue] => 
                                    [size] => 11
                                    [precision] => 11
                                    [scale] => 
                                    [isPrimaryKey] => 1
                                    [isForeignKey] => 
                                    [_e:CComponent:private] => 
                                    [_m:CComponent:private] => 
                                )

                            [name] => CMysqlColumnSchema Object
                                (
                                    [name] => name
                                    [rawName] => `name`
                                    [allowNull] => 1
                                    [dbType] => varchar(128)
                                    [type] => string
                                    [defaultValue] => 
                                    [size] => 128
                                    [precision] => 128
                                    [scale] => 
                                    [isPrimaryKey] => 
                                    [isForeignKey] => 
                                    [_e:CComponent:private] => 
                                    [_m:CComponent:private] => 
                                )

                            [description] => CMysqlColumnSchema Object
                                (
                                    [name] => description
                                    [rawName] => `description`
                                    [allowNull] => 1
                                    [dbType] => text
                                    [type] => string
                                    [defaultValue] => 
                                    [size] => 
                                    [precision] => 
                                    [scale] => 
                                    [isPrimaryKey] => 
                                    [isForeignKey] => 
                                    [_e:CComponent:private] => 
                                    [_m:CComponent:private] => 
                                )

                            [create_time] => CMysqlColumnSchema Object
                                (
                                    [name] => create_time
                                    [rawName] => `create_time`
                                    [allowNull] => 1
                                    [dbType] => datetime
                                    [type] => string
                                    [defaultValue] => 
                                    [size] => 
                                    [precision] => 
                                    [scale] => 
                                    [isPrimaryKey] => 
                                    [isForeignKey] => 
                                    [_e:CComponent:private] => 
                                    [_m:CComponent:private] => 
                                )

                            [create_user_id] => CMysqlColumnSchema Object
                                (
                                    [name] => create_user_id
                                    [rawName] => `create_user_id`
                                    [allowNull] => 1
                                    [dbType] => int(11)
                                    [type] => integer
                                    [defaultValue] => 
                                    [size] => 11
                                    [precision] => 11
                                    [scale] => 
                                    [isPrimaryKey] => 
                                    [isForeignKey] => 
                                    [_e:CComponent:private] => 
                                    [_m:CComponent:private] => 
                                )

                            [update_time] => CMysqlColumnSchema Object
                                (
                                    [name] => update_time
                                    [rawName] => `update_time`
                                    [allowNull] => 1
                                    [dbType] => datetime
                                    [type] => string
                                    [defaultValue] => 
                                    [size] => 
                                    [precision] => 
                                    [scale] => 
                                    [isPrimaryKey] => 
                                    [isForeignKey] => 
                                    [_e:CComponent:private] => 
                                    [_m:CComponent:private] => 
                                )

                            [update_user_id] => CMysqlColumnSchema Object
                                (
                                    [name] => update_user_id
                                    [rawName] => `update_user_id`
                                    [allowNull] => 1
                                    [dbType] => int(11)
                                    [type] => integer
                                    [defaultValue] => 
                                    [size] => 11
                                    [precision] => 11
                                    [scale] => 
                                    [isPrimaryKey] => 
                                    [isForeignKey] => 
                                    [_e:CComponent:private] => 
                                    [_m:CComponent:private] => 
                                )

                        )

                    [_e:CComponent:private] => 
                    [_m:CComponent:private] => 
                )

            [columns] => Array
                (
                    [id] => CMysqlColumnSchema Object
                        (
                            [name] => id
                            [rawName] => `id`
                            [allowNull] => 
                            [dbType] => int(11)
                            [type] => integer
                            [defaultValue] => 
                            [size] => 11
                            [precision] => 11
                            [scale] => 
                            [isPrimaryKey] => 1
                            [isForeignKey] => 
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                    [name] => CMysqlColumnSchema Object
                        (
                            [name] => name
                            [rawName] => `name`
                            [allowNull] => 1
                            [dbType] => varchar(128)
                            [type] => string
                            [defaultValue] => 
                            [size] => 128
                            [precision] => 128
                            [scale] => 
                            [isPrimaryKey] => 
                            [isForeignKey] => 
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                    [description] => CMysqlColumnSchema Object
                        (
                            [name] => description
                            [rawName] => `description`
                            [allowNull] => 1
                            [dbType] => text
                            [type] => string
                            [defaultValue] => 
                            [size] => 
                            [precision] => 
                            [scale] => 
                            [isPrimaryKey] => 
                            [isForeignKey] => 
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                    [create_time] => CMysqlColumnSchema Object
                        (
                            [name] => create_time
                            [rawName] => `create_time`
                            [allowNull] => 1
                            [dbType] => datetime
                            [type] => string
                            [defaultValue] => 
                            [size] => 
                            [precision] => 
                            [scale] => 
                            [isPrimaryKey] => 
                            [isForeignKey] => 
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                    [create_user_id] => CMysqlColumnSchema Object
                        (
                            [name] => create_user_id
                            [rawName] => `create_user_id`
                            [allowNull] => 1
                            [dbType] => int(11)
                            [type] => integer
                            [defaultValue] => 
                            [size] => 11
                            [precision] => 11
                            [scale] => 
                            [isPrimaryKey] => 
                            [isForeignKey] => 
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                    [update_time] => CMysqlColumnSchema Object
                        (
                            [name] => update_time
                            [rawName] => `update_time`
                            [allowNull] => 1
                            [dbType] => datetime
                            [type] => string
                            [defaultValue] => 
                            [size] => 
                            [precision] => 
                            [scale] => 
                            [isPrimaryKey] => 
                            [isForeignKey] => 
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                    [update_user_id] => CMysqlColumnSchema Object
                        (
                            [name] => update_user_id
                            [rawName] => `update_user_id`
                            [allowNull] => 1
                            [dbType] => int(11)
                            [type] => integer
                            [defaultValue] => 
                            [size] => 11
                            [precision] => 11
                            [scale] => 
                            [isPrimaryKey] => 
                            [isForeignKey] => 
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                )

            [relations] => Array
                (
                    [issues] => CHasManyRelation Object
                        (
                            [limit] => -1
                            [offset] => -1
                            [together] => 
                            [index] => 
                            [joinType] => LEFT OUTER JOIN
                            [on] => 
                            [alias] => 
                            [with] => Array
                                (
                                )

                            [name] => issues
                            [className] => Issue
                            [foreignKey] => project_id
                            [select] => *
                            [condition] => 
                            [params] => Array
                                (
                                )

                            [group] => 
                            [join] => 
                            [having] => 
                            [order] => 
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                    [users] => CManyManyRelation Object
                        (
                            [limit] => -1
                            [offset] => -1
                            [together] => 
                            [index] => 
                            [joinType] => LEFT OUTER JOIN
                            [on] => 
                            [alias] => 
                            [with] => Array
                                (
                                )

                            [name] => users
                            [className] => User
                            [foreignKey] => tbl_project_user_assignment(project_id, user_id)
                            [select] => *
                            [condition] => 
                            [params] => Array
                                (
                                )

                            [group] => 
                            [join] => 
                            [having] => 
                            [order] => 
                            [_e:CComponent:private] => 
                            [_m:CComponent:private] => 
                        )

                )

            [attributeDefaults] => Array
                (
                )

            [_model:CActiveRecordMetaData:private] => Project Object
                (
                    [_md:CActiveRecord:private] => CActiveRecordMetaData Object
 *RECURSION*
                    [_new:CActiveRecord:private] => 
                    [_attributes:CActiveRecord:private] => Array
                        (
                        )

                    [_related:CActiveRecord:private] => Array
                        (
                        )

                    [_c:CActiveRecord:private] => 
                    [_pk:CActiveRecord:private] => 
                    [_alias:CActiveRecord:private] => t
                    [_errors:CModel:private] => Array
                        (
                        )

                    [_validators:CModel:private] => 
                    [_scenario:CModel:private] => 
                    [_e:CComponent:private] => 
                    [_m:CComponent:private] => 
                )

        )

    [_new:CActiveRecord:private] => 
    [_attributes:CActiveRecord:private] => Array
        (
            [id] => 2
            [name] => Test Project 2
            [description] => Description of Project 2
            [create_time] => 0000-00-00 00:00:00
            [create_user_id] => 
            [update_time] => 0000-00-00 00:00:00
            [update_user_id] => 
        )

    [_related:CActiveRecord:private] => Array
        (
        )

    [_c:CActiveRecord:private] => 
    [_pk:CActiveRecord:private] => 2
    [_alias:CActiveRecord:private] => t
    [_errors:CModel:private] => Array
        (
        )

    [_validators:CModel:private] => 
    [_scenario:CModel:private] => update
    [_e:CComponent:private] => 
    [_m:CComponent:private] => 
)
 matches expected <null>.


My testDelete function
public function testDelete()
{
	$project = $this->projects('project2');
	$savedProjectId = $project->id;
	$this->assertTrue(Project::model()->delete());
	
	$deletedProject = Project::model()->findByPk($savedProjectId);
	$this->assertEquals(NULL, $deletedProject);
} // testDelete


and finally my fixture I created:
<?php
	return array 
	(
		'project1'=>array
		(
			'name'=>'Test Project 1',
			'description'=>'Description of Project 1',
			'create_time'=>'',
			'create_user_id'=>'',
			'update_time'=>'',
			'update_user_id'=>'',
		), // array
		
		'project2'=>array
		(
			'name'=>'Test Project 2',
			'description'=>'Description of Project 2',
			'create_time'=>'',
			'create_user_id'=>'',
			'update_time'=>'',
			'update_user_id'=>'',
		), // array
		
		'project3'=>array
		(
			'name'=>'Test Project 3',
			'description'=>'Description of Project 3',
			'create_time'=>'',
			'create_user_id'=>'',
			'update_time'=>'',
			'update_user_id'=>'',
		), // array
	); // array
	
?>


any help would be appreciated.

thanks in advance,

andre
0

#2 User is offline   jefftulsa 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 168
  • Joined: 06-October 08
  • Location:Austin, TX

Posted 29 October 2010 - 03:09 PM

it looks like in your test method, you need to be deleting the actual project.

You have:
$this->assertTrue(Project::model()->delete());


But what you NEED is:

$this->assertTrue($project->delete()); 

1

#3 User is offline   xdolving 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 01-October 10

Posted 01 November 2010 - 12:09 PM

View Postjefftulsa, on 29 October 2010 - 03:09 PM, said:

it looks like in your test method, you need to be deleting the actual project.

You have:
$this->assertTrue(Project::model()->delete());


But what you NEED is:

$this->assertTrue($project->delete()); 




Thank you, jefftulsa.

That solved my issue :)

Greetings,

andre.
0

#4 User is offline   Samuel K. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 28-November 10

Posted 16 November 2012 - 02:02 AM

My fixture test update is not saving to the test database but delete is working . What could be wrong with my code?

Here is my fixture:
<?php
...
    'member2' => array(
        'member_no' => '002',
        'surname' => 'Surname2',
        'othernames' => 'Othernames2',
        'gender' => 'F',
...


    public function testUpdate() {
        // UPDATE a member details
        $member = $this->members('member2');
        $updatedSurname = 'Updated Member Surname';
        $member->surname = $updatedSurname;
        $this->assertTrue($member->save(false));
        // read back the record again to ensure the update worked
        $updatedMember = Member::model()->findByPk($member->id);
        $this->assertTrue($updatedMember instanceof Member);
        $this->assertEquals($updatedSurname, $updatedMember->surname);
    }


I would appreciate your help.
...
I changed a moment ago
0

#5 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 511
  • Joined: 08-August 09

Posted 16 November 2012 - 11:19 PM

Hey Samuel

I'd first check your updated model passes validation. When you make save(false) - false means not to validate the model.
So you may do

$member = $this->members('member2');
$updatedSurname = 'Updated Member Surname';
$member->surname = $updatedSurname;
var_dump($member->validate());

validate() docs

P.S. Please use code formatting button next time ("Insert code snippet" one)
0

#6 User is offline   Samuel K. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 28-November 10

Posted 28 November 2012 - 09:10 AM

View Postyugene, on 16 November 2012 - 11:19 PM, said:

Hey Samuel

I'd first check your updated model passes validation. When you make save(false) - false means not to validate the model.
So you may do

$member = $this->members('member2');
$updatedSurname = 'Updated Member Surname';
$member->surname = $updatedSurname;
var_dump($member->validate());

validate() docs

P.S. Please use code formatting button next time ("Insert code snippet" one)


Thanx yugene for the advice.

I don't understand. The test results
var_dump($member->validate()); 

returns a boolean(true).
...
I changed a moment ago
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