2121 */
2222final class SessionHandlerTest extends TestCase
2323{
24- private $ session ;
25-
2624 /**
2725 * Destroy the session at the end of each test
2826 */
@@ -38,7 +36,7 @@ protected function tearDown()
3836 */
3937 public function testConstructorNoParameters ()
4038 {
41- $ this -> session = new \Likel \Session \Handler ();
39+ $ session = new \Likel \Session \Handler ();
4240 $ this ->assertEquals (session_status (), PHP_SESSION_ACTIVE );
4341 }
4442
@@ -47,7 +45,7 @@ public function testConstructorNoParameters()
4745 */
4846 public function testConstructorNonArray ()
4947 {
50- $ this -> session = new \Likel \Session \Handler ("a " );
48+ $ session = new \Likel \Session \Handler ("a " );
5149 $ this ->assertEquals (session_status (), PHP_SESSION_ACTIVE );
5250 }
5351
@@ -56,7 +54,7 @@ public function testConstructorNonArray()
5654 */
5755 public function testConstructorSessionNameSet ()
5856 {
59- $ this -> session = new \Likel \Session \Handler (array (
57+ $ session = new \Likel \Session \Handler (array (
6058 'session_name ' => "test_session "
6159 ));
6260 $ this ->assertEquals (session_status (), PHP_SESSION_ACTIVE );
@@ -68,7 +66,7 @@ public function testConstructorSessionNameSet()
6866 */
6967 public function testConstructorSecureSet ()
7068 {
71- $ this -> session = new \Likel \Session \Handler (array (
69+ $ session = new \Likel \Session \Handler (array (
7270 'secure ' => "true "
7371 ));
7472 $ this ->assertEquals (session_status (), PHP_SESSION_ACTIVE );
@@ -79,7 +77,7 @@ public function testConstructorSecureSet()
7977 */
8078 public function testConstructorCredentialsLocationSet ()
8179 {
82- $ this -> session = new \Likel \Session \Handler (array (
80+ $ session = new \Likel \Session \Handler (array (
8381 'credentials_location ' => __DIR__ . '/../src/ini/credentials.ini '
8482 ));
8583 $ this ->assertEquals (session_status (), PHP_SESSION_ACTIVE );
@@ -90,7 +88,7 @@ public function testConstructorCredentialsLocationSet()
9088 */
9189 public function testConstructorNonExistantParameter ()
9290 {
93- $ this -> session = new \Likel \Session \Handler (array (
91+ $ session = new \Likel \Session \Handler (array (
9492 'foo ' => 'bar '
9593 ));
9694 $ this ->assertEquals (session_status (), PHP_SESSION_ACTIVE );
@@ -101,7 +99,7 @@ public function testConstructorNonExistantParameter()
10199 */
102100 public function testConstructorIncorrectSecureType ()
103101 {
104- $ this -> session = new \Likel \Session \Handler (array (
102+ $ session = new \Likel \Session \Handler (array (
105103 'secure ' => "false "
106104 ));
107105 $ this ->assertEquals (session_status (), PHP_SESSION_ACTIVE );
@@ -113,9 +111,53 @@ public function testConstructorIncorrectSecureType()
113111 public function testConstructorIncorrectCredentialsLocation ()
114112 {
115113 $ this ->expectOutputString ('The credential file could not be located. ' );
116- $ this -> session = new \Likel \Session \Handler (array (
114+ $ session = new \Likel \Session \Handler (array (
117115 'credentials_location ' => "path "
118116 ));
119117 $ this ->assertEquals (session_status (), PHP_SESSION_NONE );
120118 }
119+
120+ /**
121+ * Check session is in the database
122+ */
123+ public function testSessionInDatabase ()
124+ {
125+ $ session = new \Likel \Session \Handler ();
126+ $ db = new \Likel \DB (__DIR__ . '/../src/ini/credentials.ini ' );
127+ $ db ->query ("
128+ SELECT * FROM {$ db ->getTableName ("sessions " )}
129+ WHERE id = :id
130+ " );
131+ $ db ->bind (":id " , session_id ());
132+ $ this ->assertNotNull ($ db ->result ());
133+ }
134+
135+ /**
136+ * Test ArrayAccess implementation
137+ */
138+ public function testArrayAccessImplementation ()
139+ {
140+ $ session = new \Likel \Session \Handler ();
141+
142+ // offsetSet test
143+ $ session ["set " ] = "foo " ;
144+ $ this ->assertEquals ($ session ["set " ], "foo " );
145+
146+ // offsetGet tests
147+ $ bar = $ session ["set " ];
148+ $ this ->assertEquals ($ session ["set " ], $ bar );
149+ $ this ->assertNull ($ session ["not_set " ]);
150+
151+ // offsetExists tests
152+ $ this ->assertTrue (isset ($ session ["set " ]));
153+ $ this ->assertFalse (isset ($ session ["not_set " ]));
154+
155+ // offsetUnset test
156+ unset($ session ["set " ]);
157+ $ this ->assertNull ($ session ["set " ]);
158+
159+ // __debugInfo test
160+ $ session ["set " ] = "foo " ;
161+ $ this ->assertEquals ('Likel\Session\HandlerObject([set]=>foo) ' , preg_replace ('/\s+/ ' , '' , print_r ($ session , true )));
162+ }
121163}
0 commit comments