/**
  * Logs the user out and redirects to the login page
  *
  * @param Psr\Http\Message\ServerRequestInterface $request
  * @param Psr\Http\Message\ResponseInterface $response
  * @param array $args
  */
 public function destroy($request, $response, $args)
 {
     $this->authentication->logout();
     $this->resetContextValues();
     $this->context['user'] = null;
     // Redirect to the login page
     return $response->withStatus(301)->withHeader('Location', '/login');
 }
 /**
  * @test
  * @covers SlimApp\Authentication::logout
  * @uses SlimApp\Session::delete
  * @uses SlimApp\Session::set
  */
 public function logout_deletes_the_UserId_session_variable_if_it_was_set()
 {
     // Clean the session before the tests
     Session::delete('UserId');
     // Logout called by a guest user
     $authentication = new Authentication();
     $authentication->logout();
     $userIdAfterGuestLogout = Session::get('UserId');
     // Logged in user
     Session::set('UserId', 123);
     $authentication->logout();
     $userIdAfterLoggedInUserLogout = Session::get('UserId');
     $this->assertFalse($userIdAfterGuestLogout);
     $this->assertFalse($userIdAfterLoggedInUserLogout);
 }