public static function getUser($id = null)
{
$instance = self::getSession()->get('user');
if (is_null($id))
{
if (!($instance instanceof JUser))
{
$instance = JUser::getInstance();
}
}
elseif ($instance->id != $id)
{
$instance = JUser::getInstance($id);
}
return $instance;
}
When I write a unit test case for a function, which has the code JFactory::getUser(); inside, then I need to set user in session. Otherwise session does not contain anything, and return NULL on first line of function. If $instance is null then it gets an error for "Accessing undefined property on on non-object" ($instance->id ).
Should there be the check before using "elseif ($instance->id != $id)"
Or
raise exception if $instnace is null,
Or
elseif (isset($instance) $instance->id != $id || $id)
{
$instance = JUser::getInstance($id);
}
This code should be added.
Status | New | ⇒ | Pending |
Category | ⇒ | Unit Tests |
Closing this issue as we have a PR.
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-10-15 06:15:45 |
Hi Gaurav,
Thanks!
Can you submit a pull request (PR) for it? Here's how:
http://docs.joomla.org/Git_for_Coders