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

Appearance settings

Commit e963594

Browse filesBrowse files
committed
Don't rely on session service in tests
1 parent dff5206 commit e963594
Copy full SHA for e963594

File tree

1 file changed

+10
-12
lines changed
Filter options

1 file changed

+10
-12
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php
+10-12Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,27 @@ class SessionListenerTest extends TestCase
4040
*/
4141
public function testSessionCookieOptions(array $phpSessionOptions, array $sessionOptions, array $expectedSessionOptions)
4242
{
43-
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
44-
$session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
45-
$session->expects($this->exactly(1))->method('getId')->willReturn('123456');
46-
$session->expects($this->exactly(1))->method('getName')->willReturn('PHPSESSID');
47-
$session->expects($this->exactly(1))->method('save');
48-
$session->expects($this->exactly(1))->method('isStarted')->willReturn(true);
43+
$session = $this->createMock(Session::class);
44+
$session->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1));
45+
$session->method('getId')->willReturn('123456');
46+
$session->method('getName')->willReturn('PHPSESSID');
47+
$session->method('save');
48+
$session->method('isStarted')->willReturn(true);
4949

5050
if (isset($phpSessionOptions['samesite'])) {
5151
ini_set('session.cookie_samesite', $phpSessionOptions['samesite']);
5252
}
5353
session_set_cookie_params(0, $phpSessionOptions['path'] ?? null, $phpSessionOptions['domain'] ?? null, $phpSessionOptions['secure'] ?? null, $phpSessionOptions['httponly'] ?? null);
5454

55-
$container = new Container();
56-
$container->set('initialized_session', $session);
57-
58-
$listener = new SessionListener($container, false, $sessionOptions);
59-
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
55+
$listener = new SessionListener(new Container(), false, $sessionOptions);
56+
$kernel = $this->createMock(HttpKernelInterface::class);
6057

6158
$request = new Request();
6259
$listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST));
6360

61+
$request->setSession($session);
6462
$response = new Response();
65-
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, $response));
63+
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response));
6664

6765
$cookies = $response->headers->getCookies();
6866
$this->assertSame('PHPSESSID', $cookies[0]->getName());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.