Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit 674b38f

Browse files
committed
fixed obsolete getMock() usage
1 parent b61218e commit 674b38f

11 files changed

+71
-71
lines changed

Core/Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public function testSupports()
2020
$provider = $this->getProvider('foo');
2121

2222
$this->assertTrue($provider->supports($this->getSupportedToken('foo')));
23-
$this->assertFalse($provider->supports($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')));
23+
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
2424
}
2525

2626
public function testAuthenticateWhenTokenIsNotSupported()
2727
{
2828
$provider = $this->getProvider('foo');
2929

30-
$this->assertNull($provider->authenticate($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')));
30+
$this->assertNull($provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
3131
}
3232

3333
/**
@@ -50,7 +50,7 @@ public function testAuthenticate()
5050

5151
protected function getSupportedToken($secret)
5252
{
53-
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken', array('getSecret'), array(), '', false);
53+
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken')->setMethods(array('getSecret'))->disableOriginalConstructor()->getMock();
5454
$token->expects($this->any())
5555
->method('getSecret')
5656
->will($this->returnValue($secret))

Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class LdapBindAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
2727
*/
2828
public function testEmptyPasswordShouldThrowAnException()
2929
{
30-
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
31-
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
32-
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
30+
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
31+
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
32+
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
3333

3434
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
3535
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
@@ -44,14 +44,14 @@ public function testEmptyPasswordShouldThrowAnException()
4444
*/
4545
public function testBindFailureShouldThrowAnException()
4646
{
47-
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
48-
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
47+
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
48+
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
4949
$ldap
5050
->expects($this->once())
5151
->method('bind')
5252
->will($this->throwException(new ConnectionException()))
5353
;
54-
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
54+
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
5555

5656
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
5757
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
@@ -62,15 +62,15 @@ public function testBindFailureShouldThrowAnException()
6262

6363
public function testRetrieveUser()
6464
{
65-
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
65+
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
6666
$userProvider
6767
->expects($this->once())
6868
->method('loadUserByUsername')
6969
->with('foo')
7070
;
71-
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
71+
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
7272

73-
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
73+
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
7474

7575
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
7676
$reflection = new \ReflectionMethod($provider, 'retrieveUser');

Core/Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public function testSupports()
2222
$provider = $this->getProvider();
2323

2424
$this->assertTrue($provider->supports($this->getSupportedToken()));
25-
$this->assertFalse($provider->supports($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')));
25+
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
2626
}
2727

2828
public function testAuthenticateWhenTokenIsNotSupported()
2929
{
3030
$provider = $this->getProvider();
3131

32-
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
32+
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
3333
$this->assertNull($provider->authenticate($token));
3434
}
3535

@@ -49,7 +49,7 @@ public function testAuthenticateWhenSecretsDoNotMatch()
4949
*/
5050
public function testAuthenticateWhenPreChecksFails()
5151
{
52-
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
52+
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
5353
$userChecker->expects($this->once())
5454
->method('checkPreAuth')
5555
->will($this->throwException(new DisabledException()));
@@ -61,7 +61,7 @@ public function testAuthenticateWhenPreChecksFails()
6161

6262
public function testAuthenticate()
6363
{
64-
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
64+
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
6565
$user->expects($this->exactly(2))
6666
->method('getRoles')
6767
->will($this->returnValue(array('ROLE_FOO')));
@@ -80,14 +80,14 @@ public function testAuthenticate()
8080
protected function getSupportedToken($user = null, $secret = 'test')
8181
{
8282
if (null === $user) {
83-
$user = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
83+
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
8484
$user
8585
->expects($this->any())
8686
->method('getRoles')
8787
->will($this->returnValue(array()));
8888
}
8989

90-
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', array('getProviderKey'), array($user, 'foo', $secret));
90+
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken')->setMethods(array('getProviderKey'))->setConstructorArgs(array($user, 'foo', $secret))->getMock();
9191
$token
9292
->expects($this->once())
9393
->method('getProviderKey')
@@ -99,7 +99,7 @@ protected function getSupportedToken($user = null, $secret = 'test')
9999
protected function getProvider($userChecker = null, $key = 'test')
100100
{
101101
if (null === $userChecker) {
102-
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
102+
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
103103
}
104104

105105
return new RememberMeAuthenticationProvider($userChecker, $key, 'foo');

Core/Tests/Authorization/Voter/VoterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class VoterTest extends \PHPUnit_Framework_TestCase
2121

2222
protected function setUp()
2323
{
24-
$this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
24+
$this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
2525
}
2626

2727
public function getTests()

Core/Tests/User/LdapUserProviderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
2424
*/
2525
public function testLoadUserByUsernameFailsIfCantConnectToLdap()
2626
{
27-
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
27+
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
2828
$ldap
2929
->expects($this->once())
3030
->method('bind')
@@ -40,7 +40,7 @@ public function testLoadUserByUsernameFailsIfCantConnectToLdap()
4040
*/
4141
public function testLoadUserByUsernameFailsIfNoLdapEntries()
4242
{
43-
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
43+
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
4444
$ldap
4545
->expects($this->once())
4646
->method('escape')
@@ -56,7 +56,7 @@ public function testLoadUserByUsernameFailsIfNoLdapEntries()
5656
*/
5757
public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
5858
{
59-
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
59+
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
6060
$ldap
6161
->expects($this->once())
6262
->method('escape')
@@ -78,7 +78,7 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
7878

7979
public function testSuccessfulLoadUserByUsername()
8080
{
81-
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
81+
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
8282
$ldap
8383
->expects($this->once())
8484
->method('escape')

Guard/Tests/Firewall/GuardAuthenticationListenerTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class GuardAuthenticationListenerTest extends \PHPUnit_Framework_TestCase
3131

3232
public function testHandleSuccess()
3333
{
34-
$authenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
35-
$authenticateToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
34+
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
35+
$authenticateToken = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
3636
$providerKey = 'my_firewall';
3737

3838
$credentials = array('username' => 'weaverryan', 'password' => 'all_your_base');
@@ -81,8 +81,8 @@ public function testHandleSuccess()
8181

8282
public function testHandleSuccessStopsAfterResponseIsSet()
8383
{
84-
$authenticator1 = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
85-
$authenticator2 = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
84+
$authenticator1 = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
85+
$authenticator2 = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
8686

8787
// mock the first authenticator to fail, and set a Response
8888
$authenticator1
@@ -111,8 +111,8 @@ public function testHandleSuccessStopsAfterResponseIsSet()
111111

112112
public function testHandleSuccessWithRememberMe()
113113
{
114-
$authenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
115-
$authenticateToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
114+
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
115+
$authenticateToken = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
116116
$providerKey = 'my_firewall_with_rememberme';
117117

118118
$authenticator
@@ -154,7 +154,7 @@ public function testHandleSuccessWithRememberMe()
154154

155155
public function testHandleCatchesAuthenticationException()
156156
{
157-
$authenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
157+
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
158158
$providerKey = 'my_firewall2';
159159

160160
$authException = new AuthenticationException('Get outta here crazy user with a bad password!');
@@ -186,8 +186,8 @@ public function testHandleCatchesAuthenticationException()
186186

187187
public function testReturnNullToSkipAuth()
188188
{
189-
$authenticatorA = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
190-
$authenticatorB = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
189+
$authenticatorA = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
190+
$authenticatorB = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
191191
$providerKey = 'my_firewall3';
192192

193193
$authenticatorA
@@ -240,8 +240,8 @@ protected function setUp()
240240
->method('getRequest')
241241
->will($this->returnValue($this->request));
242242

243-
$this->logger = $this->getMock('Psr\Log\LoggerInterface');
244-
$this->rememberMeServices = $this->getMock('Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface');
243+
$this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
244+
$this->rememberMeServices = $this->getMockBuilder('Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface')->getMock();
245245
}
246246

247247
protected function tearDown()

Guard/Tests/GuardAuthenticatorHandlerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ public function getTokenClearingTests()
123123

124124
protected function setUp()
125125
{
126-
$this->tokenStorage = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
127-
$this->dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
128-
$this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
126+
$this->tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
127+
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
128+
$this->token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
129129
$this->request = new Request(array(), array(), array(), array(), array(), array());
130-
$this->guardAuthenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
130+
$this->guardAuthenticator = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
131131
}
132132

133133
protected function tearDown()

Guard/Tests/Provider/GuardAuthenticationProviderTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public function testAuthenticate()
2727
{
2828
$providerKey = 'my_cool_firewall';
2929

30-
$authenticatorA = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
31-
$authenticatorB = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
32-
$authenticatorC = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
30+
$authenticatorA = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
31+
$authenticatorB = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
32+
$authenticatorC = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
3333
$authenticators = array($authenticatorA, $authenticatorB, $authenticatorC);
3434

3535
// called 2 times - for authenticator A and B (stops on B because of match)
@@ -52,7 +52,7 @@ public function testAuthenticate()
5252
$authenticatorC->expects($this->never())
5353
->method('getUser');
5454

55-
$mockedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
55+
$mockedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
5656
$authenticatorB->expects($this->once())
5757
->method('getUser')
5858
->with($enteredCredentials, $this->userProvider)
@@ -63,7 +63,7 @@ public function testAuthenticate()
6363
->with($enteredCredentials, $mockedUser)
6464
// authentication works!
6565
->will($this->returnValue(true));
66-
$authedToken = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
66+
$authedToken = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
6767
$authenticatorB->expects($this->once())
6868
->method('createAuthenticatedToken')
6969
->with($mockedUser, $providerKey)
@@ -89,7 +89,7 @@ public function testCheckCredentialsReturningNonTrueFailsAuthentication()
8989
{
9090
$providerKey = 'my_uncool_firewall';
9191

92-
$authenticator = $this->getMock('Symfony\Component\Security\Guard\GuardAuthenticatorInterface');
92+
$authenticator = $this->getMockBuilder('Symfony\Component\Security\Guard\GuardAuthenticatorInterface')->getMock();
9393

9494
// make sure the authenticator is used
9595
$this->preAuthenticationToken->expects($this->any())
@@ -101,7 +101,7 @@ public function testCheckCredentialsReturningNonTrueFailsAuthentication()
101101
->method('getCredentials')
102102
->will($this->returnValue('non-null-value'));
103103

104-
$mockedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
104+
$mockedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
105105
$authenticator->expects($this->once())
106106
->method('getUser')
107107
->will($this->returnValue($mockedUser));
@@ -124,7 +124,7 @@ public function testGuardWithNoLongerAuthenticatedTriggersLogout()
124124

125125
// create a token and mark it as NOT authenticated anymore
126126
// this mimics what would happen if a user "changed" between request
127-
$mockedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
127+
$mockedUser = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
128128
$token = new PostAuthenticationGuardToken($mockedUser, $providerKey, array('ROLE_USER'));
129129
$token->setAuthenticated(false);
130130

@@ -134,8 +134,8 @@ public function testGuardWithNoLongerAuthenticatedTriggersLogout()
134134

135135
protected function setUp()
136136
{
137-
$this->userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
138-
$this->userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
137+
$this->userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
138+
$this->userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
139139
$this->preAuthenticationToken = $this->getMockBuilder('Symfony\Component\Security\Guard\Token\PreAuthenticationGuardToken')
140140
->disableOriginalConstructor()
141141
->getMock();

0 commit comments

Comments
 (0)