@@ -42,16 +42,16 @@ class SwitchUserListenerTest extends TestCase
42
42
protected function setUp (): void
43
43
{
44
44
$ this ->tokenStorage = new TokenStorage ();
45
- $ this ->userProvider = $ this ->getMockBuilder (' Symfony\Component\Security\Core\User\UserProviderInterface ' )->getMock ();
46
- $ this ->userChecker = $ this ->getMockBuilder (' Symfony\Component\Security\Core\User\UserCheckerInterface ' )->getMock ();
47
- $ this ->accessDecisionManager = $ this ->getMockBuilder (' Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface ' )->getMock ();
45
+ $ this ->userProvider = $ this ->getMockBuilder (\ Symfony \Component \Security \Core \User \UserProviderInterface::class )->getMock ();
46
+ $ this ->userChecker = $ this ->getMockBuilder (\ Symfony \Component \Security \Core \User \UserCheckerInterface::class )->getMock ();
47
+ $ this ->accessDecisionManager = $ this ->getMockBuilder (\ Symfony \Component \Security \Core \Authorization \AccessDecisionManagerInterface::class )->getMock ();
48
48
$ this ->request = new Request ();
49
49
$ this ->event = new RequestEvent ($ this ->getMockBuilder (HttpKernelInterface::class)->getMock (), $ this ->request , HttpKernelInterface::MASTER_REQUEST );
50
50
}
51
51
52
52
public function testFirewallNameIsRequired ()
53
53
{
54
- $ this ->expectException (' InvalidArgumentException ' );
54
+ $ this ->expectException (\ InvalidArgumentException::class );
55
55
$ this ->expectExceptionMessage ('$firewallName must not be empty ' );
56
56
new SwitchUserListener ($ this ->tokenStorage , $ this ->userProvider , $ this ->userChecker , '' , $ this ->accessDecisionManager );
57
57
}
@@ -67,7 +67,7 @@ public function testEventIsIgnoredIfUsernameIsNotPassedWithTheRequest()
67
67
68
68
public function testExitUserThrowsAuthenticationExceptionIfNoCurrentToken ()
69
69
{
70
- $ this ->expectException (' Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException ' );
70
+ $ this ->expectException (\ Symfony \Component \Security \Core \Exception \AuthenticationCredentialsNotFoundException::class );
71
71
$ this ->tokenStorage ->setToken (null );
72
72
$ this ->request ->query ->set ('_switch_user ' , '_exit ' );
73
73
$ listener = new SwitchUserListener ($ this ->tokenStorage , $ this ->userProvider , $ this ->userChecker , 'provider123 ' , $ this ->accessDecisionManager );
@@ -76,7 +76,7 @@ public function testExitUserThrowsAuthenticationExceptionIfNoCurrentToken()
76
76
77
77
public function testExitUserThrowsAuthenticationExceptionIfOriginalTokenCannotBeFound ()
78
78
{
79
- $ this ->expectException (' Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException ' );
79
+ $ this ->expectException (\ Symfony \Component \Security \Core \Exception \AuthenticationCredentialsNotFoundException::class );
80
80
$ token = new UsernamePasswordToken ('username ' , '' , 'key ' , ['ROLE_FOO ' ]);
81
81
82
82
$ this ->tokenStorage ->setToken ($ token );
@@ -98,15 +98,15 @@ public function testExitUserUpdatesToken()
98
98
99
99
$ this ->assertSame ([], $ this ->request ->query ->all ());
100
100
$ this ->assertSame ('' , $ this ->request ->server ->get ('QUERY_STRING ' ));
101
- $ this ->assertInstanceOf (' Symfony\Component\HttpFoundation\RedirectResponse ' , $ this ->event ->getResponse ());
101
+ $ this ->assertInstanceOf (\ Symfony \Component \HttpFoundation \RedirectResponse::class , $ this ->event ->getResponse ());
102
102
$ this ->assertSame ($ this ->request ->getUri (), $ this ->event ->getResponse ()->getTargetUrl ());
103
103
$ this ->assertSame ($ originalToken , $ this ->tokenStorage ->getToken ());
104
104
}
105
105
106
106
public function testExitUserDispatchesEventWithRefreshedUser ()
107
107
{
108
- $ originalUser = $ this ->getMockBuilder (' Symfony\Component\Security\Core\User\UserInterface ' )->getMock ();
109
- $ refreshedUser = $ this ->getMockBuilder (' Symfony\Component\Security\Core\User\UserInterface ' )->getMock ();
108
+ $ originalUser = $ this ->getMockBuilder (\ Symfony \Component \Security \Core \User \UserInterface::class )->getMock ();
109
+ $ refreshedUser = $ this ->getMockBuilder (\ Symfony \Component \Security \Core \User \UserInterface::class )->getMock ();
110
110
$ this
111
111
->userProvider
112
112
->expects ($ this ->any ())
@@ -156,7 +156,7 @@ public function testExitUserDoesNotDispatchEventWithStringUser()
156
156
157
157
public function testSwitchUserIsDisallowed ()
158
158
{
159
- $ this ->expectException (' Symfony\Component\Security\Core\Exception\AccessDeniedException ' );
159
+ $ this ->expectException (\ Symfony \Component \Security \Core \Exception \AccessDeniedException::class );
160
160
$ token = new UsernamePasswordToken ('username ' , '' , 'key ' , ['ROLE_FOO ' ]);
161
161
$ user = new User ('username ' , 'password ' , []);
162
162
@@ -178,7 +178,7 @@ public function testSwitchUserIsDisallowed()
178
178
179
179
public function testSwitchUserTurnsAuthenticationExceptionTo403 ()
180
180
{
181
- $ this ->expectException (' Symfony\Component\Security\Core\Exception\AccessDeniedException ' );
181
+ $ this ->expectException (\ Symfony \Component \Security \Core \Exception \AccessDeniedException::class );
182
182
$ token = new UsernamePasswordToken ('username ' , '' , 'key ' , ['ROLE_ALLOWED_TO_SWITCH ' ]);
183
183
184
184
$ this ->tokenStorage ->setToken ($ token );
@@ -220,7 +220,7 @@ public function testSwitchUser()
220
220
221
221
$ this ->assertSame ([], $ this ->request ->query ->all ());
222
222
$ this ->assertSame ('' , $ this ->request ->server ->get ('QUERY_STRING ' ));
223
- $ this ->assertInstanceOf (' Symfony\Component\Security\Core\Authentication\Token\ UsernamePasswordToken' , $ this ->tokenStorage ->getToken ());
223
+ $ this ->assertInstanceOf (UsernamePasswordToken::class , $ this ->tokenStorage ->getToken ());
224
224
}
225
225
226
226
public function testSwitchUserAlreadySwitched ()
@@ -280,7 +280,7 @@ public function testSwitchUserWorksWithFalsyUsernames()
280
280
281
281
$ this ->assertSame ([], $ this ->request ->query ->all ());
282
282
$ this ->assertSame ('' , $ this ->request ->server ->get ('QUERY_STRING ' ));
283
- $ this ->assertInstanceOf (' Symfony\Component\Security\Core\Authentication\Token\ UsernamePasswordToken' , $ this ->tokenStorage ->getToken ());
283
+ $ this ->assertInstanceOf (UsernamePasswordToken::class , $ this ->tokenStorage ->getToken ());
284
284
}
285
285
286
286
public function testSwitchUserKeepsOtherQueryStringParameters ()
@@ -310,7 +310,7 @@ public function testSwitchUserKeepsOtherQueryStringParameters()
310
310
$ listener ($ this ->event );
311
311
312
312
$ this ->assertSame ('page=3§ion=2 ' , $ this ->request ->server ->get ('QUERY_STRING ' ));
313
- $ this ->assertInstanceOf (' Symfony\Component\Security\Core\Authentication\Token\ UsernamePasswordToken' , $ this ->tokenStorage ->getToken ());
313
+ $ this ->assertInstanceOf (UsernamePasswordToken::class , $ this ->tokenStorage ->getToken ());
314
314
}
315
315
316
316
public function testSwitchUserWithReplacedToken ()
@@ -357,7 +357,7 @@ public function testSwitchUserWithReplacedToken()
357
357
358
358
public function testSwitchUserThrowsAuthenticationExceptionIfNoCurrentToken ()
359
359
{
360
- $ this ->expectException (' Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException ' );
360
+ $ this ->expectException (\ Symfony \Component \Security \Core \Exception \AuthenticationCredentialsNotFoundException::class );
361
361
$ this ->tokenStorage ->setToken (null );
362
362
$ this ->request ->query ->set ('_switch_user ' , 'username ' );
363
363
$ listener = new SwitchUserListener ($ this ->tokenStorage , $ this ->userProvider , $ this ->userChecker , 'provider123 ' , $ this ->accessDecisionManager );
@@ -386,7 +386,7 @@ public function testSwitchUserStateless()
386
386
$ listener = new SwitchUserListener ($ this ->tokenStorage , $ this ->userProvider , $ this ->userChecker , 'provider123 ' , $ this ->accessDecisionManager , null , '_switch_user ' , 'ROLE_ALLOWED_TO_SWITCH ' , null , true );
387
387
$ listener ($ this ->event );
388
388
389
- $ this ->assertInstanceOf (' Symfony\Component\Security\Core\Authentication\Token\ UsernamePasswordToken' , $ this ->tokenStorage ->getToken ());
389
+ $ this ->assertInstanceOf (UsernamePasswordToken::class , $ this ->tokenStorage ->getToken ());
390
390
$ this ->assertFalse ($ this ->event ->hasResponse ());
391
391
}
392
392
}
0 commit comments