@@ -157,6 +157,94 @@ public function testPhpBridgeAlreadyStartedSession()
157157$ this ->assertSame ($ sessionId ,$ request ->getSession ()->getId ());
158158 }
159159
160+ /**
161+ * @runInSeparateProcess
162+ */
163+ public function testSessionCookieWrittenNoCookieGiven ()
164+ {
165+ $ session =new Session ();
166+ $ session ->set ('hello ' ,'world ' );
167+
168+ $ container =new Container ();
169+ $ container ->set ('initialized_session ' ,$ session );
170+
171+ $ listener =new SessionListener ($ container );
172+ $ kernel =$ this ->createMock (HttpKernelInterface::class);
173+
174+ $ request =new Request ();
175+ $ listener ->onKernelRequest (new RequestEvent ($ kernel ,$ request , HttpKernelInterface::MAIN_REQUEST ));
176+
177+ $ response =new Response ();
178+ $ listener ->onKernelResponse (new ResponseEvent ($ kernel ,$ request , HttpKernelInterface::MAIN_REQUEST ,$ response ));
179+
180+ $ cookies =$ response ->headers ->getCookies ();
181+ $ this ->assertCount (1 ,$ cookies );
182+ $ sessionCookie =$ cookies [0 ];
183+
184+ $ this ->assertSame ('PHPSESSID ' ,$ sessionCookie ->getName ());
185+ $ this ->assertNotEmpty ($ sessionCookie ->getValue ());
186+ $ this ->assertFalse ($ sessionCookie ->isCleared ());
187+ }
188+
189+ /**
190+ * @runInSeparateProcess
191+ */
192+ public function testSessionCookieNotWrittenCookieGiven ()
193+ {
194+ $ session =new Session ();
195+ $ session ->set ('hello ' ,'world ' );
196+ $ sessionId =$ session ->getId ();
197+
198+ $ container =new Container ();
199+ $ container ->set ('initialized_session ' ,$ session );
200+
201+ $ listener =new SessionListener ($ container );
202+ $ kernel =$ this ->createMock (HttpKernelInterface::class);
203+
204+ $ request =new Request ();
205+ $ request ->cookies ->set ('PHPSESSID ' ,$ sessionId );
206+ $ listener ->onKernelRequest (new RequestEvent ($ kernel ,$ request , HttpKernelInterface::MAIN_REQUEST ));
207+
208+ $ response =new Response ();
209+ $ listener ->onKernelResponse (new ResponseEvent ($ kernel ,$ request , HttpKernelInterface::MAIN_REQUEST ,$ response ));
210+
211+ $ cookies =$ response ->headers ->getCookies ();
212+ $ this ->assertCount (0 ,$ cookies );
213+ }
214+
215+ /**
216+ * @runInSeparateProcess
217+ */
218+ public function testSessionCookieClearedWhenInvalidated ()
219+ {
220+ $ session =new Session ();
221+ $ session ->set ('hello ' ,'world ' );
222+ $ sessionId =$ session ->getId ();
223+
224+ $ container =new Container ();
225+ $ container ->set ('initialized_session ' ,$ session );
226+
227+ $ listener =new SessionListener ($ container );
228+ $ kernel =$ this ->createMock (HttpKernelInterface::class);
229+
230+ $ request =new Request ();
231+ $ request ->cookies ->set ('PHPSESSID ' ,$ sessionId );
232+ $ listener ->onKernelRequest (new RequestEvent ($ kernel ,$ request , HttpKernelInterface::MAIN_REQUEST ));
233+
234+ $ session ->remove ('hello ' );
235+ $ session ->invalidate ();
236+
237+ $ response =new Response ();
238+ $ listener ->onKernelResponse (new ResponseEvent ($ kernel ,$ request , HttpKernelInterface::MAIN_REQUEST ,$ response ));
239+
240+ $ cookies =$ response ->headers ->getCookies ();
241+ $ this ->assertCount (1 ,$ cookies );
242+ $ sessionCookie =$ cookies [0 ];
243+
244+ $ this ->assertSame ('PHPSESSID ' ,$ sessionCookie ->getName ());
245+ $ this ->assertTrue ($ sessionCookie ->isCleared ());
246+ }
247+
160248public function testOnlyTriggeredOnMainRequest ()
161249 {
162250$ listener =$ this ->getMockForAbstractClass (AbstractSessionListener::class);