@@ -218,8 +218,6 @@ public function testSessionCookieNotWrittenCookieGiven()
218
218
public function testSessionCookieClearedWhenInvalidated ()
219
219
{
220
220
$ session = new Session ();
221
- $ session ->set ('hello ' , 'world ' );
222
- $ sessionId = $ session ->getId ();
223
221
224
222
$ container = new Container ();
225
223
$ container ->set ('initialized_session ' , $ session );
@@ -228,10 +226,14 @@ public function testSessionCookieClearedWhenInvalidated()
228
226
$ kernel = $ this ->createMock (HttpKernelInterface::class);
229
227
230
228
$ request = new Request ();
231
- $ request ->cookies ->set ('PHPSESSID ' , $ sessionId );
232
229
$ listener ->onKernelRequest (new RequestEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST ));
233
230
234
- $ session ->remove ('hello ' );
231
+ $ session ->start ();
232
+ $ sessionId = $ session ->getId ();
233
+ $ this ->assertNotEmpty ($ sessionId );
234
+ $ request ->cookies ->set ($ session ->getName (), $ sessionId );
235
+ $ _SESSION ['hello ' ] = 'world ' ; // check compatibility to php session bridge
236
+
235
237
$ session ->invalidate ();
236
238
237
239
$ response = new Response ();
@@ -245,6 +247,68 @@ public function testSessionCookieClearedWhenInvalidated()
245
247
$ this ->assertTrue ($ sessionCookie ->isCleared ());
246
248
}
247
249
250
+ /**
251
+ * @runInSeparateProcess
252
+ */
253
+ public function testSessionCookieNotClearedWhenOtherVariablesSet ()
254
+ {
255
+ $ session = new Session ();
256
+
257
+ $ container = new Container ();
258
+ $ container ->set ('initialized_session ' , $ session );
259
+
260
+ $ listener = new SessionListener ($ container );
261
+ $ kernel = $ this ->createMock (HttpKernelInterface::class);
262
+
263
+ $ request = new Request ();
264
+ $ listener ->onKernelRequest (new RequestEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST ));
265
+
266
+ $ session ->start ();
267
+ $ sessionId = $ session ->getId ();
268
+ $ this ->assertNotEmpty ($ sessionId );
269
+ $ request ->cookies ->set ($ session ->getName (), $ sessionId );
270
+ $ _SESSION ['hello ' ] = 'world ' ;
271
+
272
+ $ response = new Response ();
273
+ $ listener ->onKernelResponse (new ResponseEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST , $ response ));
274
+
275
+ $ cookies = $ response ->headers ->getCookies ();
276
+ $ this ->assertCount (0 , $ cookies );
277
+ }
278
+
279
+ /**
280
+ * @runInSeparateProcess
281
+ */
282
+ public function testSessionCookieSetWhenOtherNativeVariablesSet ()
283
+ {
284
+ $ session = new Session ();
285
+
286
+ $ container = new Container ();
287
+ $ container ->set ('initialized_session ' , $ session );
288
+
289
+ $ listener = new SessionListener ($ container );
290
+ $ kernel = $ this ->createMock (HttpKernelInterface::class);
291
+
292
+ $ request = new Request ();
293
+ $ listener ->onKernelRequest (new RequestEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST ));
294
+
295
+ $ session ->start ();
296
+ $ sessionId = $ session ->getId ();
297
+ $ this ->assertNotEmpty ($ sessionId );
298
+ $ _SESSION ['hello ' ] = 'world ' ;
299
+
300
+ $ response = new Response ();
301
+ $ listener ->onKernelResponse (new ResponseEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST , $ response ));
302
+
303
+ $ cookies = $ response ->headers ->getCookies ();
304
+ $ this ->assertCount (1 , $ cookies );
305
+ $ sessionCookie = $ cookies [0 ];
306
+
307
+ $ this ->assertSame ('PHPSESSID ' , $ sessionCookie ->getName ());
308
+ $ this ->assertNotEmpty ($ sessionCookie ->getValue ());
309
+ $ this ->assertFalse ($ sessionCookie ->isCleared ());
310
+ }
311
+
248
312
public function testOnlyTriggeredOnMainRequest ()
249
313
{
250
314
$ listener = $ this ->getMockForAbstractClass (AbstractSessionListener::class);
0 commit comments