public function testLogsUserInIfValidCredentials()
 {
     $username = '******';
     $password = '******';
     $session = new UserSession(1);
     $request = new AuthenticationRequest($username, $password);
     $this->server->SetRequest($request);
     $this->authentication->expects($this->once())->method('Validate')->with($this->equalTo($username), $this->equalTo($password))->will($this->returnValue(true));
     $this->authentication->expects($this->once())->method('Login')->with($this->equalTo($username))->will($this->returnValue($session));
     $this->service->Authenticate($this->server);
     $expectedResponse = AuthenticationResponse::Success($this->server, $session);
     $this->assertEquals($expectedResponse, $this->server->_LastResponse);
 }
 /**
  * @name Authenticate
  * @description Authenticates an existing Booked Scheduler user
  * @request AuthenticationRequest
  * @response AuthenticationResponse
  * @return void
  */
 public function Authenticate()
 {
     /** @var $request AuthenticationRequest */
     $request = $this->server->GetRequest();
     $username = $request->username;
     $password = $request->password;
     Log::Debug('WebService Authenticate for user %s', $username);
     $isValid = $this->authentication->Validate($username, $password);
     if ($isValid) {
         Log::Debug('WebService Authenticate, user %s was authenticated', $username);
         $session = $this->authentication->Login($username);
         Log::Debug('SessionToken=%s', $session->SessionToken);
         $this->server->WriteResponse(AuthenticationResponse::Success($this->server, $session));
     } else {
         Log::Debug('WebService Authenticate, user %s was not authenticated', $username);
         $this->server->WriteResponse(AuthenticationResponse::Failed());
     }
 }