@@ -202,6 +202,40 @@ public function testSessionCookieNotWrittenCookieGiven()
202
202
$ this ->assertCount (0 , $ cookies );
203
203
}
204
204
205
+ /**
206
+ * @runInSeparateProcess
207
+ */
208
+ public function testNewSessionIdIsNotOverwritten ()
209
+ {
210
+ $ newSessionId = $ this ->createValidSessionId ();
211
+
212
+ $ this ->assertNotEmpty ($ newSessionId );
213
+
214
+ $ request = new Request ();
215
+ $ request ->cookies ->set ('PHPSESSID ' , 'OLD-SESSION-ID ' );
216
+
217
+ $ listener = $ this ->createListener ($ request , new NativeSessionStorageFactory ());
218
+
219
+ $ kernel = $ this ->createMock (HttpKernelInterface::class);
220
+ $ listener ->onKernelRequest (new RequestEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST ));
221
+
222
+ $ session = $ request ->getSession ();
223
+ $ this ->assertSame ($ newSessionId , $ session ->getId ());
224
+ $ session ->set ('hello ' , 'world ' );
225
+
226
+ $ response = new Response ();
227
+ $ listener ->onKernelResponse (new ResponseEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST , $ response ));
228
+ $ this ->assertSame ($ newSessionId , $ session ->getId ());
229
+
230
+ $ cookies = $ response ->headers ->getCookies ();
231
+
232
+ $ this ->assertCount (1 , $ cookies );
233
+ $ sessionCookie = $ cookies [0 ];
234
+
235
+ $ this ->assertSame ('PHPSESSID ' , $ sessionCookie ->getName ());
236
+ $ this ->assertSame ($ newSessionId , $ sessionCookie ->getValue ());
237
+ }
238
+
205
239
/**
206
240
* @runInSeparateProcess
207
241
*/
@@ -488,7 +522,7 @@ public function testUninitializedSessionWithoutInitializedSession()
488
522
public function testSurrogateMainRequestIsPublic ()
489
523
{
490
524
$ session = $ this ->createMock (Session::class);
491
- $ session ->expects ($ this ->exactly (2 ))->method ('getName ' )->willReturn ('PHPSESSID ' );
525
+ $ session ->expects ($ this ->exactly (1 ))->method ('getName ' )->willReturn ('PHPSESSID ' );
492
526
$ session ->expects ($ this ->exactly (4 ))->method ('getUsageIndex ' )->will ($ this ->onConsecutiveCalls (0 , 1 , 1 , 1 ));
493
527
494
528
$ container = new Container ();
@@ -528,7 +562,7 @@ public function testSurrogateMainRequestIsPublic()
528
562
public function testGetSessionIsCalledOnce ()
529
563
{
530
564
$ session = $ this ->createMock (Session::class);
531
- $ session ->expects ($ this ->exactly (2 ))->method ('getName ' )->willReturn ('PHPSESSID ' );
565
+ $ session ->expects ($ this ->exactly (1 ))->method ('getName ' )->willReturn ('PHPSESSID ' );
532
566
$ sessionStorage = $ this ->createMock (NativeSessionStorage::class);
533
567
$ kernel = $ this ->createMock (KernelInterface::class);
534
568
0 commit comments