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

Commite963594

Browse files
committed
Don't rely on session service in tests
1 parentdff5206 commite963594

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,29 +40,27 @@ class SessionListenerTest extends TestCase
4040
*/
4141
publicfunctiontestSessionCookieOptions(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 =newContainer();
56-
$container->set('initialized_session',$session);
57-
58-
$listener =newSessionListener($container,false,$sessionOptions);
59-
$kernel =$this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
55+
$listener =newSessionListener(newContainer(),false,$sessionOptions);
56+
$kernel =$this->createMock(HttpKernelInterface::class);
6057

6158
$request =newRequest();
6259
$listener->onKernelRequest(newRequestEvent($kernel,$request, HttpKernelInterface::MAIN_REQUEST));
6360

61+
$request->setSession($session);
6462
$response =newResponse();
65-
$listener->onKernelResponse(newResponseEvent($kernel,newRequest(), HttpKernelInterface::MAIN_REQUEST,$response));
63+
$listener->onKernelResponse(newResponseEvent($kernel,$request, HttpKernelInterface::MAIN_REQUEST,$response));
6664

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp