@@ -85,13 +85,15 @@ public function testRegisterBagException()
85
85
public function testGetId ()
86
86
{
87
87
$ storage = $ this ->getStorage ();
88
- $ this ->assertEquals ('' , $ storage ->getId ());
88
+ $ this ->assertSame ('' , $ storage ->getId (), ' Empty ID before starting session ' );
89
89
90
90
$ storage ->start ();
91
- $ this ->assertNotEquals ('' , $ storage ->getId ());
91
+ $ id = $ storage ->getId ();
92
+ $ this ->assertInternalType ('string ' , $ id );
93
+ $ this ->assertNotSame ('' , $ id );
92
94
93
95
$ storage ->save ();
94
- $ this ->assertNotEquals ( '' , $ storage ->getId ());
96
+ $ this ->assertSame ( $ id , $ storage ->getId (), ' ID stays after saving session ' );
95
97
}
96
98
97
99
public function testRegenerate ()
@@ -209,18 +211,20 @@ public function testSetSaveHandler54()
209
211
/**
210
212
* @expectedException \RuntimeException
211
213
*/
212
- public function testStartedOutside53 ()
214
+ public function testStartedOutside ()
213
215
{
214
- if (PHP_VERSION_ID >= 50400 ) {
215
- $ this ->markTestSkipped ('Test skipped, for PHP 5.3 only. ' );
216
- }
217
-
218
216
$ storage = $ this ->getStorage ();
219
217
220
218
$ this ->assertFalse (isset ($ _SESSION ));
219
+ $ this ->assertFalse ($ storage ->getSaveHandler ()->isActive ());
220
+ $ this ->assertFalse ($ storage ->isStarted ());
221
221
222
222
session_start ();
223
223
$ this ->assertTrue (isset ($ _SESSION ));
224
+ if (PHP_VERSION_ID >= 50400 ) {
225
+ // this only works in PHP >= 5.4 where session_status is available
226
+ $ this ->assertTrue ($ storage ->getSaveHandler ()->isActive ());
227
+ }
224
228
// PHP session might have started, but the storage driver has not, so false is correct here
225
229
$ this ->assertFalse ($ storage ->isStarted ());
226
230
@@ -229,29 +233,15 @@ public function testStartedOutside53()
229
233
$ storage ->start ();
230
234
}
231
235
232
- /**
233
- * @expectedException \RuntimeException
234
- */
235
- public function testCanStartOutside54 ()
236
+ public function testRestart ()
236
237
{
237
- if (PHP_VERSION_ID < 50400 ) {
238
- $ this ->markTestSkipped ('Test skipped, for PHP 5.4 only. ' );
239
- }
240
-
241
238
$ storage = $ this ->getStorage ();
242
-
243
- $ this ->assertFalse (isset ($ _SESSION ));
244
- $ this ->assertFalse ($ storage ->getSaveHandler ()->isActive ());
245
- $ this ->assertFalse ($ storage ->isStarted ());
246
-
247
- session_start ();
248
- $ this ->assertTrue (isset ($ _SESSION ));
249
- $ this ->assertTrue ($ storage ->getSaveHandler ()->isActive ());
250
- // PHP session might have started, but the storage driver has not, so false is correct here
251
- $ this ->assertFalse ($ storage ->isStarted ());
252
-
253
- $ key = $ storage ->getMetadataBag ()->getStorageKey ();
254
- $ this ->assertFalse (isset ($ _SESSION [$ key ]));
255
239
$ storage ->start ();
240
+ $ id = $ storage ->getId ();
241
+ $ storage ->getBag ('attributes ' )->set ('lucky ' , 7 );
242
+ $ storage ->save ();
243
+ $ storage ->start ();
244
+ $ this ->assertSame ($ id , $ storage ->getId (), 'Same session ID after restarting ' );
245
+ $ this ->assertSame (7 , $ storage ->getBag ('attributes ' )->get ('lucky ' ), 'Data still available ' );
256
246
}
257
247
}
0 commit comments