1111use PHPUnit \Framework \TestCase ;
1212use Ratchet \ConnectionInterface ;
1313use Ratchet \Wamp \Topic ;
14+ use Symfony \Component \Security \Core \Authentication \Token \AbstractToken ;
1415use Symfony \Component \Security \Core \Authentication \Token \AnonymousToken ;
15- use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
1616use Symfony \Component \Security \Core \Authentication \Token \UsernamePasswordToken ;
1717
1818class ClientManipulatorTest extends TestCase
1919{
2020 /**
21- * @var MockObject| ClientStorageInterface
21+ * @var MockObject& ClientStorageInterface
2222 */
2323 private $ clientStorage ;
2424
2525 /**
26- * @var MockObject| WebsocketAuthenticationProviderInterface
26+ * @var MockObject& WebsocketAuthenticationProviderInterface
2727 */
2828 private $ authenticationProvider ;
2929
@@ -46,7 +46,7 @@ public function testGetClientForConnection(): void
4646 {
4747 $ connection = $ this ->createMock (ConnectionInterface::class);
4848 $ storageId = 42 ;
49- $ client = $ this ->createMock (TokenInterface ::class);
49+ $ client = $ this ->createMock (AbstractToken ::class);
5050
5151 $ this ->clientStorage ->expects ($ this ->once ())
5252 ->method ('getStorageId ' )
@@ -65,7 +65,7 @@ public function testGetClientForConnectionAfterReauthenticating(): void
6565 {
6666 $ connection = $ this ->createMock (ConnectionInterface::class);
6767 $ storageId = 42 ;
68- $ client = $ this ->createMock (TokenInterface ::class);
68+ $ client = $ this ->createMock (AbstractToken ::class);
6969
7070 $ this ->clientStorage ->expects ($ this ->exactly (2 ))
7171 ->method ('getStorageId ' )
@@ -89,13 +89,15 @@ public function testGetClientForConnectionAfterReauthenticating(): void
8989
9090 public function testAllConnectionsForAUserCanBeFoundByUsername (): void
9191 {
92- /** @var MockObject|ConnectionInterface $connection1 */
92+ $ usernameMethod = method_exists (AbstractToken::class, 'getUserIdentifier ' ) ? 'getUserIdentifier ' : 'getUsername ' ;
93+
94+ /** @var MockObject&ConnectionInterface $connection1 */
9395 $ connection1 = $ this ->createMock (ConnectionInterface::class);
9496
95- /** @var MockObject| ConnectionInterface $connection2 */
97+ /** @var MockObject& ConnectionInterface $connection2 */
9698 $ connection2 = $ this ->createMock (ConnectionInterface::class);
9799
98- /** @var MockObject| ConnectionInterface $connection3 */
100+ /** @var MockObject& ConnectionInterface $connection3 */
99101 $ connection3 = $ this ->createMock (ConnectionInterface::class);
100102
101103 $ storageId1 = 42 ;
@@ -105,22 +107,22 @@ public function testAllConnectionsForAUserCanBeFoundByUsername(): void
105107 $ username1 = 'user ' ;
106108 $ username2 = 'guest ' ;
107109
108- /** @var MockObject|TokenInterface $client1 */
109- $ client1 = $ this ->createMock (TokenInterface ::class);
110+ /** @var MockObject&AbstractToken $client1 */
111+ $ client1 = $ this ->createMock (AbstractToken ::class);
110112 $ client1 ->expects ($ this ->once ())
111- ->method (' getUsername ' )
113+ ->method ($ usernameMethod )
112114 ->willReturn ($ username1 );
113115
114- /** @var MockObject|TokenInterface $client2 */
115- $ client2 = $ this ->createMock (TokenInterface ::class);
116+ /** @var MockObject&AbstractToken $client2 */
117+ $ client2 = $ this ->createMock (AbstractToken ::class);
116118 $ client2 ->expects ($ this ->once ())
117- ->method (' getUsername ' )
119+ ->method ($ usernameMethod )
118120 ->willReturn ($ username1 );
119121
120- /** @var MockObject|TokenInterface $client3 */
121- $ client3 = $ this ->createMock (TokenInterface ::class);
122+ /** @var MockObject&AbstractToken $client3 */
123+ $ client3 = $ this ->createMock (AbstractToken ::class);
122124 $ client3 ->expects ($ this ->once ())
123- ->method (' getUsername ' )
125+ ->method ($ usernameMethod )
124126 ->willReturn ($ username2 );
125127
126128 $ this ->clientStorage ->expects ($ this ->exactly (3 ))
@@ -149,7 +151,7 @@ public function testAllConnectionsForAUserCanBeFoundByUsername(): void
149151 $ client3
150152 );
151153
152- /** @var MockObject| Topic $topic */
154+ /** @var MockObject& Topic $topic */
153155 $ topic = $ this ->createMock (Topic::class);
154156 $ topic ->expects ($ this ->once ())
155157 ->method ('getIterator ' )
@@ -172,7 +174,7 @@ public function testFetchingAllConnectionsByDefaultOnlyReturnsAuthenticatedUsers
172174 $ storageId1 = 42 ;
173175 $ storageId2 = 84 ;
174176
175- $ authenticatedClient = $ this ->createMock (TokenInterface ::class);
177+ $ authenticatedClient = $ this ->createMock (AbstractToken ::class);
176178 $ guestClient = $ this ->createMock (AnonymousToken::class);
177179
178180 $ this ->clientStorage ->expects ($ this ->exactly (2 ))
@@ -212,19 +214,19 @@ public function testFetchingAllConnectionsByDefaultOnlyReturnsAuthenticatedUsers
212214
213215 public function testFetchingAllConnectionsWithAnonymousFlagReturnsAllConnectedUsers (): void
214216 {
215- /** @var MockObject| ConnectionInterface $connection1 */
217+ /** @var MockObject& ConnectionInterface $connection1 */
216218 $ connection1 = $ this ->createMock (ConnectionInterface::class);
217219
218- /** @var MockObject| ConnectionInterface $connection2 */
220+ /** @var MockObject& ConnectionInterface $connection2 */
219221 $ connection2 = $ this ->createMock (ConnectionInterface::class);
220222
221223 $ storageId1 = 42 ;
222224 $ storageId2 = 84 ;
223225
224- /** @var MockObject|TokenInterface $authenticatedClient */
225- $ authenticatedClient = $ this ->createMock (TokenInterface ::class);
226+ /** @var MockObject&AbstractToken $authenticatedClient */
227+ $ authenticatedClient = $ this ->createMock (AbstractToken ::class);
226228
227- /** @var MockObject| AnonymousToken $guestClient */
229+ /** @var MockObject& AnonymousToken $guestClient */
228230 $ guestClient = $ this ->createMock (AnonymousToken::class);
229231
230232 $ this ->clientStorage ->expects ($ this ->exactly (2 ))
@@ -249,7 +251,7 @@ public function testFetchingAllConnectionsWithAnonymousFlagReturnsAllConnectedUs
249251 $ guestClient
250252 );
251253
252- /** @var MockObject| Topic $topic */
254+ /** @var MockObject& Topic $topic */
253255 $ topic = $ this ->createMock (Topic::class);
254256 $ topic ->expects ($ this ->once ())
255257 ->method ('getIterator ' )
0 commit comments