77use PhpList \RestApiClient \Entity \Administrator ;
88use PhpList \WebFrontend \Controller \AuthController ;
99use PhpList \RestApiClient \Endpoint \AuthClient ;
10+ use PHPUnit \Framework \Assert ;
1011use PHPUnit \Framework \MockObject \MockObject ;
1112use PHPUnit \Framework \TestCase ;
1213use RuntimeException ;
@@ -107,13 +108,21 @@ public function testLoginWithPostRequestSuccess(): void
107108 ['login_error ' , false ]
108109 ]);
109110
111+ $ expected = [
112+ ['auth_token ' , 'test-token ' ],
113+ ['auth_expiry_date ' , '2026-03-18T14:15:38+04:00 ' ],
114+ ['auth_id ' , 1 ],
115+ ];
116+
117+ $ index = 0 ;
118+
110119 $ session ->expects ($ this ->exactly (3 ))
111120 ->method ('set ' )
112- ->withConsecutive (
113- [ ' auth_token ' , ' test-token ' ],
114- [ ' auth_expiry_date ' , ' test-token ' ],
115- [ ' auth_id ' , 1 ]
116- );
121+ ->willReturnCallback ( function ( $ key , $ value ) use (& $ expected , & $ index ) {
122+ Assert:: assertSame ( $ expected [ $ index ][ 0 ], $ key );
123+ Assert:: assertSame ( $ expected [ $ index ][ 1 ], $ value );
124+ $ index ++;
125+ } );
117126
118127 $ request = Request::create ('/login ' , 'POST ' , [
119128 'username ' => 'testuser ' ,
@@ -123,7 +132,7 @@ public function testLoginWithPostRequestSuccess(): void
123132
124133 $ this ->authClient ->method ('login ' )
125134 ->with ('testuser ' , 'testpass ' )
126- ->willReturn (['key ' => 'test-token ' , 'id ' => 1 ]);
135+ ->willReturn (['key ' => 'test-token ' , 'id ' => 1 , ' expiry_date ' => ' 2026-03-18T14:15:38+04:00 ' ]);
127136
128137 $ response = $ this ->controller ->login ($ request );
129138
@@ -181,12 +190,19 @@ public function testLoginWithExistingSession(): void
181190 public function testLogout (): void
182191 {
183192 $ session = $ this ->createMock (SessionInterface::class);
193+ $ expected = [
194+ ['auth_token ' ],
195+ ['auth_id ' ],
196+ ];
197+
198+ $ index = 0 ;
199+
184200 $ session ->expects ($ this ->exactly (2 ))
185201 ->method ('remove ' )
186- ->withConsecutive (
187- [ ' auth_token ' ],
188- [ ' auth_id ' ]
189- );
202+ ->willReturnCallback ( function ( $ key ) use (& $ expected , & $ index ) {
203+ Assert:: assertSame ( $ expected [ $ index ][ 0 ], $ key );
204+ $ index ++;
205+ } );
190206
191207 $ request = $ this ->createMock (Request::class);
192208 $ request ->method ('getSession ' )
0 commit comments