Unit testing with logged in user

Hi there!

Which is the best practice to unit test with a logged in user? I do it this way:




class TestUserIdentity extends CUserIdentity

  public function authenticate() {

    $this->_id=1;

    return $this->errorCode=self::ERROR_NONE;

  }

}






class TestUserIdentityTest extends CTestCase {

  function testLogin() {

    $identity = new TestUserIdentity('testuser','');

    $identity->authenticate();

    Yii::app()->user->login($identity);

    $this->assertEquals(1, Yii::app()->user->id);

  }

}



This way, if I need a logged in user, I can do a @depends testLogin on the unit test. But is this the best way?

I write this:


$_identity=new UserIdentity($login,$password);

$return = $_identity->authenticate();

$this->assertTrue($return);

$this->assertEquals(1, Yii::app()->user->id);