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

Commit b61218e

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: fixed obsolete getMock() usage [WebProfilerBundle] Display multiple HTTP headers in WDT
2 parents 8a7bf02 + 0582ad2 commit b61218e

File tree

52 files changed

+434
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+434
-434
lines changed

Core/Tests/Authentication/AuthenticationProviderManagerTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testAuthenticateWhenNoProviderSupportsToken()
4444
));
4545

4646
try {
47-
$manager->authenticate($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
47+
$manager->authenticate($token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
4848
$this->fail();
4949
} catch (ProviderNotFoundException $e) {
5050
$this->assertSame($token, $e->getToken());
@@ -58,7 +58,7 @@ public function testAuthenticateWhenProviderReturnsAccountStatusException()
5858
));
5959

6060
try {
61-
$manager->authenticate($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
61+
$manager->authenticate($token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
6262
$this->fail();
6363
} catch (AccountStatusException $e) {
6464
$this->assertSame($token, $e->getToken());
@@ -72,7 +72,7 @@ public function testAuthenticateWhenProviderReturnsAuthenticationException()
7272
));
7373

7474
try {
75-
$manager->authenticate($token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
75+
$manager->authenticate($token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
7676
$this->fail();
7777
} catch (AuthenticationException $e) {
7878
$this->assertSame($token, $e->getToken());
@@ -83,26 +83,26 @@ public function testAuthenticateWhenOneReturnsAuthenticationExceptionButNotAll()
8383
{
8484
$manager = new AuthenticationProviderManager(array(
8585
$this->getAuthenticationProvider(true, null, 'Symfony\Component\Security\Core\Exception\AuthenticationException'),
86-
$this->getAuthenticationProvider(true, $expected = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')),
86+
$this->getAuthenticationProvider(true, $expected = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()),
8787
));
8888

89-
$token = $manager->authenticate($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
89+
$token = $manager->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
9090
$this->assertSame($expected, $token);
9191
}
9292

9393
public function testAuthenticateReturnsTokenOfTheFirstMatchingProvider()
9494
{
95-
$second = $this->getMock('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface');
95+
$second = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface')->getMock();
9696
$second
9797
->expects($this->never())
9898
->method('supports')
9999
;
100100
$manager = new AuthenticationProviderManager(array(
101-
$this->getAuthenticationProvider(true, $expected = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')),
101+
$this->getAuthenticationProvider(true, $expected = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()),
102102
$second,
103103
));
104104

105-
$token = $manager->authenticate($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
105+
$token = $manager->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
106106
$this->assertSame($expected, $token);
107107
}
108108

@@ -112,20 +112,20 @@ public function testEraseCredentialFlag()
112112
$this->getAuthenticationProvider(true, $token = new UsernamePasswordToken('foo', 'bar', 'key')),
113113
));
114114

115-
$token = $manager->authenticate($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
115+
$token = $manager->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
116116
$this->assertEquals('', $token->getCredentials());
117117

118118
$manager = new AuthenticationProviderManager(array(
119119
$this->getAuthenticationProvider(true, $token = new UsernamePasswordToken('foo', 'bar', 'key')),
120120
), false);
121121

122-
$token = $manager->authenticate($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'));
122+
$token = $manager->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
123123
$this->assertEquals('bar', $token->getCredentials());
124124
}
125125

126126
protected function getAuthenticationProvider($supports, $token = null, $exception = null)
127127
{
128-
$provider = $this->getMock('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface');
128+
$provider = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface')->getMock();
129129
$provider->expects($this->once())
130130
->method('supports')
131131
->will($this->returnValue($supports))
@@ -139,7 +139,7 @@ protected function getAuthenticationProvider($supports, $token = null, $exceptio
139139
} elseif (null !== $exception) {
140140
$provider->expects($this->once())
141141
->method('authenticate')
142-
->will($this->throwException($this->getMock($exception, null, array(), '')))
142+
->will($this->throwException($this->getMockBuilder($exception)->setMethods(null)->getMock()))
143143
;
144144
}
145145

Core/Tests/Authentication/AuthenticationTrustResolverTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ public function testisFullFledged()
4747

4848
protected function getToken()
4949
{
50-
return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
50+
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
5151
}
5252

5353
protected function getAnonymousToken()
5454
{
55-
return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken', null, array('', ''));
55+
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken')->setConstructorArgs(array('', ''))->getMock();
5656
}
5757

5858
protected function getRememberMeToken()
5959
{
60-
return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken', array('setPersistent'), array(), '', false);
60+
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\RememberMeToken')->setMethods(array('setPersistent'))->disableOriginalConstructor()->getMock();
6161
}
6262

6363
protected function getResolver()

Core/Tests/Authentication/Provider/DaoAuthenticationProviderTest.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ public function testRetrieveUserWhenProviderDoesNotReturnAnUserInterface()
3434
*/
3535
public function testRetrieveUserWhenUsernameIsNotFound()
3636
{
37-
$userProvider = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
37+
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
3838
$userProvider->expects($this->once())
3939
->method('loadUserByUsername')
4040
->will($this->throwException(new UsernameNotFoundException()))
4141
;
4242

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

@@ -52,13 +52,13 @@ public function testRetrieveUserWhenUsernameIsNotFound()
5252
*/
5353
public function testRetrieveUserWhenAnExceptionOccurs()
5454
{
55-
$userProvider = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
55+
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
5656
$userProvider->expects($this->once())
5757
->method('loadUserByUsername')
5858
->will($this->throwException(new \RuntimeException()))
5959
;
6060

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

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

6868
public function testRetrieveUserReturnsUserFromTokenOnReauthentication()
6969
{
70-
$userProvider = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
70+
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
7171
$userProvider->expects($this->never())
7272
->method('loadUserByUsername')
7373
;
7474

75-
$user = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
75+
$user = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
7676
$token = $this->getSupportedToken();
7777
$token->expects($this->once())
7878
->method('getUser')
7979
->will($this->returnValue($user))
8080
;
8181

82-
$provider = new DaoAuthenticationProvider($userProvider, $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface'), 'key', $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface'));
82+
$provider = new DaoAuthenticationProvider($userProvider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface')->getMock(), 'key', $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface')->getMock());
8383
$reflection = new \ReflectionMethod($provider, 'retrieveUser');
8484
$reflection->setAccessible(true);
8585
$result = $reflection->invoke($provider, null, $token);
@@ -89,15 +89,15 @@ public function testRetrieveUserReturnsUserFromTokenOnReauthentication()
8989

9090
public function testRetrieveUser()
9191
{
92-
$user = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
92+
$user = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
9393

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

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

@@ -109,7 +109,7 @@ public function testRetrieveUser()
109109
*/
110110
public function testCheckAuthenticationWhenCredentialsAreEmpty()
111111
{
112-
$encoder = $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface');
112+
$encoder = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
113113
$encoder
114114
->expects($this->never())
115115
->method('isPasswordValid')
@@ -128,14 +128,14 @@ public function testCheckAuthenticationWhenCredentialsAreEmpty()
128128

129129
$method->invoke(
130130
$provider,
131-
$this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface'),
131+
$this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock(),
132132
$token
133133
);
134134
}
135135

136136
public function testCheckAuthenticationWhenCredentialsAre0()
137137
{
138-
$encoder = $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface');
138+
$encoder = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
139139
$encoder
140140
->expects($this->once())
141141
->method('isPasswordValid')
@@ -155,7 +155,7 @@ public function testCheckAuthenticationWhenCredentialsAre0()
155155

156156
$method->invoke(
157157
$provider,
158-
$this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface'),
158+
$this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock(),
159159
$token
160160
);
161161
}
@@ -165,7 +165,7 @@ public function testCheckAuthenticationWhenCredentialsAre0()
165165
*/
166166
public function testCheckAuthenticationWhenCredentialsAreNotValid()
167167
{
168-
$encoder = $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface');
168+
$encoder = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
169169
$encoder->expects($this->once())
170170
->method('isPasswordValid')
171171
->will($this->returnValue(false))
@@ -181,15 +181,15 @@ public function testCheckAuthenticationWhenCredentialsAreNotValid()
181181
->will($this->returnValue('foo'))
182182
;
183183

184-
$method->invoke($provider, $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface'), $token);
184+
$method->invoke($provider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock(), $token);
185185
}
186186

187187
/**
188188
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
189189
*/
190190
public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChanged()
191191
{
192-
$user = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
192+
$user = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
193193
$user->expects($this->once())
194194
->method('getPassword')
195195
->will($this->returnValue('foo'))
@@ -200,7 +200,7 @@ public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChang
200200
->method('getUser')
201201
->will($this->returnValue($user));
202202

203-
$dbUser = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
203+
$dbUser = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
204204
$dbUser->expects($this->once())
205205
->method('getPassword')
206206
->will($this->returnValue('newFoo'))
@@ -214,7 +214,7 @@ public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChang
214214

215215
public function testCheckAuthenticationWhenTokenNeedsReauthenticationWorksWithoutOriginalCredentials()
216216
{
217-
$user = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
217+
$user = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
218218
$user->expects($this->once())
219219
->method('getPassword')
220220
->will($this->returnValue('foo'))
@@ -225,7 +225,7 @@ public function testCheckAuthenticationWhenTokenNeedsReauthenticationWorksWithou
225225
->method('getUser')
226226
->will($this->returnValue($user));
227227

228-
$dbUser = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
228+
$dbUser = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
229229
$dbUser->expects($this->once())
230230
->method('getPassword')
231231
->will($this->returnValue('foo'))
@@ -239,7 +239,7 @@ public function testCheckAuthenticationWhenTokenNeedsReauthenticationWorksWithou
239239

240240
public function testCheckAuthentication()
241241
{
242-
$encoder = $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface');
242+
$encoder = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
243243
$encoder->expects($this->once())
244244
->method('isPasswordValid')
245245
->will($this->returnValue(true))
@@ -255,12 +255,12 @@ public function testCheckAuthentication()
255255
->will($this->returnValue('foo'))
256256
;
257257

258-
$method->invoke($provider, $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface'), $token);
258+
$method->invoke($provider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock(), $token);
259259
}
260260

261261
protected function getSupportedToken()
262262
{
263-
$mock = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken', array('getCredentials', 'getUser', 'getProviderKey'), array(), '', false);
263+
$mock = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken')->setMethods(array('getCredentials', 'getUser', 'getProviderKey'))->disableOriginalConstructor()->getMock();
264264
$mock
265265
->expects($this->any())
266266
->method('getProviderKey')
@@ -272,7 +272,7 @@ protected function getSupportedToken()
272272

273273
protected function getProvider($user = null, $userChecker = null, $passwordEncoder = null)
274274
{
275-
$userProvider = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface');
275+
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
276276
if (null !== $user) {
277277
$userProvider->expects($this->once())
278278
->method('loadUserByUsername')
@@ -281,14 +281,14 @@ protected function getProvider($user = null, $userChecker = null, $passwordEncod
281281
}
282282

283283
if (null === $userChecker) {
284-
$userChecker = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface');
284+
$userChecker = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserCheckerInterface')->getMock();
285285
}
286286

287287
if (null === $passwordEncoder) {
288288
$passwordEncoder = new PlaintextPasswordEncoder();
289289
}
290290

291-
$encoderFactory = $this->getMock('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface');
291+
$encoderFactory = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactoryInterface')->getMock();
292292
$encoderFactory
293293
->expects($this->any())
294294
->method('getEncoder')

0 commit comments

Comments
 (0)