@@ -211,6 +211,40 @@ public function testSessionCookieNotWrittenCookieGiven()
211
211
$ this ->assertCount (0 , $ cookies );
212
212
}
213
213
214
+ /**
215
+ * @runInSeparateProcess
216
+ */
217
+ public function testNewSessionIdIsNotOverwritten ()
218
+ {
219
+ $ newSessionId = $ this ->createValidSessionId ();
220
+
221
+ $ this ->assertNotEmpty ($ newSessionId );
222
+
223
+ $ request = new Request ();
224
+ $ request ->cookies ->set ('PHPSESSID ' , 'OLD-SESSION-ID ' );
225
+
226
+ $ listener = $ this ->createListener ($ request , new NativeSessionStorageFactory ());
227
+
228
+ $ kernel = $ this ->createMock (HttpKernelInterface::class);
229
+ $ listener ->onKernelRequest (new RequestEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST ));
230
+
231
+ $ session = $ request ->getSession ();
232
+ $ this ->assertSame ($ newSessionId , $ session ->getId ());
233
+ $ session ->set ('hello ' , 'world ' );
234
+
235
+ $ response = new Response ();
236
+ $ listener ->onKernelResponse (new ResponseEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST , $ response ));
237
+ $ this ->assertSame ($ newSessionId , $ session ->getId ());
238
+
239
+ $ cookies = $ response ->headers ->getCookies ();
240
+
241
+ $ this ->assertCount (1 , $ cookies );
242
+ $ sessionCookie = $ cookies [0 ];
243
+
244
+ $ this ->assertSame ('PHPSESSID ' , $ sessionCookie ->getName ());
245
+ $ this ->assertSame ($ newSessionId , $ sessionCookie ->getValue ());
246
+ }
247
+
214
248
/**
215
249
* @runInSeparateProcess
216
250
*/
@@ -523,7 +557,7 @@ public function testUninitializedSessionWithoutInitializedSession()
523
557
public function testSurrogateMainRequestIsPublic ()
524
558
{
525
559
$ session = $ this ->createMock (Session::class);
526
- $ session ->expects ($ this ->exactly (2 ))->method ('getName ' )->willReturn ('PHPSESSID ' );
560
+ $ session ->expects ($ this ->exactly (1 ))->method ('getName ' )->willReturn ('PHPSESSID ' );
527
561
$ session ->expects ($ this ->exactly (2 ))->method ('getUsageIndex ' )->will ($ this ->onConsecutiveCalls (0 , 1 ));
528
562
$ sessionFactory = $ this ->createMock (SessionFactory::class);
529
563
$ sessionFactory ->expects ($ this ->once ())->method ('createSession ' )->willReturn ($ session );
@@ -563,7 +597,7 @@ public function testSurrogateMainRequestIsPublic()
563
597
public function testGetSessionIsCalledOnce ()
564
598
{
565
599
$ session = $ this ->createMock (Session::class);
566
- $ session ->expects ($ this ->exactly (2 ))->method ('getName ' )->willReturn ('PHPSESSID ' );
600
+ $ session ->expects ($ this ->exactly (1 ))->method ('getName ' )->willReturn ('PHPSESSID ' );
567
601
$ sessionFactory = $ this ->createMock (SessionFactory::class);
568
602
$ sessionFactory ->expects ($ this ->once ())->method ('createSession ' )->willReturn ($ session );
569
603
$ kernel = $ this ->createMock (KernelInterface::class);
0 commit comments