Skip to content

Commit f0f0730

Browse files
author
Greg Bowler
committed
Implement getting email from Authenticator instance
1 parent 57abac9 commit f0f0730

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/Authenticator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public function getUuid():string {
8383
return $userData->getUuid();
8484
}
8585

86+
public function getEmail():string {
87+
$userData = $this->sessionData->getUserData();
88+
return $userData->getEmail();
89+
}
90+
8691
private function authInProgress():bool {
8792
return false;
8893
}

src/UserData.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
class UserData {
55
private string $uuid;
6+
private string $email;
67

78
public function getUuid():string {
89
return $this->uuid;
910
}
11+
12+
public function getEmail():string {
13+
return $this->email;
14+
}
1015
}

test/phpunit/AuthenticatorTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,36 @@ public function testGetUuid() {
201201
);
202202
self::assertEquals($expectedUuid, $sut->getUuid());
203203
}
204+
205+
public function testGetEmailThrowsExceptionWhenNotLoggedIn() {
206+
$_SESSION = [];
207+
$sut = new Authenticator(
208+
"test-key",
209+
"test-secret",
210+
"/"
211+
);
212+
self::expectException(NotLoggedInException::class);
213+
$sut->getEmail();
214+
}
215+
216+
public function testGetEmail() {
217+
$expectedEmail = "example@example.com";
218+
219+
$userData = self::createMock(UserData::class);
220+
$userData->method("getEmail")
221+
->willReturn($expectedEmail);
222+
$sessionData = self::createMock(SessionData::class);
223+
$sessionData->method("getUserData")
224+
->willReturn($userData);
225+
226+
$_SESSION = [
227+
Authenticator::SESSION_KEY => $sessionData,
228+
];
229+
$sut = new Authenticator(
230+
"test-key",
231+
"test-secret",
232+
"/"
233+
);
234+
self::assertEquals($expectedEmail, $sut->getEmail());
235+
}
204236
}

0 commit comments

Comments
 (0)