Skip to content

Commit c25a04f

Browse files
committed
Use ::class keyword when possible
1 parent d148fe2 commit c25a04f

File tree

6 files changed

+55
-51
lines changed

6 files changed

+55
-51
lines changed

Tests/EventListener/SessionStrategyListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private function createEvent($providerKey)
6767

6868
private function configurePreviousSession()
6969
{
70-
$session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock();
70+
$session = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock();
7171
$session->expects($this->any())
7272
->method('getName')
7373
->willReturn('test_session_name');

Tests/Firewall/AccessListenerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ public function testHandleWhenTheSecurityTokenStorageHasNoTokenAndExceptionOnTok
247247

248248
$listener = new AccessListener(
249249
$tokenStorage,
250-
$this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock(),
250+
$this->getMockBuilder(AccessDecisionManagerInterface::class)->getMock(),
251251
$accessMap,
252-
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
252+
$this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(),
253253
false
254254
);
255255

@@ -270,9 +270,9 @@ public function testHandleWhenPublicAccessIsAllowedAndExceptionOnTokenIsFalse()
270270

271271
$listener = new AccessListener(
272272
$tokenStorage,
273-
$this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock(),
273+
$this->getMockBuilder(AccessDecisionManagerInterface::class)->getMock(),
274274
$accessMap,
275-
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
275+
$this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(),
276276
false
277277
);
278278

@@ -297,9 +297,9 @@ public function testHandleWhenPublicAccessWhileAuthenticated()
297297

298298
$listener = new AccessListener(
299299
$tokenStorage,
300-
$this->getMockBuilder('Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface')->getMock(),
300+
$this->getMockBuilder(AccessDecisionManagerInterface::class)->getMock(),
301301
$accessMap,
302-
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
302+
$this->getMockBuilder(AuthenticationManagerInterface::class)->getMock(),
303303
false
304304
);
305305

Tests/Firewall/LogoutListenerTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function testHandleMatchedPathWithoutCsrfValidation()
121121

122122
public function testNoResponseSet()
123123
{
124-
$this->expectException('RuntimeException');
124+
$this->expectException(\RuntimeException::class);
125125

126126
[$listener, , $httpUtils, $options] = $this->getListener();
127127

@@ -137,7 +137,7 @@ public function testNoResponseSet()
137137

138138
public function testCsrfValidationFails()
139139
{
140-
$this->expectException('Symfony\Component\Security\Core\Exception\LogoutException');
140+
$this->expectException(\Symfony\Component\Security\Core\Exception\LogoutException::class);
141141
$tokenManager = $this->getTokenManager();
142142

143143
[$listener, , $httpUtils, $options] = $this->getListener(null, $tokenManager);
@@ -194,12 +194,12 @@ public function testLegacyLogoutHandlers()
194194

195195
private function getTokenManager()
196196
{
197-
return $this->getMockBuilder('Symfony\Component\Security\Csrf\CsrfTokenManagerInterface')->getMock();
197+
return $this->getMockBuilder(\Symfony\Component\Security\Csrf\CsrfTokenManagerInterface::class)->getMock();
198198
}
199199

200200
private function getTokenStorage()
201201
{
202-
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
202+
return $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock();
203203
}
204204

205205
private function getGetResponseEvent()
@@ -217,7 +217,7 @@ private function getGetResponseEvent()
217217

218218
private function getHttpUtils()
219219
{
220-
return $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')
220+
return $this->getMockBuilder(\Symfony\Component\Security\Http\HttpUtils::class)
221221
->disableOriginalConstructor()
222222
->getMock();
223223
}
@@ -247,6 +247,6 @@ private function getEventDispatcher()
247247

248248
private function getToken()
249249
{
250-
return $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
250+
return $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\TokenInterface::class)->getMock();
251251
}
252252
}

Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class UsernamePasswordFormAuthenticationListenerTest extends TestCase
3333
public function testHandleWhenUsernameLength($username, $ok)
3434
{
3535
$request = Request::create('/login_check', 'POST', ['_username' => $username]);
36-
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
36+
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
3737

38-
$httpUtils = $this->getMockBuilder('Symfony\Component\Security\Http\HttpUtils')->getMock();
38+
$httpUtils = $this->getMockBuilder(HttpUtils::class)->getMock();
3939
$httpUtils
4040
->expects($this->any())
4141
->method('checkRequestPath')
@@ -46,24 +46,24 @@ public function testHandleWhenUsernameLength($username, $ok)
4646
->willReturn(new RedirectResponse('/hello'))
4747
;
4848

49-
$failureHandler = $this->getMockBuilder('Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface')->getMock();
49+
$failureHandler = $this->getMockBuilder(\Symfony\Component\Security\Http\Authentication\AuthenticationFailureHandlerInterface::class)->getMock();
5050
$failureHandler
5151
->expects($ok ? $this->never() : $this->once())
5252
->method('onAuthenticationFailure')
5353
->willReturn(new Response())
5454
;
5555

56-
$authenticationManager = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager')->disableOriginalConstructor()->getMock();
56+
$authenticationManager = $this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager::class)->disableOriginalConstructor()->getMock();
5757
$authenticationManager
5858
->expects($ok ? $this->once() : $this->never())
5959
->method('authenticate')
6060
->willReturnArgument(0)
6161
;
6262

6363
$listener = new UsernamePasswordFormAuthenticationListener(
64-
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(),
64+
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface::class)->getMock(),
6565
$authenticationManager,
66-
$this->getMockBuilder('Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface')->getMock(),
66+
$this->getMockBuilder(\Symfony\Component\Security\Http\Session\SessionAuthenticationStrategyInterface::class)->getMock(),
6767
$httpUtils,
6868
'TheProviderKey',
6969
new DefaultAuthenticationSuccessHandler($httpUtils),
@@ -86,18 +86,18 @@ public function testHandleWhenUsernameLength($username, $ok)
8686
*/
8787
public function testHandleNonStringUsernameWithArray($postOnly)
8888
{
89-
$this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
89+
$this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class);
9090
$this->expectExceptionMessage('The key "_username" must be a string, "array" given.');
9191
$request = Request::create('/login_check', 'POST', ['_username' => []]);
92-
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
92+
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
9393
$listener = new UsernamePasswordFormAuthenticationListener(
9494
new TokenStorage(),
95-
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
95+
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface::class)->getMock(),
9696
new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE),
9797
$httpUtils = new HttpUtils(),
9898
'foo',
9999
new DefaultAuthenticationSuccessHandler($httpUtils),
100-
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
100+
new DefaultAuthenticationFailureHandler($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $httpUtils),
101101
['require_previous_session' => false, 'post_only' => $postOnly]
102102
);
103103
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
@@ -109,18 +109,18 @@ public function testHandleNonStringUsernameWithArray($postOnly)
109109
*/
110110
public function testHandleNonStringUsernameWithInt($postOnly)
111111
{
112-
$this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
112+
$this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class);
113113
$this->expectExceptionMessage('The key "_username" must be a string, "int" given.');
114114
$request = Request::create('/login_check', 'POST', ['_username' => 42]);
115-
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
115+
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
116116
$listener = new UsernamePasswordFormAuthenticationListener(
117117
new TokenStorage(),
118-
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
118+
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface::class)->getMock(),
119119
new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE),
120120
$httpUtils = new HttpUtils(),
121121
'foo',
122122
new DefaultAuthenticationSuccessHandler($httpUtils),
123-
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
123+
new DefaultAuthenticationFailureHandler($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $httpUtils),
124124
['require_previous_session' => false, 'post_only' => $postOnly]
125125
);
126126
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
@@ -132,18 +132,18 @@ public function testHandleNonStringUsernameWithInt($postOnly)
132132
*/
133133
public function testHandleNonStringUsernameWithObject($postOnly)
134134
{
135-
$this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
135+
$this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class);
136136
$this->expectExceptionMessage('The key "_username" must be a string, "stdClass" given.');
137137
$request = Request::create('/login_check', 'POST', ['_username' => new \stdClass()]);
138-
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
138+
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
139139
$listener = new UsernamePasswordFormAuthenticationListener(
140140
new TokenStorage(),
141-
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
141+
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface::class)->getMock(),
142142
new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE),
143143
$httpUtils = new HttpUtils(),
144144
'foo',
145145
new DefaultAuthenticationSuccessHandler($httpUtils),
146-
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
146+
new DefaultAuthenticationFailureHandler($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $httpUtils),
147147
['require_previous_session' => false, 'post_only' => $postOnly]
148148
);
149149
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
@@ -162,15 +162,15 @@ public function testHandleNonStringUsernameWith__toString($postOnly)
162162
->willReturn('someUsername');
163163

