Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit84e5f4c

Browse files
Add test for session invalidated, session cookie given and not given
1 parent8c10721 commit84e5f4c

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

‎src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,94 @@ public function testPhpBridgeAlreadyStartedSession()
157157
$this->assertSame($sessionId,$request->getSession()->getId());
158158
}
159159

160+
/**
161+
* @runInSeparateProcess
162+
*/
163+
publicfunctiontestSessionCookieWrittenNoCookieGiven()
164+
{
165+
$session =newSession();
166+
$session->set('hello','world');
167+
168+
$container =newContainer();
169+
$container->set('initialized_session',$session);
170+
171+
$listener =newSessionListener($container);
172+
$kernel =$this->createMock(HttpKernelInterface::class);
173+
174+
$request =newRequest();
175+
$listener->onKernelRequest(newRequestEvent($kernel,$request, HttpKernelInterface::MAIN_REQUEST));
176+
177+
$response =newResponse();
178+
$listener->onKernelResponse(newResponseEvent($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+
publicfunctiontestSessionCookieNotWrittenCookieGiven()
193+
{
194+
$session =newSession();
195+
$session->set('hello','world');
196+
$sessionId =$session->getId();
197+
198+
$container =newContainer();
199+
$container->set('initialized_session',$session);
200+
201+
$listener =newSessionListener($container);
202+
$kernel =$this->createMock(HttpKernelInterface::class);
203+
204+
$request =newRequest();
205+
$request->cookies->set('PHPSESSID',$sessionId);
206+
$listener->onKernelRequest(newRequestEvent($kernel,$request, HttpKernelInterface::MAIN_REQUEST));
207+
208+
$response =newResponse();
209+
$listener->onKernelResponse(newResponseEvent($kernel,$request, HttpKernelInterface::MAIN_REQUEST,$response));
210+
211+
$cookies =$response->headers->getCookies();
212+
$this->assertCount(0,$cookies);
213+
}
214+
215+
/**
216+
* @runInSeparateProcess
217+
*/
218+
publicfunctiontestSessionCookieClearedWhenInvalidated()
219+
{
220+
$session =newSession();
221+
$session->set('hello','world');
222+
$sessionId =$session->getId();
223+
224+
$container =newContainer();
225+
$container->set('initialized_session',$session);
226+
227+
$listener =newSessionListener($container);
228+
$kernel =$this->createMock(HttpKernelInterface::class);
229+
230+
$request =newRequest();
231+
$request->cookies->set('PHPSESSID',$sessionId);
232+
$listener->onKernelRequest(newRequestEvent($kernel,$request, HttpKernelInterface::MAIN_REQUEST));
233+
234+
$session->remove('hello');
235+
$session->invalidate();
236+
237+
$response =newResponse();
238+
$listener->onKernelResponse(newResponseEvent($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+
160248
publicfunctiontestOnlyTriggeredOnMainRequest()
161249
{
162250
$listener =$this->getMockForAbstractClass(AbstractSessionListener::class);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp