Skip to content

Commit 1087a47

Browse files
committed
Merge branch '5.1' into 5.2
* 5.1: Use ::class keyword when possible
2 parents 35bf93a + 34ef29d commit 1087a47

File tree

7 files changed

+45
-45
lines changed

7 files changed

+45
-45
lines changed

Tests/Authentication/Provider/DaoAuthenticationProviderTest.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DaoAuthenticationProviderTest extends TestCase
2525
{
2626
public function testRetrieveUserWhenProviderDoesNotReturnAnUserInterface()
2727
{
28-
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationServiceException');
28+
$this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationServiceException::class);
2929
$provider = $this->getProvider('fabien');
3030
$method = new \ReflectionMethod($provider, 'retrieveUser');
3131
$method->setAccessible(true);
@@ -35,14 +35,14 @@ public function testRetrieveUserWhenProviderDoesNotReturnAnUserInterface()
3535

3636
public function testRetrieveUserWhenUsernameIsNotFound()
3737
{
38-
$this->expectException('Symfony\Component\Security\Core\Exception\UsernameNotFoundException');
39-
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
38+
$this->expectException(UsernameNotFoundException::class);
39+
$userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
4040
$userProvider->expects($this->once())
4141
->method('loadUserByUsername')
4242
->willThrowException(new UsernameNotFoundException())
4343
;
4444

45-
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface')->getMock(), 'key', $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface')->getMock());
45+
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock(), 'key', $this->getMockBuilder(\Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface::class)->getMock());
4646
$method = new \ReflectionMethod($provider, 'retrieveUser');
4747
$method->setAccessible(true);
4848

@@ -51,14 +51,14 @@ public function testRetrieveUserWhenUsernameIsNotFound()
5151

5252
public function testRetrieveUserWhenAnExceptionOccurs()
5353
{
54-
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationServiceException');
55-
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
54+
$this->expectException(\Symfony\Component\Security\Core\Exception\AuthenticationServiceException::class);
55+
$userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
5656
$userProvider->expects($this->once())
5757
->method('loadUserByUsername')
5858
->willThrowException(new \RuntimeException())
5959
;
6060

61-
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface')->getMock(), 'key', $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface')->getMock());
61+
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock(), 'key', $this->getMockBuilder(\Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface::class)->getMock());
6262
$method = new \ReflectionMethod($provider, 'retrieveUser');
6363
$method->setAccessible(true);
6464

@@ -67,7 +67,7 @@ public function testRetrieveUserWhenAnExceptionOccurs()
6767

6868
public function testRetrieveUserReturnsUserFromTokenOnReauthentication()
6969
{
70-
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
70+
$userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
7171
$userProvider->expects($this->never())
7272
->method('loadUserByUsername')
7373
;
@@ -79,7 +79,7 @@ public function testRetrieveUserReturnsUserFromTokenOnReauthentication()
7979
->willReturn($user)
8080
;
8181

82-
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface')->getMock(), 'key', $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface')->getMock());
82+
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock(), 'key', $this->getMockBuilder(\Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface::class)->getMock());
8383
$reflection = new \ReflectionMethod($provider, 'retrieveUser');
8484
$reflection->setAccessible(true);
8585
$result = $reflection->invoke($provider, 'someUser', $token);
@@ -91,13 +91,13 @@ public function testRetrieveUser()
9191
{
9292
$user = new TestUser();
9393

94-
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
94+
$userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
9595
$userProvider->expects($this->once())
9696
->method('loadUserByUsername')
9797
->willReturn($user)
9898
;
9999

100-
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface')->getMock(), 'key', $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface')->getMock());
100+
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock(), 'key', $this->getMockBuilder(\Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface::class)->getMock());
101101
$method = new \ReflectionMethod($provider, 'retrieveUser');
102102
$method->setAccessible(true);
103103

@@ -106,8 +106,8 @@ public function testRetrieveUser()
106106

107107
public function testCheckAuthenticationWhenCredentialsAreEmpty()
108108
{
109-
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
110-
$encoder = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
109+
$this->expectException(\Symfony\Component\Security\Core\Exception\BadCredentialsException::class);
110+
$encoder = $this->getMockBuilder(\Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface::class)->getMock();
111111
$encoder
112112
->expects($this->never())
113113
->method('isPasswordValid')
@@ -129,7 +129,7 @@ public function testCheckAuthenticationWhenCredentialsAreEmpty()
129129

130130
public function testCheckAuthenticationWhenCredentialsAre0()
131131
{
132-
$encoder = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
132+
$encoder = $this->getMockBuilder(\Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface::class)->getMock();
133133
$encoder
134134
->expects($this->once())
135135
->method('isPasswordValid')
@@ -156,8 +156,8 @@ public function testCheckAuthenticationWhenCredentialsAre0()
156156

157157
public function testCheckAuthenticationWhenCredentialsAreNotValid()
158158
{
159-
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
160-
$encoder = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
159+
$this->expectException(\Symfony\Component\Security\Core\Exception\BadCredentialsException::class);
160+
$encoder = $this->getMockBuilder(\Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface::class)->getMock();
161161
$encoder->expects($this->once())
162162
->method('isPasswordValid')
163163
->willReturn(false)
@@ -178,8 +178,8 @@ public function testCheckAuthenticationWhenCredentialsAreNotValid()
178178

179179
public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChanged()
180180
{
181-
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
182-
$user = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
181+
$this->expectException(\Symfony\Component\Security\Core\Exception\BadCredentialsException::class);
182+
$user = $this->getMockBuilder(UserInterface::class)->getMock();
183183
$user->expects($this->once())
184184
->method('getPassword')
185185
->willReturn('foo')
@@ -190,7 +190,7 @@ public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChang
190190
->method('getUser')
191191
->willReturn($user);
192192

193-
$dbUser = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
193+
$dbUser = $this->getMockBuilder(UserInterface::class)->getMock();
194194
$dbUser->expects($this->once())
195195
->method('getPassword')
196196
->willReturn('newFoo')
@@ -204,7 +204,7 @@ public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChang
204204

205205
public function testCheckAuthenticationWhenTokenNeedsReauthenticationWorksWithoutOriginalCredentials()
206206
{
207-
$user = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
207+
$user = $this->getMockBuilder(UserInterface::class)->getMock();
208208
$user->expects($this->once())
209209
->method('getPassword')
210210
->willReturn('foo')
@@ -215,7 +215,7 @@ public function testCheckAuthenticationWhenTokenNeedsReauthenticationWorksWithou
215215
->method('getUser')
216216
->willReturn($user);
217217

218-
$dbUser = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
218+
$dbUser = $this->getMockBuilder(UserInterface::class)->getMock();
219219
$dbUser->expects($this->once())
220220
->method('getPassword')
221221
->willReturn('foo')
@@ -229,7 +229,7 @@ public function testCheckAuthenticationWhenTokenNeedsReauthenticationWorksWithou
229229

230230
public function testCheckAuthentication()
231231
{
232-
$encoder = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
232+
$encoder = $this->getMockBuilder(\Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface::class)->getMock();
233233
$encoder->expects($this->once())
234234
->method('isPasswordValid')
235235
->willReturn(true)
@@ -288,7 +288,7 @@ public function testPasswordUpgrades()
288288

289289
protected function getSupportedToken()
290290
{
291-
$mock = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken')->setMethods(['getCredentials', 'getUser', 'getProviderKey'])->disableOriginalConstructor()->getMock();
291+
$mock = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken::class)->setMethods(['getCredentials', 'getUser', 'getProviderKey'])->disableOriginalConstructor()->getMock();
292292
$mock
293293
->expects($this->any())
294294
->method('getProviderKey')
@@ -309,14 +309,14 @@ protected function getProvider($user = null, $userChecker = null, $passwordEncod
309309
}
310310

311311
if (null === $userChecker) {
312-
$userChecker = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface')->getMock();
312+
$userChecker = $this->getMockBuilder(\Symfony\Component\Security\Core\User\UserCheckerInterface::class)->getMock();
313313
}
314314

315315
if (null === $passwordEncoder) {
316316
$passwordEncoder = new PlaintextPasswordEncoder();
317317
}
318318

319-
$encoderFactory = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface')->getMock();
319+
$encoderFactory = $this->getMockBuilder(\Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface::class)->getMock();
320320
$encoderFactory
321321
->expects($this->any())
322322
->method('getEncoder')

Tests/Authentication/Token/AbstractTokenTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testGetUsername()
2626
$token->setUser(new TestUser('fabien'));
2727
$this->assertEquals('fabien', $token->getUsername());
2828

29-
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
29+
$user = $this->getMockBuilder(UserInterface::class)->getMock();
3030
$user->expects($this->once())->method('getUsername')->willReturn('fabien');
3131
$token->setUser($user);
3232
$this->assertEquals('fabien', $token->getUsername());
@@ -36,7 +36,7 @@ public function testEraseCredentials()
3636
{
3737
$token = new ConcreteToken(['ROLE_FOO']);
3838

39-
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
39+
$user = $this->getMockBuilder(UserInterface::class)->getMock();
4040
$user->expects($this->once())->method('eraseCredentials');
4141
$token->setUser($user);
4242

@@ -106,7 +106,7 @@ public function testSetUser($user)
106106

107107
public function getUsers()
108108
{
109-
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
109+
$user = $this->getMockBuilder(UserInterface::class)->getMock();
110110

111111
return [
112112
[$user],
@@ -133,7 +133,7 @@ public function testSetUserSetsAuthenticatedToFalseWhenUserChanges($firstUser, $
133133

134134
public function getUserChanges()
135135
{
136-
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
136+
$user = $this->getMockBuilder(UserInterface::class)->getMock();
137137

138138
return [
139139
['foo', 'bar'],

Tests/Authorization/AccessDecisionManagerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AccessDecisionManagerTest extends TestCase
1919
{
2020
public function testSetUnsupportedStrategy()
2121
{
22-
$this->expectException('InvalidArgumentException');
22+
$this->expectException(\InvalidArgumentException::class);
2323
new AccessDecisionManager([$this->getVoter(VoterInterface::ACCESS_GRANTED)], 'fooBar');
2424
}
2525

@@ -28,7 +28,7 @@ public function testSetUnsupportedStrategy()
2828
*/
2929
public function testStrategies($strategy, $voters, $allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions, $expected)
3030
{
31-
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
31+
$token = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
3232
$manager = new AccessDecisionManager($voters, $strategy, $allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions);
3333

3434
$this->assertSame($expected, $manager->decide($token, ['ROLE_FOO']));
@@ -112,7 +112,7 @@ protected function getVoters($grants, $denies, $abstains)
112112

113113
protected function getVoter($vote)
114114
{
115-
$voter = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface')->getMock();
115+
$voter = $this->getMockBuilder(VoterInterface::class)->getMock();
116116
$voter->expects($this->any())
117117
->method('vote')
118118
->willReturn($vote);

Tests/Authorization/Voter/AuthenticatedVoterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ public function getVoteTests()
6464
protected function getToken($authenticated)
6565
{
6666
if ('fully' === $authenticated) {
67-
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
67+
return $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
6868
} elseif ('remembered' === $authenticated) {
69-
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken')->setMethods(['setPersistent'])->disableOriginalConstructor()->getMock();
69+
return $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\RememberMeToken::class)->setMethods(['setPersistent'])->disableOriginalConstructor()->getMock();
7070
} elseif ('impersonated' === $authenticated) {
71-
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken')->disableOriginalConstructor()->getMock();
71+
return $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken::class)->disableOriginalConstructor()->getMock();
7272
} else {
73-
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken')->setConstructorArgs(['', ''])->getMock();
73+
return $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\AnonymousToken::class)->setConstructorArgs(['', ''])->getMock();
7474
}
7575
}
7676
}

Tests/Authorization/Voter/ExpressionVoterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function getTokenWithRoleNames(array $roles, $tokenExpectsGetRoles = t
5757

5858
protected function createExpressionLanguage($expressionLanguageExpectsEvaluate = true)
5959
{
60-
$mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\ExpressionLanguage')->getMock();
60+
$mock = $this->getMockBuilder(\Symfony\Component\Security\Core\Authorization\ExpressionLanguage::class)->getMock();
6161

6262
if ($expressionLanguageExpectsEvaluate) {
6363
$mock->expects($this->once())
@@ -70,7 +70,7 @@ protected function createExpressionLanguage($expressionLanguageExpectsEvaluate =
7070

7171
protected function createTrustResolver()
7272
{
73-
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface')->getMock();
73+
return $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface::class)->getMock();
7474
}
7575

7676
protected function createAuthorizationChecker()
@@ -80,7 +80,7 @@ protected function createAuthorizationChecker()
8080

8181
protected function createExpression()
8282
{
83-
return $this->getMockBuilder('Symfony\Component\ExpressionLanguage\Expression')
83+
return $this->getMockBuilder(\Symfony\Component\ExpressionLanguage\Expression::class)
8484
->disableOriginalConstructor()
8585
->getMock();
8686
}

Tests/Authorization/Voter/VoterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testVote(VoterInterface $voter, array $attributes, $expectedVote
6565

6666
public function testVoteWithTypeError()
6767
{
68-
$this->expectException('TypeError');
68+
$this->expectException(\TypeError::class);
6969
$this->expectExceptionMessage('Should error');
7070
$voter = new TypeErrorVoterTest_Voter();
7171
$voter->vote($this->token, new \stdClass(), ['EDIT']);

0 commit comments

Comments
 (0)