@@ -106,6 +106,36 @@ public function testEmptySessionWithNewSessionIdDoesSendCookie()
106
106
$ this ->assertNotEmpty ($ response ->headers ->getCookies ());
107
107
}
108
108
109
+ /**
110
+ * @dataProvider anotherCookieProvider
111
+ */
112
+ public function testSessionWithNewSessionIdAndNewCookieDoesNotSendAnotherCookie ($ existing , array $ expected )
113
+ {
114
+ $ this ->sessionHasBeenStarted ();
115
+ $ this ->sessionIsEmpty ();
116
+ $ this ->fixSessionId ('456 ' );
117
+
118
+ $ kernel = $ this ->getMockBuilder ('Symfony\Component\HttpKernel\HttpKernelInterface ' )->getMock ();
119
+ $ request = Request::create ('/ ' , 'GET ' , array (), array ('MOCKSESSID ' => '123 ' ));
120
+ $ event = new GetResponseEvent ($ kernel , $ request , HttpKernelInterface::MASTER_REQUEST );
121
+ $ this ->listener ->onKernelRequest ($ event );
122
+
123
+ $ response = new Response ('' , 200 , array ('Set-Cookie ' => $ existing ));
124
+
125
+ $ response = $ this ->filterResponse (new Request (), HttpKernelInterface::MASTER_REQUEST , $ response );
126
+
127
+ $ this ->assertSame ($ expected , $ response ->headers ->get ('Set-Cookie ' , null , false ));
128
+ }
129
+
130
+ public function anotherCookieProvider ()
131
+ {
132
+ return array (
133
+ 'same ' => array ('MOCKSESSID=789; path=/ ' , array ('MOCKSESSID=789; path=/ ' )),
134
+ 'different domain ' => array ('MOCKSESSID=789; path=/; domain=example.com ' , array ('MOCKSESSID=789; path=/; domain=example.com ' , 'MOCKSESSID=456; path=/ ' )),
135
+ 'different path ' => array ('MOCKSESSID=789; path=/foo ' , array ('MOCKSESSID=789; path=/foo ' , 'MOCKSESSID=456; path=/ ' )),
136
+ );
137
+ }
138
+
109
139
public function testUnstartedSessionIsNotSave ()
110
140
{
111
141
$ this ->sessionHasNotBeenStarted ();
@@ -123,10 +153,10 @@ public function testDoesNotImplementServiceSubscriberInterface()
123
153
$ this ->assertFalse (is_subclass_of (TestSessionListener::class, ServiceSubscriberInterface::class, 'Implementing ServiceSubscriberInterface would create a dep on the DI component, which eg Silex cannot afford ' ));
124
154
}
125
155
126
- private function filterResponse (Request $ request , $ type = HttpKernelInterface::MASTER_REQUEST )
156
+ private function filterResponse (Request $ request , $ type = HttpKernelInterface::MASTER_REQUEST , Response $ response = null )
127
157
{
128
158
$ request ->setSession ($ this ->session );
129
- $ response = new Response ();
159
+ $ response = $ response ?: new Response ();
130
160
$ kernel = $ this ->getMockBuilder ('Symfony\Component\HttpKernel\HttpKernelInterface ' )->getMock ();
131
161
$ event = new FilterResponseEvent ($ kernel , $ request , $ type , $ response );
132
162
0 commit comments