public function testUpdateWhenSessionExistsInDatabase()
 {
     $user = new FakeUserSession();
     $this->fakeAuth->_Session = $user;
     $expectedSession = WebServiceUserSession::FromSession($user);
     $this->userSessionRepository->expects($this->once())->method('LoadByUserId')->with($this->equalTo($user->UserId))->will($this->returnValue(new WebServiceUserSession(123)));
     $this->userSessionRepository->expects($this->once())->method('Update')->with($this->equalTo($expectedSession));
     $actualSession = $this->webAuth->Login($this->username);
     $this->assertEquals($expectedSession, $actualSession);
 }
Exemplo n.º 2
0
 /**
  * @param string $username
  * @return WebServiceUserSession
  */
 public function Login($username)
 {
     Log::Debug('Web Service Login with username: %s', $username);
     $userSession = $this->authentication->Login($username, new WebServiceLoginContext());
     if ($userSession->IsLoggedIn()) {
         $webSession = WebServiceUserSession::FromSession($userSession);
         $existingSession = $this->userSessionRepository->LoadByUserId($userSession->UserId);
         if ($existingSession == null) {
             $this->userSessionRepository->Add($webSession);
         } else {
             $this->userSessionRepository->Update($webSession);
         }
         return $webSession;
     }
     return new NullUserSession();
 }