@@ -40,29 +40,27 @@ class SessionListenerTest extends TestCase
40
40
*/
41
41
public function testSessionCookieOptions (array $ phpSessionOptions , array $ sessionOptions , array $ expectedSessionOptions )
42
42
{
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 );
49
49
50
50
if (isset ($ phpSessionOptions ['samesite ' ])) {
51
51
ini_set ('session.cookie_samesite ' , $ phpSessionOptions ['samesite ' ]);
52
52
}
53
53
session_set_cookie_params (0 , $ phpSessionOptions ['path ' ] ?? null , $ phpSessionOptions ['domain ' ] ?? null , $ phpSessionOptions ['secure ' ] ?? null , $ phpSessionOptions ['httponly ' ] ?? null );
54
54
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);
60
57
61
58
$ request = new Request ();
62
59
$ listener ->onKernelRequest (new RequestEvent ($ kernel , $ request , HttpKernelInterface::MAIN_REQUEST ));
63
60
61
+ $ request ->setSession ($ session );
64
62
$ 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 ));
66
64
67
65
$ cookies = $ response ->headers ->getCookies ();
68
66
$ this ->assertSame ('PHPSESSID ' , $ cookies [0 ]->getName ());
0 commit comments