@@ -35,13 +35,13 @@ public function testRetrieveUserWhenProviderDoesNotReturnAnUserInterface()
35
35
*/
36
36
public function testRetrieveUserWhenUsernameIsNotFound ()
37
37
{
38
- $ userProvider = $ this ->getMock ('Symfony\Component\Security\Core\User\UserProviderInterface ' );
38
+ $ userProvider = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserProviderInterface ' );
39
39
$ userProvider ->expects ($ this ->once ())
40
40
->method ('loadUserByUsername ' )
41
- ->will ($ this ->throwException ($ this ->getMock ('Symfony\Component\Security\Core\Exception\UsernameNotFoundException ' , null , array (), '' , false )))
41
+ ->will ($ this ->throwException ($ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ Exception \ \UsernameNotFoundException ' , null , array (), '' , false )))
42
42
;
43
43
44
- $ provider = new DaoAuthenticationProvider ($ userProvider , $ this ->getMock ('Symfony\Component\Security\Core\User\UserCheckerInterface ' ), 'key ' , $ this ->getMock ('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface ' ));
44
+ $ provider = new DaoAuthenticationProvider ($ userProvider , $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \\ UserCheckerInterface ' ), 'key ' , $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ Encoder \ \EncoderFactoryInterface ' ));
45
45
$ method = new \ReflectionMethod ($ provider , 'retrieveUser ' );
46
46
$ method ->setAccessible (true );
47
47
@@ -53,13 +53,13 @@ public function testRetrieveUserWhenUsernameIsNotFound()
53
53
*/
54
54
public function testRetrieveUserWhenAnExceptionOccurs ()
55
55
{
56
- $ userProvider = $ this ->getMock ('Symfony\Component\Security\Core\User\UserProviderInterface ' );
56
+ $ userProvider = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserProviderInterface ' );
57
57
$ userProvider ->expects ($ this ->once ())
58
58
->method ('loadUserByUsername ' )
59
59
->will ($ this ->throwException ($ this ->getMock ('RuntimeException ' , null , array (), '' , false )))
60
60
;
61
61
62
- $ provider = new DaoAuthenticationProvider ($ userProvider , $ this ->getMock ('Symfony\Component\Security\Core\User\UserCheckerInterface ' ), 'key ' , $ this ->getMock ('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface ' ));
62
+ $ provider = new DaoAuthenticationProvider ($ userProvider , $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \\ UserCheckerInterface ' ), 'key ' , $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ Encoder \ \EncoderFactoryInterface ' ));
63
63
$ method = new \ReflectionMethod ($ provider , 'retrieveUser ' );
64
64
$ method ->setAccessible (true );
65
65
@@ -68,19 +68,19 @@ public function testRetrieveUserWhenAnExceptionOccurs()
68
68
69
69
public function testRetrieveUserReturnsUserFromTokenOnReauthentication ()
70
70
{
71
- $ userProvider = $ this ->getMock ('Symfony\Component\Security\Core\User\UserProviderInterface ' );
71
+ $ userProvider = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserProviderInterface ' );
72
72
$ userProvider ->expects ($ this ->never ())
73
73
->method ('loadUserByUsername ' )
74
74
;
75
75
76
- $ user = $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' );
76
+ $ user = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserInterface ' );
77
77
$ token = $ this ->getSupportedToken ();
78
78
$ token ->expects ($ this ->once ())
79
79
->method ('getUser ' )
80
80
->will ($ this ->returnValue ($ user ))
81
81
;
82
82
83
- $ provider = new DaoAuthenticationProvider ($ userProvider , $ this ->getMock ('Symfony\Component\Security\Core\User\UserCheckerInterface ' ), 'key ' , $ this ->getMock ('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface ' ));
83
+ $ provider = new DaoAuthenticationProvider ($ userProvider , $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \\ UserCheckerInterface ' ), 'key ' , $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ Encoder \ \EncoderFactoryInterface ' ));
84
84
$ reflection = new \ReflectionMethod ($ provider , 'retrieveUser ' );
85
85
$ reflection ->setAccessible (true );
86
86
$ result = $ reflection ->invoke ($ provider , null , $ token );
@@ -90,15 +90,15 @@ public function testRetrieveUserReturnsUserFromTokenOnReauthentication()
90
90
91
91
public function testRetrieveUser ()
92
92
{
93
- $ user = $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' );
93
+ $ user = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserInterface ' );
94
94
95
- $ userProvider = $ this ->getMock ('Symfony\Component\Security\Core\User\UserProviderInterface ' );
95
+ $ userProvider = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserProviderInterface ' );
96
96
$ userProvider ->expects ($ this ->once ())
97
97
->method ('loadUserByUsername ' )
98
98
->will ($ this ->returnValue ($ user ))
99
99
;
100
100
101
- $ provider = new DaoAuthenticationProvider ($ userProvider , $ this ->getMock ('Symfony\Component\Security\Core\User\UserCheckerInterface ' ), 'key ' , $ this ->getMock ('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface ' ));
101
+ $ provider = new DaoAuthenticationProvider ($ userProvider , $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \\ UserCheckerInterface ' ), 'key ' , $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ Encoder \ \EncoderFactoryInterface ' ));
102
102
$ method = new \ReflectionMethod ($ provider , 'retrieveUser ' );
103
103
$ method ->setAccessible (true );
104
104
@@ -110,25 +110,63 @@ public function testRetrieveUser()
110
110
*/
111
111
public function testCheckAuthenticationWhenCredentialsAreEmpty ()
112
112
{
113
- $ provider = $ this ->getProvider ();
113
+ $ encoder = $ this ->getMock ('Symfony \\Component \\Security \\Core \\Encoder \\PasswordEncoderInterface ' );
114
+ $ encoder
115
+ ->expects ($ this ->never ())
116
+ ->method ('isPasswordValid ' )
117
+ ;
118
+
119
+ $ provider = $ this ->getProvider (false , false , $ encoder );
114
120
$ method = new \ReflectionMethod ($ provider , 'checkAuthentication ' );
115
121
$ method ->setAccessible (true );
116
122
117
123
$ token = $ this ->getSupportedToken ();
118
- $ token ->expects ($ this ->once ())
119
- ->method ('getCredentials ' )
120
- ->will ($ this ->returnValue ('' ))
124
+ $ token
125
+ ->expects ($ this ->once ())
126
+ ->method ('getCredentials ' )
127
+ ->will ($ this ->returnValue ('' ))
128
+ ;
129
+
130
+ $ method ->invoke (
131
+ $ provider ,
132
+ $ this ->getMock ('Symfony \\Component \\Security \\Core \\User \\UserInterface ' ),
133
+ $ token
134
+ );
135
+ }
136
+
137
+ public function testCheckAuthenticationWhenCredentialsAre0 ()
138
+ {
139
+ $ encoder = $ this ->getMock ('Symfony \\Component \\Security \\Core \\Encoder \\PasswordEncoderInterface ' );
140
+ $ encoder
141
+ ->expects ($ this ->once ())
142
+ ->method ('isPasswordValid ' )
143
+ ->will ($ this ->returnValue (true ))
144
+ ;
145
+
146
+ $ provider = $ this ->getProvider (false , false , $ encoder );
147
+ $ method = new \ReflectionMethod ($ provider , 'checkAuthentication ' );
148
+ $ method ->setAccessible (true );
149
+
150
+ $ token = $ this ->getSupportedToken ();
151
+ $ token
152
+ ->expects ($ this ->once ())
153
+ ->method ('getCredentials ' )
154
+ ->will ($ this ->returnValue ('0 ' ))
121
155
;
122
156
123
- $ method ->invoke ($ provider , $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' ), $ token );
157
+ $ method ->invoke (
158
+ $ provider ,
159
+ $ this ->getMock ('Symfony \\Component \\Security \\Core \\User \\UserInterface ' ),
160
+ $ token
161
+ );
124
162
}
125
163
126
164
/**
127
165
* @expectedException Symfony\Component\Security\Core\Exception\BadCredentialsException
128
166
*/
129
167
public function testCheckAuthenticationWhenCredentialsAreNotValid ()
130
168
{
131
- $ encoder = $ this ->getMock ('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface ' );
169
+ $ encoder = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ Encoder \ \PasswordEncoderInterface ' );
132
170
$ encoder ->expects ($ this ->once ())
133
171
->method ('isPasswordValid ' )
134
172
->will ($ this ->returnValue (false ))
@@ -144,15 +182,15 @@ public function testCheckAuthenticationWhenCredentialsAreNotValid()
144
182
->will ($ this ->returnValue ('foo ' ))
145
183
;
146
184
147
- $ method ->invoke ($ provider , $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' ), $ token );
185
+ $ method ->invoke ($ provider , $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserInterface ' ), $ token );
148
186
}
149
187
150
188
/**
151
189
* @expectedException Symfony\Component\Security\Core\Exception\BadCredentialsException
152
190
*/
153
191
public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChanged ()
154
192
{
155
- $ user = $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' );
193
+ $ user = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserInterface ' );
156
194
$ user ->expects ($ this ->once ())
157
195
->method ('getPassword ' )
158
196
->will ($ this ->returnValue ('foo ' ))
@@ -163,7 +201,7 @@ public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChang
163
201
->method ('getUser ' )
164
202
->will ($ this ->returnValue ($ user ));
165
203
166
- $ dbUser = $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' );
204
+ $ dbUser = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserInterface ' );
167
205
$ dbUser ->expects ($ this ->once ())
168
206
->method ('getPassword ' )
169
207
->will ($ this ->returnValue ('newFoo ' ))
@@ -177,7 +215,7 @@ public function testCheckAuthenticationDoesNotReauthenticateWhenPasswordHasChang
177
215
178
216
public function testCheckAuthenticationWhenTokenNeedsReauthenticationWorksWithoutOriginalCredentials ()
179
217
{
180
- $ user = $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' );
218
+ $ user = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserInterface ' );
181
219
$ user ->expects ($ this ->once ())
182
220
->method ('getPassword ' )
183
221
->will ($ this ->returnValue ('foo ' ))
@@ -188,7 +226,7 @@ public function testCheckAuthenticationWhenTokenNeedsReauthenticationWorksWithou
188
226
->method ('getUser ' )
189
227
->will ($ this ->returnValue ($ user ));
190
228
191
- $ dbUser = $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' );
229
+ $ dbUser = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserInterface ' );
192
230
$ dbUser ->expects ($ this ->once ())
193
231
->method ('getPassword ' )
194
232
->will ($ this ->returnValue ('foo ' ))
@@ -202,7 +240,7 @@ public function testCheckAuthenticationWhenTokenNeedsReauthenticationWorksWithou
202
240
203
241
public function testCheckAuthentication ()
204
242
{
205
- $ encoder = $ this ->getMock ('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface ' );
243
+ $ encoder = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ Encoder \ \PasswordEncoderInterface ' );
206
244
$ encoder ->expects ($ this ->once ())
207
245
->method ('isPasswordValid ' )
208
246
->will ($ this ->returnValue (true ))
@@ -218,12 +256,12 @@ public function testCheckAuthentication()
218
256
->will ($ this ->returnValue ('foo ' ))
219
257
;
220
258
221
- $ method ->invoke ($ provider , $ this ->getMock ('Symfony\Component\Security\Core\User\UserInterface ' ), $ token );
259
+ $ method ->invoke ($ provider , $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserInterface ' ), $ token );
222
260
}
223
261
224
262
protected function getSupportedToken ()
225
263
{
226
- $ mock = $ this ->getMock ('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken ' , array ('getCredentials ' , 'getUser ' , 'getProviderKey ' ), array (), '' , false );
264
+ $ mock = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ Authentication \\ Token \ \UsernamePasswordToken ' , array ('getCredentials ' , 'getUser ' , 'getProviderKey ' ), array (), '' , false );
227
265
$ mock
228
266
->expects ($ this ->any ())
229
267
->method ('getProviderKey ' )
@@ -235,7 +273,7 @@ protected function getSupportedToken()
235
273
236
274
protected function getProvider ($ user = false , $ userChecker = false , $ passwordEncoder = null )
237
275
{
238
- $ userProvider = $ this ->getMock ('Symfony\Component\Security\Core\User\UserProviderInterface ' );
276
+ $ userProvider = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserProviderInterface ' );
239
277
if (false !== $ user ) {
240
278
$ userProvider ->expects ($ this ->once ())
241
279
->method ('loadUserByUsername ' )
@@ -244,14 +282,14 @@ protected function getProvider($user = false, $userChecker = false, $passwordEnc
244
282
}
245
283
246
284
if (false === $ userChecker ) {
247
- $ userChecker = $ this ->getMock ('Symfony\Component\Security\Core\User\UserCheckerInterface ' );
285
+ $ userChecker = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ User \ \UserCheckerInterface ' );
248
286
}
249
287
250
288
if (null === $ passwordEncoder ) {
251
289
$ passwordEncoder = new PlaintextPasswordEncoder ();
252
290
}
253
291
254
- $ encoderFactory = $ this ->getMock ('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface ' );
292
+ $ encoderFactory = $ this ->getMock ('Symfony \\ Component \\ Security \\ Core \\ Encoder \ \EncoderFactoryInterface ' );
255
293
$ encoderFactory
256
294
->expects ($ this ->any ())
257
295
->method ('getEncoder ' )
0 commit comments