File tree Expand file tree Collapse file tree 4 files changed +32
-16
lines changed Expand file tree Collapse file tree 4 files changed +32
-16
lines changed Original file line number Diff line number Diff line change @@ -16,5 +16,12 @@ public function __construct(
1616 if (is_null ($ session )) {
1717 $ session = new GlobalSessionContainer ();
1818 }
19+
20+ if (!$ session ->contains (GlobalSessionContainer::SESSION_KEY )) {
21+ $ session ->set (
22+ GlobalSessionContainer::SESSION_KEY ,
23+ new SessionData ()
24+ );
25+ }
1926 }
2027}
Original file line number Diff line number Diff line change 44use Gt \Session \SessionArrayWrapper ;
55
66class GlobalSessionContainer extends SessionArrayWrapper {
7- const DEFAULT_SESSION_KEY = "AUTHWAVE_SESSION " ;
7+ const SESSION_KEY = "AUTHWAVE_SESSION_DATA " ;
88
9- public function __construct (
10- string $ baseSessionKey = self ::DEFAULT_SESSION_KEY
11- ) {
12- if (session_status () !== PHP_SESSION_ACTIVE ) {
13- session_start ();
9+ public function __construct () {
10+ if (!isset ($ _SESSION )) {
11+ throw new SessionNotStartedException ();
1412 }
15-
16- if (!isset ($ _SESSION [$ baseSessionKey ])) {
17- $ _SESSION [$ baseSessionKey ] = new SessionData ();
18- }
19-
20- // TODO: Should this implement SessionContainer interface and define
21- // the getters and setters to $_SESSION itself, rather than being an
22- // instance of SessionArrayWrapper?
23-
24- parent ::__construct ($ _SESSION [$ baseSessionKey ]);
13+ parent ::__construct ($ _SESSION );
2514 }
2615}
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Authwave ;
3+
4+ class SessionNotStartedException extends AuthwaveException {}
Original file line number Diff line number Diff line change 22namespace Authwave \Test ;
33
44use Authwave \Authenticator ;
5+ use Authwave \GlobalSessionContainer ;
6+ use Authwave \SessionNotStartedException ;
57use PHPUnit \Framework \TestCase ;
68
79class AuthenticatorTest extends TestCase {
10+ public function testConstructWithDefaultSessionNotStarted () {
11+ self ::expectException (SessionNotStartedException::class);
12+ new Authenticator (
13+ "test-key " ,
14+ "test-secret " ,
15+ "/ "
16+ );
17+ }
18+
819 public function testConstructWithDefaultSession () {
20+ $ _SESSION = [];
921 $ sut = new Authenticator (
1022 "test-key " ,
1123 "test-secret " ,
1224 "/ "
1325 );
26+ self ::assertArrayHasKey (
27+ GlobalSessionContainer::SESSION_KEY ,
28+ $ _SESSION
29+ );
1430 }
1531}
You can’t perform that action at this time.
0 commit comments