164164
$request = Request::create('/login_check', 'POST', ['_username' => $usernameClass]);
165-
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
165+
$request->setSession($this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\SessionInterface::class)->getMock());
166166
$listener = new UsernamePasswordFormAuthenticationListener(
167167
new TokenStorage(),
168-
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),
168+
$this->getMockBuilder(\Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface::class)->getMock(),
169169
new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE),
170170
$httpUtils = new HttpUtils(),
171171
'foo',
172172
new DefaultAuthenticationSuccessHandler($httpUtils),
173-
new DefaultAuthenticationFailureHandler($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $httpUtils),
173+
new DefaultAuthenticationFailureHandler($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $httpUtils),
174174
['require_previous_session' => false, 'post_only' => $postOnly]
175175
);
176176
$event = new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);

Tests/FirewallTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@
1212
namespace Symfony\Component\Security\Http\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
16+
use Symfony\Component\HttpFoundation\Request;
1517
use Symfony\Component\HttpKernel\Event\RequestEvent;
1618
use Symfony\Component\HttpKernel\HttpKernelInterface;
1719
use Symfony\Component\Security\Http\Firewall;
20+
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
21+
use Symfony\Component\Security\Http\FirewallMapInterface;
1822

1923
class FirewallTest extends TestCase
2024
{

0 commit comments

Comments
 (0)