Skip to content

Commit 67c8a1e

Browse files
committed
Fix deprecated phpunit annotation
1 parent b8c2c89 commit 67c8a1e

15 files changed

+90
-121
lines changed

Tests/Authentication/SimpleAuthenticationHandlerTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,10 @@ public function testOnAuthenticationSuccessCallsSimpleAuthenticator()
8181
$this->assertSame($this->response, $result);
8282
}
8383

84-
/**
85-
* @expectedException \UnexpectedValueException
86-
* @expectedExceptionMessage onAuthenticationSuccess method must return null to use the default success handler, or a Response object
87-
*/
8884
public function testOnAuthenticationSuccessThrowsAnExceptionIfNonResponseIsReturned()
8985
{
86+
$this->expectException('UnexpectedValueException');
87+
$this->expectExceptionMessage('onAuthenticationSuccess method must return null to use the default success handler, or a Response object');
9088
$this->successHandler->expects($this->never())
9189
->method('onAuthenticationSuccess');
9290

@@ -151,12 +149,10 @@ public function testOnAuthenticationFailureCallsSimpleAuthenticator()
151149
$this->assertSame($this->response, $result);
152150
}
153151

154-
/**
155-
* @expectedException \UnexpectedValueException
156-
* @expectedExceptionMessage onAuthenticationFailure method must return null to use the default failure handler, or a Response object
157-
*/
158152
public function testOnAuthenticationFailureThrowsAnExceptionIfNonResponseIsReturned()
159153
{
154+
$this->expectException('UnexpectedValueException');
155+
$this->expectExceptionMessage('onAuthenticationFailure method must return null to use the default failure handler, or a Response object');
160156
$this->failureHandler->expects($this->never())
161157
->method('onAuthenticationFailure');
162158

Tests/Firewall/AccessListenerTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
namespace Symfony\Component\Security\Http\Tests\Firewall;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Security\Http\Firewall\AccessListener;
1617

1718
class AccessListenerTest extends TestCase
1819
{
19-
/**
20-
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
21-
*/
20+
use ForwardCompatTestTrait;
21+
2222
public function testHandleWhenTheAccessDecisionManagerDecidesToRefuseAccess()
2323
{
24+
$this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
2425
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->disableOriginalConstructor()->disableOriginalClone()->getMock();
2526

2627
$accessMap = $this->getMockBuilder('Symfony\Component\Security\Http\AccessMapInterface')->getMock();
@@ -183,11 +184,9 @@ public function testHandleWhenThereIsNoAccessMapEntryMatchingTheRequest()
183184
$listener->handle($event);
184185
}
185186

186-
/**
187-
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException
188-
*/
189187
public function testHandleWhenTheSecurityTokenStorageHasNoToken()
190188
{
189+
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException');
191190
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
192191
$tokenStorage
193192
->expects($this->any())

Tests/Firewall/BasicAuthenticationListenerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Http\Tests\Firewall;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\Response;
1718
use Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager;
@@ -21,6 +22,8 @@
2122

2223
class BasicAuthenticationListenerTest extends TestCase
2324
{
25+
use ForwardCompatTestTrait;
26+
2427
public function testHandleWithValidUsernameAndPasswordServerParameters()
2528
{
2629
$request = new Request([], [], [], [], [], [
@@ -182,12 +185,10 @@ public function testHandleWithASimilarAuthenticatedToken()
182185
$listener->handle($event);
183186
}
184187

185-
/**
186-
* @expectedException \InvalidArgumentException
187-
* @expectedExceptionMessage $providerKey must not be empty
188-
*/
189188
public function testItRequiresProviderKey()
190189
{
190+
$this->expectException('InvalidArgumentException');
191+
$this->expectExceptionMessage('$providerKey must not be empty');
191192
new BasicAuthenticationListener(
192193
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(),
193194
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')->getMock(),

Tests/Firewall/ContextListenerTest.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Http\Tests\Firewall;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\EventDispatcher\EventDispatcher;
1617
use Symfony\Component\HttpFoundation\Request;
1718
use Symfony\Component\HttpFoundation\Response;
@@ -34,25 +35,23 @@
3435

3536
class ContextListenerTest extends TestCase
3637
{
37-
/**
38-
* @expectedException \InvalidArgumentException
39-
* @expectedExceptionMessage $contextKey must not be empty
40-
*/
38+
use ForwardCompatTestTrait;
39+
4140
public function testItRequiresContextKey()
4241
{
42+
$this->expectException('InvalidArgumentException');
43+
$this->expectExceptionMessage('$contextKey must not be empty');
4344
new ContextListener(
4445
$this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock(),
4546
[],
4647
''
4748
);
4849
}
4950

50-
/**
51-
* @expectedException \InvalidArgumentException
52-
* @expectedExceptionMessage User provider "stdClass" must implement "Symfony\Component\Security\Core\User\UserProviderInterface
53-
*/
5451
public function testUserProvidersNeedToImplementAnInterface()
5552
{
53+
$this->expectException('InvalidArgumentException');
54+
$this->expectExceptionMessage('User provider "stdClass" must implement "Symfony\Component\Security\Core\User\UserProviderInterface');
5655
$this->handleEventWithPreviousSession(new TokenStorage(), [new \stdClass()]);
5756
}
5857

@@ -308,11 +307,9 @@ public function testTokenIsSetToNullIfNoUserWasLoadedByTheRegisteredUserProvider
308307
$this->assertNull($tokenStorage->getToken());
309308
}
310309

311-
/**
312-
* @expectedException \RuntimeException
313-
*/
314310
public function testRuntimeExceptionIsThrownIfNoSupportingUserProviderWasRegistered()
315311
{
312+
$this->expectException('RuntimeException');
316313
$this->handleEventWithPreviousSession(new TokenStorage(), [new NotSupportingUserProvider(), new NotSupportingUserProvider()]);
317314
}
318315

Tests/Firewall/LogoutListenerTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
namespace Symfony\Component\Security\Http\Tests\Firewall;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\Response;
1718
use Symfony\Component\Security\Http\Firewall\LogoutListener;
1819

1920
class LogoutListenerTest extends TestCase
2021
{
22+
use ForwardCompatTestTrait;
23+
2124
public function testHandleUnmatchedPath()
2225
{
2326
list($listener, $tokenStorage, $httpUtils, $options) = $this->getListener();
@@ -122,11 +125,9 @@ public function testHandleMatchedPathWithoutSuccessHandlerAndCsrfValidation()
122125
$listener->handle($event);
123126
}
124127

125-
/**
126-
* @expectedException \RuntimeException
127-
*/
128128
public function testSuccessHandlerReturnsNonResponse()
129129
{
130+
$this->expectException('RuntimeException');
130131
$successHandler = $this->getSuccessHandler();
131132

132133
list($listener, $tokenStorage, $httpUtils, $options) = $this->getListener($successHandler);
@@ -146,11 +147,9 @@ public function testSuccessHandlerReturnsNonResponse()
146147
$listener->handle($event);
147148
}
148149

149-
/**
150-
* @expectedException \Symfony\Component\Security\Core\Exception\LogoutException
151-
*/
152150
public function testCsrfValidationFails()
153151
{
152+
$this->expectException('Symfony\Component\Security\Core\Exception\LogoutException');
154153
$tokenManager = $this->getTokenManager();
155154

156155
list($listener, $tokenStorage, $httpUtils, $options) = $this->getListener(null, $tokenManager);

Tests/Firewall/RememberMeListenerTest.php

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

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1718
use Symfony\Component\Security\Http\Firewall\RememberMeListener;
1819
use Symfony\Component\Security\Http\SecurityEvents;
1920

2021
class RememberMeListenerTest extends TestCase
2122
{
23+
use ForwardCompatTestTrait;
24+
2225
public function testOnCoreSecurityDoesNotTryToPopulateNonEmptyTokenStorage()
2326
{
2427
list($listener, $tokenStorage) = $this->getListener();
@@ -103,12 +106,10 @@ public function testOnCoreSecurityIgnoresAuthenticationExceptionThrownByAuthenti
103106
$listener->handle($event);
104107
}
105108

106-
/**
107-
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
108-
* @expectedExceptionMessage Authentication failed.
109-
*/
110109
public function testOnCoreSecurityIgnoresAuthenticationOptionallyRethrowsExceptionThrownAuthenticationManagerImplementation()
111110
{
111+
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationException');
112+
$this->expectExceptionMessage('Authentication failed.');
112113
list($listener, $tokenStorage, $service, $manager) = $this->getListener(false, false);
113114

114115
$tokenStorage

Tests/Firewall/RemoteUserAuthenticationListenerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
namespace Symfony\Component\Security\Http\Tests\Firewall;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\Security\Http\Firewall\RemoteUserAuthenticationListener;
1718

1819
class RemoteUserAuthenticationListenerTest extends TestCase
1920
{
21+
use ForwardCompatTestTrait;
22+
2023
public function testGetPreAuthenticatedData()
2124
{
2225
$serverVars = [
@@ -42,11 +45,9 @@ public function testGetPreAuthenticatedData()
4245
$this->assertSame($result, ['TheUser', null]);
4346
}
4447

45-
/**
46-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
47-
*/
4848
public function testGetPreAuthenticatedDataNoUser()
4949
{
50+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
5051
$request = new Request([], [], [], [], [], []);
5152

5253
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();

Tests/Firewall/SwitchUserListenerTest.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ private function doSetUp()
5050
$this->event = new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $this->request, HttpKernelInterface::MASTER_REQUEST);
5151
}
5252

53-
/**
54-
* @expectedException \InvalidArgumentException
55-
* @expectedExceptionMessage $providerKey must not be empty
56-
*/
5753
public function testProviderKeyIsRequired()
5854
{
55+
$this->expectException('InvalidArgumentException');
56+
$this->expectExceptionMessage('$providerKey must not be empty');
5957
new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, '', $this->accessDecisionManager);
6058
}
6159

@@ -68,22 +66,18 @@ public function testEventIsIgnoredIfUsernameIsNotPassedWithTheRequest()
6866
$this->assertNull($this->tokenStorage->getToken());
6967
}
7068

71-
/**
72-
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException
73-
*/
7469
public function testExitUserThrowsAuthenticationExceptionIfNoCurrentToken()
7570
{
71+
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException');
7672
$this->tokenStorage->setToken(null);
7773
$this->request->query->set('_switch_user', '_exit');
7874
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);
7975
$listener->handle($this->event);
8076
}
8177

82-
/**
83-
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException
84-
*/
8578
public function testExitUserThrowsAuthenticationExceptionIfOriginalTokenCannotBeFound()
8679
{
80+
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException');
8781
$token = new UsernamePasswordToken('username', '', 'key', ['ROLE_FOO']);
8882

8983
$this->tokenStorage->setToken($token);
@@ -158,11 +152,9 @@ public function testExitUserDoesNotDispatchEventWithStringUser()
158152
$listener->handle($this->event);
159153
}
160154

161-
/**
162-
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
163-
*/
164155
public function testSwitchUserIsDisallowed()
165156
{
157+
$this->expectException('Symfony\Component\Security\Core\Exception\AccessDeniedException');
166158
$token = new UsernamePasswordToken('username', '', 'key', ['ROLE_FOO']);
167159

168160
$this->tokenStorage->setToken($token);
@@ -270,11 +262,9 @@ public function testSwitchUserWithReplacedToken()
270262
$this->assertSame($replacedToken, $this->tokenStorage->getToken());
271263
}
272264

273-
/**
274-
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException
275-
*/
276265
public function testSwitchtUserThrowsAuthenticationExceptionIfNoCurrentToken()
277266
{
267+
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException');
278268
$this->tokenStorage->setToken(null);
279269
$this->request->query->set('_switch_user', 'username');
280270
$listener = new SwitchUserListener($this->tokenStorage, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager);

Tests/Firewall/UsernamePasswordFormAuthenticationListenerTest.php

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

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\HttpFoundation\Request;
1617
use Symfony\Component\HttpFoundation\Response;
1718
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
@@ -26,6 +27,8 @@
2627

2728
class UsernamePasswordFormAuthenticationListenerTest extends TestCase
2829
{
30+
use ForwardCompatTestTrait;
31+
2932
/**
3033
* @dataProvider getUsernameForLength
3134
*/
@@ -78,11 +81,11 @@ public function testHandleWhenUsernameLength($username, $ok)
7881

7982
/**
8083
* @dataProvider postOnlyDataProvider
81-
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
82-
* @expectedExceptionMessage The key "_username" must be a string, "array" given.
8384
*/
8485
public function testHandleNonStringUsernameWithArray($postOnly)
8586
{
87+
$this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
88+
$this->expectExceptionMessage('The key "_username" must be a string, "array" given.');
8689
$request = Request::create('/login_check', 'POST', ['_username' => []]);
8790
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
8891
$listener = new UsernamePasswordFormAuthenticationListener(
@@ -101,11 +104,11 @@ public function testHandleNonStringUsernameWithArray($postOnly)
101104

102105
/**
103106
* @dataProvider postOnlyDataProvider
104-
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
105-
* @expectedExceptionMessage The key "_username" must be a string, "integer" given.
106107
*/
107108
public function testHandleNonStringUsernameWithInt($postOnly)
108109
{
110+
$this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
111+
$this->expectExceptionMessage('The key "_username" must be a string, "integer" given.');
109112
$request = Request::create('/login_check', 'POST', ['_username' => 42]);
110113
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
111114
$listener = new UsernamePasswordFormAuthenticationListener(
@@ -124,11 +127,11 @@ public function testHandleNonStringUsernameWithInt($postOnly)
124127

125128
/**
126129
* @dataProvider postOnlyDataProvider
127-
* @expectedException \Symfony\Component\HttpKernel\Exception\BadRequestHttpException
128-
* @expectedExceptionMessage The key "_username" must be a string, "object" given.
129130
*/
130131
public function testHandleNonStringUsernameWithObject($postOnly)
131132
{
133+
$this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException');
134+
$this->expectExceptionMessage('The key "_username" must be a string, "object" given.');
132135
$request = Request::create('/login_check', 'POST', ['_username' => new \stdClass()]);
133136
$request->setSession($this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface')->getMock());
134137
$listener = new UsernamePasswordFormAuthenticationListener(

0 commit comments

Comments
 (0)