?
avatar gauravjain028
gauravjain028
14 Feb 2014

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.

avatar rbsl-gaurav rbsl-gaurav - open - 14 Feb 2014
avatar brianteeman brianteeman - change - 28 Jul 2014
Status New Pending
avatar brianteeman brianteeman - change - 2 Sep 2014
Category Unit Tests
avatar nicksavov
nicksavov - comment - 14 Oct 2014

Hi Gaurav,

Thanks!

Can you submit a pull request (PR) for it? Here's how:
http://docs.joomla.org/Git_for_Coders

avatar rbsl-gaurav
rbsl-gaurav - comment - 15 Oct 2014

Thanks Nick.

Just create a PR #4675

avatar Bakual
Bakual - comment - 15 Oct 2014

Closing this issue as we have a PR.

avatar Bakual Bakual - close - 15 Oct 2014
avatar Bakual Bakual - change - 15 Oct 2014
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2014-10-15 06:15:45

Add a Comment

Login with GitHub to post a comment