@@ -128,4 +128,48 @@ public function testGC(): void
128128 $ handler = $ this ->getInstance ();
129129 $ this ->assertSame (1 , $ handler ->gc (3600 ));
130130 }
131+
132+ public function testReopenAndReadWithSameHandlerInstance (): void
133+ {
134+ $ handler = $ this ->getInstance ();
135+ $ handler ->open ($ this ->sessionSavePath , $ this ->sessionName );
136+
137+ $ sessionId = '666666b43phsnnf8if6bo33b635e4448 ' ;
138+
139+ $ this ->assertSame ('' , $ handler ->read ($ sessionId ));
140+
141+ $ data = '__ci_last_regenerate|i:1664607454;key|s:5:"value"; ' ;
142+ $ this ->assertTrue ($ handler ->write ($ sessionId , $ data ));
143+ $ this ->assertTrue ($ handler ->close ());
144+
145+ // Reopen with the same handler instance (e.g. session_write_close() + session_start())
146+ $ this ->assertTrue ($ handler ->open ($ this ->sessionSavePath , $ this ->sessionName ));
147+ $ this ->assertSame ($ data , $ handler ->read ($ sessionId ));
148+ $ this ->assertTrue ($ handler ->close ());
149+ }
150+
151+ public function testRegenerateSessionIdWithSameHandlerInstance (): void
152+ {
153+ $ handler = $ this ->getInstance ();
154+ $ handler ->open ($ this ->sessionSavePath , $ this ->sessionName );
155+
156+ $ oldSessionId = '777777b43phsnnf8if6bo33b635e4449 ' ;
157+ $ newSessionId = '888888b43phsnnf8if6bo33b635e4450 ' ;
158+
159+ $ this ->assertSame ('' , $ handler ->read ($ oldSessionId ));
160+
161+ $ data = '__ci_last_regenerate|i:1664607454;role|s:5:"admin"; ' ;
162+ $ this ->assertTrue ($ handler ->write ($ oldSessionId , $ data ));
163+ $ this ->assertTrue ($ handler ->close ());
164+
165+ // PHP reuses the same SessionHandler object on regeneration
166+ $ this ->assertTrue ($ handler ->open ($ this ->sessionSavePath , $ this ->sessionName ));
167+ $ this ->assertSame ('' , $ handler ->read ($ newSessionId ));
168+ $ this ->assertTrue ($ handler ->write ($ newSessionId , $ data ));
169+ $ this ->assertTrue ($ handler ->close ());
170+
171+ $ this ->assertTrue ($ handler ->open ($ this ->sessionSavePath , $ this ->sessionName ));
172+ $ this ->assertSame ($ data , $ handler ->read ($ newSessionId ));
173+ $ this ->assertTrue ($ handler ->close ());
174+ }
131175}
0 commit comments