Skip to content

Commit 15734a7

Browse files
committed
Logout function clears session
1 parent 4a328bb commit 15734a7

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Authenticator.php

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Authenticator {
99
private string $clientKey;
1010
private string $clientSecret;
1111
private string $redirectPath;
12+
private SessionContainer $session;
1213
private SessionData $sessionData;
1314

1415
public function __construct(
@@ -28,6 +29,7 @@ public function __construct(
2829
$this->clientKey = $clientKey;
2930
$this->clientSecret = $clientSecret;
3031
$this->redirectPath = $redirectPath;
32+
$this->session = $session;
3133
$this->sessionData = $session->get(self::SESSION_KEY);
3234

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

53+
public function logout():void {
54+
$this->session->remove(self::SESSION_KEY);
55+
}
56+
5157
private function authInProgress():bool {
5258
return false;
5359
}

test/phpunit/AuthenticatorTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,19 @@ public function testIsLoggedInTrueWhenSessionDataSet() {
5959
);
6060
self::assertTrue($sut->isLoggedIn());
6161
}
62+
63+
public function testLogoutClearsSession() {
64+
$sessionData = self::createMock(SessionData::class);
65+
$_SESSION = [
66+
Authenticator::SESSION_KEY => $sessionData
67+
];
68+
69+
$sut = new Authenticator(
70+
"test-key",
71+
"test-secret",
72+
"/"
73+
);
74+
$sut->logout();
75+
self::assertEmpty($_SESSION);
76+
}
6277
}

0 commit comments

Comments
 (0)