12
12
namespace Symfony \Component \Security \Http \Tests \Authentication ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \HttpFoundation \Request ;
15
16
use Symfony \Component \HttpFoundation \Response ;
16
17
use Symfony \Component \Security \Core \Authentication \SimpleAuthenticatorInterface ;
18
+ use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
17
19
use Symfony \Component \Security \Core \Exception \AuthenticationException ;
18
20
use Symfony \Component \Security \Http \Authentication \AuthenticationFailureHandlerInterface ;
19
21
use Symfony \Component \Security \Http \Authentication \AuthenticationSuccessHandlerInterface ;
@@ -38,11 +40,11 @@ class SimpleAuthenticationHandlerTest extends TestCase
38
40
39
41
protected function setUp (): void
40
42
{
41
- $ this ->successHandler = $ this ->getMockBuilder (AuthenticationSuccessHandlerInterface::class)-> getMock ( );
42
- $ this ->failureHandler = $ this ->getMockBuilder (AuthenticationFailureHandlerInterface::class)-> getMock ( );
43
+ $ this ->successHandler = $ this ->createMock (AuthenticationSuccessHandlerInterface::class);
44
+ $ this ->failureHandler = $ this ->createMock (AuthenticationFailureHandlerInterface::class);
43
45
44
- $ this ->request = $ this ->getMockBuilder (\ Symfony \ Component \ HttpFoundation \ Request::class)-> getMock ( );
45
- $ this ->token = $ this ->getMockBuilder (\ Symfony \ Component \ Security \ Core \ Authentication \ Token \ TokenInterface::class)-> getMock ( );
46
+ $ this ->request = $ this ->createMock ( Request::class);
47
+ $ this ->token = $ this ->createMock ( TokenInterface::class);
46
48
// No methods are invoked on the exception; we just assert on its class
47
49
$ this ->authenticationException = new AuthenticationException ();
48
50
@@ -51,7 +53,7 @@ protected function setUp(): void
51
53
52
54
public function testOnAuthenticationSuccessFallsBackToDefaultHandlerIfSimpleIsNotASuccessHandler ()
53
55
{
54
- $ authenticator = $ this ->getMockBuilder (SimpleAuthenticatorInterface::class)-> getMock ( );
56
+ $ authenticator = $ this ->createMock (SimpleAuthenticatorInterface::class);
55
57
56
58
$ this ->successHandler ->expects ($ this ->once ())
57
59
->method ('onAuthenticationSuccess ' )
@@ -69,7 +71,7 @@ public function testOnAuthenticationSuccessCallsSimpleAuthenticator()
69
71
$ this ->successHandler ->expects ($ this ->never ())
70
72
->method ('onAuthenticationSuccess ' );
71
73
72
- $ authenticator = $ this ->getMockForAbstractClass (\ Symfony \ Component \ Security \ Http \ Tests \ Authentication \ TestSuccessHandlerInterface::class);
74
+ $ authenticator = $ this ->getMockForAbstractClass (TestSuccessHandlerInterface::class);
73
75
$ authenticator ->expects ($ this ->once ())
74
76
->method ('onAuthenticationSuccess ' )
75
77
->with ($ this ->request , $ this ->token )
@@ -88,7 +90,7 @@ public function testOnAuthenticationSuccessThrowsAnExceptionIfNonResponseIsRetur
88
90
$ this ->successHandler ->expects ($ this ->never ())
89
91
->method ('onAuthenticationSuccess ' );
90
92
91
- $ authenticator = $ this ->getMockForAbstractClass (\ Symfony \ Component \ Security \ Http \ Tests \ Authentication \ TestSuccessHandlerInterface::class);
93
+ $ authenticator = $ this ->getMockForAbstractClass (TestSuccessHandlerInterface::class);
92
94
$ authenticator ->expects ($ this ->once ())
93
95
->method ('onAuthenticationSuccess ' )
94
96
->with ($ this ->request , $ this ->token )
@@ -105,7 +107,7 @@ public function testOnAuthenticationSuccessFallsBackToDefaultHandlerIfNullIsRetu
105
107
->with ($ this ->request , $ this ->token )
106
108
->willReturn ($ this ->response );
107
109
108
- $ authenticator = $ this ->getMockForAbstractClass (\ Symfony \ Component \ Security \ Http \ Tests \ Authentication \ TestSuccessHandlerInterface::class);
110
+ $ authenticator = $ this ->getMockForAbstractClass (TestSuccessHandlerInterface::class);
109
111
$ authenticator ->expects ($ this ->once ())
110
112
->method ('onAuthenticationSuccess ' )
111
113
->with ($ this ->request , $ this ->token )
@@ -119,7 +121,7 @@ public function testOnAuthenticationSuccessFallsBackToDefaultHandlerIfNullIsRetu
119
121
120
122
public function testOnAuthenticationFailureFallsBackToDefaultHandlerIfSimpleIsNotAFailureHandler ()
121
123
{
122
- $ authenticator = $ this ->getMockBuilder (SimpleAuthenticatorInterface::class)-> getMock ( );
124
+ $ authenticator = $ this ->createMock (SimpleAuthenticatorInterface::class);
123
125
124
126
$ this ->failureHandler ->expects ($ this ->once ())
125
127
->method ('onAuthenticationFailure ' )
@@ -137,7 +139,7 @@ public function testOnAuthenticationFailureCallsSimpleAuthenticator()
137
139
$ this ->failureHandler ->expects ($ this ->never ())
138
140
->method ('onAuthenticationFailure ' );
139
141
140
- $ authenticator = $ this ->getMockForAbstractClass (\ Symfony \ Component \ Security \ Http \ Tests \ Authentication \ TestFailureHandlerInterface::class);
142
+ $ authenticator = $ this ->getMockForAbstractClass (TestFailureHandlerInterface::class);
141
143
$ authenticator ->expects ($ this ->once ())
142
144
->method ('onAuthenticationFailure ' )
143
145
->with ($ this ->request , $ this ->authenticationException )
@@ -156,7 +158,7 @@ public function testOnAuthenticationFailureThrowsAnExceptionIfNonResponseIsRetur
156
158
$ this ->failureHandler ->expects ($ this ->never ())
157
159
->method ('onAuthenticationFailure ' );
158
160
159
- $ authenticator = $ this ->getMockForAbstractClass (\ Symfony \ Component \ Security \ Http \ Tests \ Authentication \ TestFailureHandlerInterface::class);
161
+ $ authenticator = $ this ->getMockForAbstractClass (TestFailureHandlerInterface::class);
160
162
$ authenticator ->expects ($ this ->once ())
161
163
->method ('onAuthenticationFailure ' )
162
164
->with ($ this ->request , $ this ->authenticationException )
@@ -173,7 +175,7 @@ public function testOnAuthenticationFailureFallsBackToDefaultHandlerIfNullIsRetu
173
175
->with ($ this ->request , $ this ->authenticationException )
174
176
->willReturn ($ this ->response );
175
177
176
- $ authenticator = $ this ->getMockForAbstractClass (\ Symfony \ Component \ Security \ Http \ Tests \ Authentication \ TestFailureHandlerInterface::class);
178
+ $ authenticator = $ this ->getMockForAbstractClass (TestFailureHandlerInterface::class);
177
179
$ authenticator ->expects ($ this ->once ())
178
180
->method ('onAuthenticationFailure ' )
179
181
->with ($ this ->request , $ this ->authenticationException )
0 commit comments