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

Commit b668677

Browse files
committed
fixed obsolete getMock() usage
1 parent a57c258 commit b668677

File tree

8 files changed

+49
-49
lines changed

8 files changed

+49
-49
lines changed

Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class LdapBindAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
3030
*/
3131
public function testEmptyPasswordShouldThrowAnException()
3232
{
33-
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
34-
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
35-
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
33+
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
34+
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapClientInterface')->getMock();
35+
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
3636

3737
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
3838
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
@@ -47,14 +47,14 @@ public function testEmptyPasswordShouldThrowAnException()
4747
*/
4848
public function testBindFailureShouldThrowAnException()
4949
{
50-
$userProvider = $this->getMock(UserProviderInterface::class);
51-
$ldap = $this->getMock(LdapInterface::class);
50+
$userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
51+
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
5252
$ldap
5353
->expects($this->once())
5454
->method('bind')
5555
->will($this->throwException(new ConnectionException()))
5656
;
57-
$userChecker = $this->getMock(UserCheckerInterface::class);
57+
$userChecker = $this->getMockBuilder(UserCheckerInterface::class)->getMock();
5858

5959
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
6060
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
@@ -65,15 +65,15 @@ public function testBindFailureShouldThrowAnException()
6565

6666
public function testRetrieveUser()
6767
{
68-
$userProvider = $this->getMock(UserProviderInterface::class);
68+
$userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
6969
$userProvider
7070
->expects($this->once())
7171
->method('loadUserByUsername')
7272
->with('foo')
7373
;
74-
$ldap = $this->getMock(LdapInterface::class);
74+
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
7575

76-
$userChecker = $this->getMock(UserCheckerInterface::class);
76+
$userChecker = $this->getMockBuilder(UserCheckerInterface::class)->getMock();
7777

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

Core/Tests/Authorization/AccessDecisionManagerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testSetUnsupportedStrategy()
2929
*/
3030
public function testStrategies($strategy, $voters, $allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions, $expected)
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
$manager = new AccessDecisionManager($voters, $strategy, $allowIfAllAbstainDecisions, $allowIfEqualGrantedDeniedDecisions);
3434

3535
$this->assertSame($expected, $manager->decide($token, array('ROLE_FOO')));
@@ -47,7 +47,7 @@ public function testStrategiesWith2Roles($token, $strategy, $voter, $expected)
4747

4848
public function getStrategiesWith2RolesTests()
4949
{
50-
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
50+
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
5151

5252
return array(
5353
array($token, 'affirmative', $this->getVoter(VoterInterface::ACCESS_DENIED), false),
@@ -65,7 +65,7 @@ public function getStrategiesWith2RolesTests()
6565

6666
protected function getVoterFor2Roles($token, $vote1, $vote2)
6767
{
68-
$voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface');
68+
$voter = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface')->getMock();
6969
$voter->expects($this->any())
7070
->method('vote')
7171
->will($this->returnValueMap(array(
@@ -130,7 +130,7 @@ protected function getVoters($grants, $denies, $abstains)
130130

131131
protected function getVoter($vote)
132132
{
133-
$voter = $this->getMock('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface');
133+
$voter = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\Voter\VoterInterface')->getMock();
134134
$voter->expects($this->any())
135135
->method('vote')
136136
->will($this->returnValue($vote));

Core/Tests/Authorization/DebugAccessDecisionManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class DebugAccessDecisionManagerTest extends \PHPUnit_Framework_TestCase
2323
public function testDecideLog($expectedLog, $object)
2424
{
2525
$adm = new DebugAccessDecisionManager(new AccessDecisionManager());
26-
$adm->decide($this->getMock(TokenInterface::class), array('ATTRIBUTE_1'), $object);
26+
$adm->decide($this->getMockBuilder(TokenInterface::class)->getMock(), array('ATTRIBUTE_1'), $object);
2727

2828
$this->assertSame($expectedLog, $adm->getDecisionLog());
2929
}

Core/Tests/Authorization/Voter/ExpressionVoterTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function getToken(array $roles, $tokenExpectsGetRoles = true)
4545
foreach ($roles as $i => $role) {
4646
$roles[$i] = new Role($role);
4747
}
48-
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
48+
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
4949

5050
if ($tokenExpectsGetRoles) {
5151
$token->expects($this->once())
@@ -58,7 +58,7 @@ protected function getToken(array $roles, $tokenExpectsGetRoles = true)
5858

5959
protected function createExpressionLanguage($expressionLanguageExpectsEvaluate = true)
6060
{
61-
$mock = $this->getMock('Symfony\Component\Security\Core\Authorization\ExpressionLanguage');
61+
$mock = $this->getMockBuilder('Symfony\Component\Security\Core\Authorization\ExpressionLanguage')->getMock();
6262

6363
if ($expressionLanguageExpectsEvaluate) {
6464
$mock->expects($this->once())
@@ -71,12 +71,12 @@ protected function createExpressionLanguage($expressionLanguageExpectsEvaluate =
7171

7272
protected function createTrustResolver()
7373
{
74-
return $this->getMock('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface');
74+
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationTrustResolverInterface')->getMock();
7575
}
7676

7777
protected function createRoleHierarchy()
7878
{
79-
return $this->getMock('Symfony\Component\Security\Core\Role\RoleHierarchyInterface');
79+
return $this->getMockBuilder('Symfony\Component\Security\Core\Role\RoleHierarchyInterface')->getMock();
8080
}
8181

8282
protected function createExpression()

Core/Tests/User/LdapUserProviderTest.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class LdapUserProviderTest extends \PHPUnit_Framework_TestCase
2828
*/
2929
public function testLoadUserByUsernameFailsIfCantConnectToLdap()
3030
{
31-
$ldap = $this->getMock(LdapInterface::class);
31+
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
3232
$ldap
3333
->expects($this->once())
3434
->method('bind')
@@ -44,8 +44,8 @@ public function testLoadUserByUsernameFailsIfCantConnectToLdap()
4444
*/
4545
public function testLoadUserByUsernameFailsIfNoLdapEntries()
4646
{
47-
$result = $this->getMock(CollectionInterface::class);
48-
$query = $this->getMock(QueryInterface::class);
47+
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
48+
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
4949
$query
5050
->expects($this->once())
5151
->method('execute')
@@ -56,7 +56,7 @@ public function testLoadUserByUsernameFailsIfNoLdapEntries()
5656
->method('count')
5757
->will($this->returnValue(0))
5858
;
59-
$ldap = $this->getMock(LdapInterface::class);
59+
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
6060
$ldap
6161
->expects($this->once())
6262
->method('escape')
@@ -77,8 +77,8 @@ public function testLoadUserByUsernameFailsIfNoLdapEntries()
7777
*/
7878
public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
7979
{
80-
$result = $this->getMock(CollectionInterface::class);
81-
$query = $this->getMock(QueryInterface::class);
80+
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
81+
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
8282
$query
8383
->expects($this->once())
8484
->method('execute')
@@ -89,7 +89,7 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
8989
->method('count')
9090
->will($this->returnValue(2))
9191
;
92-
$ldap = $this->getMock(LdapInterface::class);
92+
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
9393
$ldap
9494
->expects($this->once())
9595
->method('escape')
@@ -110,14 +110,14 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapEntry()
110110
*/
111111
public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry()
112112
{
113-
$result = $this->getMock(CollectionInterface::class);
114-
$query = $this->getMock(QueryInterface::class);
113+
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
114+
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
115115
$query
116116
->expects($this->once())
117117
->method('execute')
118118
->will($this->returnValue($result))
119119
;
120-
$ldap = $this->getMock(LdapInterface::class);
120+
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
121121
$result
122122
->expects($this->once())
123123
->method('offsetGet')
@@ -156,14 +156,14 @@ public function testLoadUserByUsernameFailsIfMoreThanOneLdapPasswordsInEntry()
156156
*/
157157
public function testLoadUserByUsernameFailsIfEntryHasNoPasswordAttribute()
158158
{
159-
$result = $this->getMock(CollectionInterface::class);
160-
$query = $this->getMock(QueryInterface::class);
159+
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
160+
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
161161
$query
162162
->expects($this->once())
163163
->method('execute')
164164
->will($this->returnValue($result))
165165
;
166-
$ldap = $this->getMock(LdapInterface::class);
166+
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
167167
$result
168168
->expects($this->once())
169169
->method('offsetGet')
@@ -198,14 +198,14 @@ public function testLoadUserByUsernameFailsIfEntryHasNoPasswordAttribute()
198198

199199
public function testLoadUserByUsernameIsSuccessfulWithoutPasswordAttribute()
200200
{
201-
$result = $this->getMock(CollectionInterface::class);
202-
$query = $this->getMock(QueryInterface::class);
201+
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
202+
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
203203
$query
204204
->expects($this->once())
205205
->method('execute')
206206
->will($this->returnValue($result))
207207
;
208-
$ldap = $this->getMock(LdapInterface::class);
208+
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
209209
$result
210210
->expects($this->once())
211211
->method('offsetGet')
@@ -240,14 +240,14 @@ public function testLoadUserByUsernameIsSuccessfulWithoutPasswordAttribute()
240240

241241
public function testLoadUserByUsernameIsSuccessfulWithPasswordAttribute()
242242
{
243-
$result = $this->getMock(CollectionInterface::class);
244-
$query = $this->getMock(QueryInterface::class);
243+
$result = $this->getMockBuilder(CollectionInterface::class)->getMock();
244+
$query = $this->getMockBuilder(QueryInterface::class)->getMock();
245245
$query
246246
->expects($this->once())
247247
->method('execute')
248248
->will($this->returnValue($result))
249249
;
250-
$ldap = $this->getMock(LdapInterface::class);
250+
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
251251
$result
252252
->expects($this->once())
253253
->method('offsetGet')

Http/Tests/Firewall/ExceptionListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testExceptionWhenEntryPointReturnsBadValue()
6969
{
7070
$event = $this->createEvent(new AuthenticationException());
7171

72-
$entryPoint = $this->getMock('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface');
72+
$entryPoint = $this->getMockBuilder('Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface')->getMock();
7373
$entryPoint->expects($this->once())->method('start')->will($this->returnValue('NOT A RESPONSE'));
7474

7575
$listener = $this->createExceptionListener(null, null, null, $entryPoint);

Http/Tests/Session/SessionAuthenticationStrategyTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testUnsupportedStrategy()
3939

4040
public function testSessionIsMigrated()
4141
{
42-
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
42+
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock();
4343
$session->expects($this->once())->method('migrate')->with($this->equalTo(true));
4444

4545
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE);
@@ -48,7 +48,7 @@ public function testSessionIsMigrated()
4848

4949
public function testSessionIsInvalidated()
5050
{
51-
$session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
51+
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock();
5252
$session->expects($this->once())->method('invalidate');
5353

5454
$strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::INVALIDATE);
@@ -57,7 +57,7 @@ public function testSessionIsInvalidated()
5757

5858
private function getRequest($session = null)
5959
{
60-
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
60+
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
6161

6262
if (null !== $session) {
6363
$request->expects($this->any())->method('getSession')->will($this->returnValue($session));
@@ -68,6 +68,6 @@ private function getRequest($session = null)
6868

6969
private function getToken()
7070
{
71-
return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
71+
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
7272
}
7373
}

Tests/Http/Firewall/UsernamePasswordFormAuthenticationListenerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ class UsernamePasswordFormAuthenticationListenerTest extends \PHPUnit_Framework_
2424
public function testHandleWhenUsernameLength($username, $ok)
2525
{
2626
$request = Request::create('/login_check', 'POST', array('_username' => $username));
27-
$request->setSession($this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface'));
27+
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
2828

29-
$httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
29+
$httpUtils = $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')->getMock();
3030
$httpUtils
3131
->expects($this->any())
3232
->method('checkRequestPath')
3333
->will($this->returnValue(true))
3434
;
3535

36-
$failureHandler = $this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface');
36+
$failureHandler = $this->getMockBuilder('Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface')->getMock();
3737
$failureHandler
3838
->expects($ok ? $this->never() : $this->once())
3939
->method('onAuthenticationFailure')
@@ -48,17 +48,17 @@ public function testHandleWhenUsernameLength($username, $ok)
4848
;
4949

5050
$listener = new UsernamePasswordFormAuthenticationListener(
51-
$this->getMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface'),
51+
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(),
5252
$authenticationManager,
53-
$this->getMock('Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface'),
53+
$this->getMockBuilder('Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface')->getMock(),
5454
$httpUtils,
5555
'TheProviderKey',
56-
$this->getMock('Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface'),
56+
$this->getMockBuilder('Symfony\Component\Security\Http\Authentication\AuthenticationSuccessHandlerInterface')->getMock(),
5757
$failureHandler,
5858
array('require_previous_session' => false)
5959
);
6060

61-
$event = $this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false);
61+
$event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')->disableOriginalConstructor()->getMock();
6262
$event
6363
->expects($this->any())
6464
->method('getRequest')

0 commit comments

Comments
 (0)