While testing a piece of code(written as per codeigniter mvc) with PHPUnit I got the error PHP Fatal error: Call to a member function getPermissionObject() on a non-object.
The code is as below and the part of it producing error is indented.
class Some_model extends Model
{
var $userid;
var $permisson_object;
var $username;
var $userType;
var $userFirstName;
function Some_model()
{
parent::Model();
$user_obj = @unserialize($this->db_session->userdata('user_object'));
//following line shows error
$this->permisson_object = $user_obj->getPermissionObject();
$this->userid = $user_obj->getUserid();
$this->username = $user_obj->getUsername();
$this->userType =$user_obj->getusertype();
$this->userFirstName = $user_obj->getFirstName()." ".$user_obj->getLastName();
}
}
The error came because while testing I am unable to generate $user_obj from my testclass (as it is generated from session data).
My requirement is to generate the same in the test Class so that I can use it.
Thanks
Thanks for your reply.
The object looks something like this:
User_library Object
(
[username:User_library:private] => [email protected]
[firstname:User_library:private] => some
[lastname:User_library:private] => Staff
[typename:User_library:private] =>
[userid:User_library:private] => 2
[userType:User_library:private] => 2
[permissionObject:User_library:private] => Permission_library Object
(
[create_custom_attr:Permission_library:private] => 1
[create_jobspecific_attr:Permission_library:private] => 0
[injob:Permission_library:private] => Array
(
[products] => 2
[services] => 2
[options] => 2
[tasks_assigned_to_me] => 2
[tasks_assigned_to_others] => 2
)
[outjob:Permission_library:private] => Array
(
[products] => 2
[services] => 2
[options] => 2
[tasks_assigned_to_others] => 2
)
[samedept:Permission_library:private] => Array
(
)
[alldepts:Permission_library:private] => Array
(
[add_and_assign_tasks] => 4
[add_and_assign_milestones] => 4
)
)
I can not find any option to mock this because this object also has other objects in it. Here User_library Object is the object of a class User_library. This also has Permission_library Object inside it. How can I mock the above by the following way:
$observer = $this->getMock('Some_model', array('Some_model'));
$observer->expects($this->any())
->method('Some_model')
->with($this->equalTo('something'));
Here my problem is what would be there in the something part in $this->equalTo('something')?