Summary




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 ).

There should be a check before using "elseif ($instance->id != $id)"

 

PR : https://github.com/joomla/joomla-cms/pull/4675

 



 
Opened On:
15 Oct 2014, 0:50 by Gaurav Jain
Closed On:
15 Oct 2014, 1:35
Status:
Closed

Filed Under

  • CMS Libraries
  • No Platform Implications

Responses

Posted on 15 Oct 2014, 1:35 by Thomas Hunziker

This Tracker is no longer used. A GitHub issue is all that is needed. Closing the issue.