Skip to content

Commit

Permalink
Logout function clears session
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Feb 28, 2020
1 parent 4a328bb commit 15734a7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Authenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Authenticator {
private string $clientKey;
private string $clientSecret;
private string $redirectPath;
private SessionContainer $session;
private SessionData $sessionData;

public function __construct(
Expand All @@ -28,6 +29,7 @@ public function __construct(
$this->clientKey = $clientKey;
$this->clientSecret = $clientSecret;
$this->redirectPath = $redirectPath;
$this->session = $session;
$this->sessionData = $session->get(self::SESSION_KEY);

if($this->authInProgress()) {
Expand All @@ -48,6 +50,10 @@ public function isLoggedIn():bool {
return isset($userData);
}

public function logout():void {
$this->session->remove(self::SESSION_KEY);
}

private function authInProgress():bool {
return false;
}
Expand Down
15 changes: 15 additions & 0 deletions test/phpunit/AuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,19 @@ public function testIsLoggedInTrueWhenSessionDataSet() {
);
self::assertTrue($sut->isLoggedIn());
}

public function testLogoutClearsSession() {
$sessionData = self::createMock(SessionData::class);
$_SESSION = [
Authenticator::SESSION_KEY => $sessionData
];

$sut = new Authenticator(
"test-key",
"test-secret",
"/"
);
$sut->logout();
self::assertEmpty($_SESSION);
}
}

0 comments on commit 15734a7

Please sign in to comment.