Skip to content

Commit 39cfd50

Browse files
committed
Fix deprecated phpunit annotation
1 parent 46e0ecc commit 39cfd50

27 files changed

+143
-200
lines changed

Tests/Authentication/AuthenticationProviderManagerTest.php

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

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Security\Core\Authentication\AuthenticationProviderManager;
1617
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1718
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
@@ -24,19 +25,17 @@
2425

2526
class AuthenticationProviderManagerTest extends TestCase
2627
{
27-
/**
28-
* @expectedException \InvalidArgumentException
29-
*/
28+
use ForwardCompatTestTrait;
29+
3030
public function testAuthenticateWithoutProviders()
3131
{
32+
$this->expectException('InvalidArgumentException');
3233
new AuthenticationProviderManager([]);
3334
}
3435

35-
/**
36-
* @expectedException \InvalidArgumentException
37-
*/
3836
public function testAuthenticateWithProvidersWithIncorrectInterface()
3937
{
38+
$this->expectException('InvalidArgumentException');
4039
(new AuthenticationProviderManager([
4140
new \stdClass(),
4241
]))->authenticate($this->getMockBuilder(TokenInterface::class)->getMock());

Tests/Authentication/Provider/AnonymousAuthenticationProviderTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Security\Core\Authentication\Provider\AnonymousAuthenticationProvider;
1617

1718
class AnonymousAuthenticationProviderTest extends TestCase
1819
{
20+
use ForwardCompatTestTrait;
21+
1922
public function testSupports()
2023
{
2124
$provider = $this->getProvider('foo');
@@ -24,22 +27,18 @@ public function testSupports()
2427
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
2528
}
2629

27-
/**
28-
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
29-
* @expectedExceptionMessage The token is not supported by this authentication provider.
30-
*/
3130
public function testAuthenticateWhenTokenIsNotSupported()
3231
{
32+
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationException');
33+
$this->expectExceptionMessage('The token is not supported by this authentication provider.');
3334
$provider = $this->getProvider('foo');
3435

3536
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
3637
}
3738

38-
/**
39-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
40-
*/
4139
public function testAuthenticateWhenSecretIsNotValid()
4240
{
41+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
4342
$provider = $this->getProvider('foo');
4443

4544
$provider->authenticate($this->getSupportedToken('bar'));

Tests/Authentication/Provider/DaoAuthenticationProviderTest.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,28 @@
1212
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider;
1617
use Symfony\Component\Security\Core\Encoder\PlaintextPasswordEncoder;
1718
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
1819

1920
class DaoAuthenticationProviderTest extends TestCase
2021
{
21-
/**
22-
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationServiceException
23-
*/
22+
use ForwardCompatTestTrait;
23+
2424
public function testRetrieveUserWhenProviderDoesNotReturnAnUserInterface()
2525
{
26+
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationServiceException');
2627
$provider = $this->getProvider('fabien');
2728
$method = new \ReflectionMethod($provider, 'retrieveUser');
2829
$method->setAccessible(true);
2930

3031
$method->invoke($provider, 'fabien', $this->getSupportedToken());
3132
}
3233

33-
/**
34-
* @expectedException \Symfony\Component\Security\Core\Exception\UsernameNotFoundException
35-
*/
3634
public function testRetrieveUserWhenUsernameIsNotFound()
3735
{
36+
$this->expectException('Symfony\Component\Security\Core\Exception\UsernameNotFoundException');
3837
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
3938
$userProvider->expects($this->once())
4039
->method('loadUserByUsername')
@@ -48,11 +47,9 @@ public function testRetrieveUserWhenUsernameIsNotFound()
4847
$method->invoke($provider, 'fabien', $this->getSupportedToken());
4948
}
5049

51-
/**
52-
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationServiceException
53-
*/
5450
public function testRetrieveUserWhenAnExceptionOccurs()
5551
{
52+
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationServiceException');
5653
$userProvider = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserProviderInterface')->getMock();
5754
$userProvider->expects($this->once())
5855
->method('loadUserByUsername')
@@ -105,11 +102,9 @@ public function testRetrieveUser()
105102
$this->assertSame($user, $method->invoke($provider, 'fabien', $this->getSupportedToken()));
106103
}
107104

108-
/**
109-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
110-
*/
111105
public function testCheckAuthenticationWhenCredentialsAreEmpty()
112106
{
107+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
113108
$encoder = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
114109
$encoder
115110
->expects($this->never())
@@ -161,11 +156,9 @@ public function testCheckAuthenticationWhenCredentialsAre0()
161156
);
162157
}
163158

164-
/**
165-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
166-
*/
167159
public function testCheckAuthenticationWhenCredentialsAreNotValid()
168160
{
161+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
169162
$encoder = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface')->getMock();
170163
$encoder->expects($this->once())
171164
->method('isPasswordValid')
@@ -185,11 +178,9 @@ public function testCheckAuthenticationWhenCredentialsAreNotValid()
185178
$method->invoke($provider, $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock(), $token);
186179
}
187180

188-
/**
189-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
190-
*/
191181
public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChanged()
192182
{
183+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
193184
$user = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->getMock();
194185
$user->expects($this->once())
195186
->method('getPassword')

Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php

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

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Ldap\Adapter\CollectionInterface;
1617
use Symfony\Component\Ldap\Adapter\QueryInterface;
1718
use Symfony\Component\Ldap\Entry;
@@ -28,12 +29,12 @@
2829
*/
2930
class LdapBindAuthenticationProviderTest extends TestCase
3031
{
31-
/**
32-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
33-
* @expectedExceptionMessage The presented password must not be empty.
34-
*/
32+
use ForwardCompatTestTrait;
33+
3534
public function testEmptyPasswordShouldThrowAnException()
3635
{
36+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
37+
$this->expectExceptionMessage('The presented password must not be empty.');
3738
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
3839
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
3940
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
@@ -45,12 +46,10 @@ public function testEmptyPasswordShouldThrowAnException()
4546
$reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', '', 'key'));
4647
}
4748

48-
/**
49-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
50-
* @expectedExceptionMessage The presented password must not be empty.
51-
*/
5249
public function testNullPasswordShouldThrowAnException()
5350
{
51+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
52+
$this->expectExceptionMessage('The presented password must not be empty.');
5453
$userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')->getMock();
5554
$ldap = $this->getMockBuilder('Symfony\Component\Ldap\LdapInterface')->getMock();
5655
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
@@ -62,12 +61,10 @@ public function testNullPasswordShouldThrowAnException()
6261
$reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', null, 'key'));
6362
}
6463

65-
/**
66-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
67-
* @expectedExceptionMessage The presented password is invalid.
68-
*/
6964
public function testBindFailureShouldThrowAnException()
7065
{
66+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
67+
$this->expectExceptionMessage('The presented password is invalid.');
7168
$userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
7269
$ldap = $this->getMockBuilder(LdapInterface::class)->getMock();
7370
$ldap
@@ -139,12 +136,10 @@ public function testQueryForDn()
139136
$reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', 'bar', 'key'));
140137
}
141138

142-
/**
143-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
144-
* @expectedExceptionMessage The presented username is invalid.
145-
*/
146139
public function testEmptyQueryResultShouldThrowAnException()
147140
{
141+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
142+
$this->expectExceptionMessage('The presented username is invalid.');
148143
$userProvider = $this->getMockBuilder(UserProviderInterface::class)->getMock();
149144

150145
$collection = $this->getMockBuilder(CollectionInterface::class)->getMock();

Tests/Authentication/Provider/PreAuthenticatedAuthenticationProviderTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Security\Core\Authentication\Provider\PreAuthenticatedAuthenticationProvider;
1617
use Symfony\Component\Security\Core\Exception\LockedException;
1718

1819
class PreAuthenticatedAuthenticationProviderTest extends TestCase
1920
{
21+
use ForwardCompatTestTrait;
22+
2023
public function testSupports()
2124
{
2225
$provider = $this->getProvider();
@@ -36,22 +39,18 @@ public function testSupports()
3639
$this->assertFalse($provider->supports($token));
3740
}
3841

39-
/**
40-
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
41-
* @expectedExceptionMessage The token is not supported by this authentication provider.
42-
*/
4342
public function testAuthenticateWhenTokenIsNotSupported()
4443
{
44+
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationException');
45+
$this->expectExceptionMessage('The token is not supported by this authentication provider.');
4546
$provider = $this->getProvider();
4647

4748
$provider->authenticate($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock());
4849
}
4950

50-
/**
51-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
52-
*/
5351
public function testAuthenticateWhenNoUserIsSet()
5452
{
53+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
5554
$provider = $this->getProvider();
5655
$provider->authenticate($this->getSupportedToken(''));
5756
}
@@ -75,11 +74,9 @@ public function testAuthenticate()
7574
$this->assertSame($user, $token->getUser());
7675
}
7776

78-
/**
79-
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException
80-
*/
8177
public function testAuthenticateWhenUserCheckerThrowsException()
8278
{
79+
$this->expectException('Symfony\Component\Security\Core\Exception\LockedException');
8380
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
8481

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

Tests/Authentication/Provider/RememberMeAuthenticationProviderTest.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Security\Core\Authentication\Provider\RememberMeAuthenticationProvider;
1617
use Symfony\Component\Security\Core\Exception\DisabledException;
1718
use Symfony\Component\Security\Core\Role\Role;
1819

1920
class RememberMeAuthenticationProviderTest extends TestCase
2021
{
22+
use ForwardCompatTestTrait;
23+
2124
public function testSupports()
2225
{
2326
$provider = $this->getProvider();
@@ -26,34 +29,28 @@ public function testSupports()
2629
$this->assertFalse($provider->supports($this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock()));
2730
}
2831

29-
/**
30-
* @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException
31-
* @expectedExceptionMessage The token is not supported by this authentication provider.
32-
*/
3332
public function testAuthenticateWhenTokenIsNotSupported()
3433
{
34+
$this->expectException('Symfony\Component\Security\Core\Exception\AuthenticationException');
35+
$this->expectExceptionMessage('The token is not supported by this authentication provider.');
3536
$provider = $this->getProvider();
3637

3738
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
3839
$provider->authenticate($token);
3940
}
4041

41-
/**
42-
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
43-
*/
4442
public function testAuthenticateWhenSecretsDoNotMatch()
4543
{
44+
$this->expectException('Symfony\Component\Security\Core\Exception\BadCredentialsException');
4645
$provider = $this->getProvider(null, 'secret1');
4746
$token = $this->getSupportedToken(null, 'secret2');
4847

4948
$provider->authenticate($token);
5049
}
5150

52-
/**
53-
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
54-
*/
5551
public function testAuthenticateWhenPreChecksFails()
5652
{
53+
$this->expectException('Symfony\Component\Security\Core\Exception\DisabledException');
5754
$userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')->getMock();
5855
$userChecker->expects($this->once())
5956
->method('checkPreAuth')

Tests/Authentication/Provider/SimpleAuthenticationProviderTest.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212
namespace Symfony\Component\Security\Core\Tests\Authentication\Provider;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\Security\Core\Authentication\Provider\SimpleAuthenticationProvider;
1617
use Symfony\Component\Security\Core\Exception\DisabledException;
1718
use Symfony\Component\Security\Core\Exception\LockedException;
1819
use Symfony\Component\Security\Core\User\UserChecker;
1920

2021
class SimpleAuthenticationProviderTest extends TestCase
2122
{
22-
/**
23-
* @expectedException \Symfony\Component\Security\Core\Exception\DisabledException
24-
*/
23+
use ForwardCompatTestTrait;
24+
2525
public function testAuthenticateWhenPreChecksFails()
2626
{
27+
$this->expectException('Symfony\Component\Security\Core\Exception\DisabledException');
2728
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
2829

2930
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();
@@ -46,11 +47,9 @@ public function testAuthenticateWhenPreChecksFails()
4647
$provider->authenticate($token);
4748
}
4849

49-
/**
50-
* @expectedException \Symfony\Component\Security\Core\Exception\LockedException
51-
*/
5250
public function testAuthenticateWhenPostChecksFails()
5351
{
52+
$this->expectException('Symfony\Component\Security\Core\Exception\LockedException');
5453
$user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')->getMock();
5554

5655
$token = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\TokenInterface')->getMock();

0 commit comments

Comments
 (0)