I need to quickly mock an object, so that when in template appears:
$that->user->isAdmin()
it will return true.
I tried to cast an array with anonymous function into object:
$that = (object) ( (array(
'user' =>
(object) (array(
'isAdmin' => function() {
return true;
}
(...)
but var_dump($that->user) returns an empty(?) Closure:
object(stdClass)#3 (1) {
["isAdmin"]=>
object(Closure)#2 (1) {
["this"]=>
object(View)#1 (0) {
}
}
}
and calling it directly by $that->user->isAdmin() returns Call to undefined method stdClass::isAdmin().
How can I rewrite $that in order to be able to call $that->user->isAdmin()?
Can be done in a dirty/hacky way, since it's only for a mocking purpose.