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 bfbc5a6

Browse filesBrowse files
committed
minor #44749 [HttpKernel] Don't rely on session service in tests (derrabus)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpKernel] Don't rely on session service in tests | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Follow-up to #44518 | License | MIT | Doc PR | N/A The test introduced by #44518 makes use of the deprecated session service mechanism. Instead, I've attached the session to the request. This allows us to merge the test up to 6.0 and beyond without breaking it. Commits ------- e963594 Don't rely on session service in tests
2 parents dff5206 + e963594 commit bfbc5a6
Copy full SHA for bfbc5a6

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.