@@ -36,12 +36,24 @@ class OAuthStorageTest extends \PHPUnit_Framework_TestCase
36
36
37
37
public function setUp ()
38
38
{
39
- $ this ->clientManager = $ this ->createMock ('FOS\OAuthServerBundle\Model\ClientManagerInterface ' );
40
- $ this ->accessTokenManager = $ this ->createMock ('FOS\OAuthServerBundle\Model\AccessTokenManagerInterface ' );
41
- $ this ->refreshTokenManager = $ this ->createMock ('FOS\OAuthServerBundle\Model\RefreshTokenManagerInterface ' );
42
- $ this ->authCodeManager = $ this ->createMock ('FOS\OAuthServerBundle\Model\AuthCodeManagerInterface ' );
43
- $ this ->userProvider = $ this ->createMock ('Symfony\Component\Security\Core\User\UserProviderInterface ' );
44
- $ this ->encoderFactory = $ this ->createMock ('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface ' );
39
+ $ this ->clientManager = $ this ->getMockBuilder ('FOS\OAuthServerBundle\Model\ClientManagerInterface ' )
40
+ ->disableOriginalConstructor ()
41
+ ->getMock ();
42
+ $ this ->accessTokenManager = $ this ->getMockBuilder ('FOS\OAuthServerBundle\Model\AccessTokenManagerInterface ' )
43
+ ->disableOriginalConstructor ()
44
+ ->getMock ();
45
+ $ this ->refreshTokenManager = $ this ->getMockBuilder ('FOS\OAuthServerBundle\Model\RefreshTokenManagerInterface ' )
46
+ ->disableOriginalConstructor ()
47
+ ->getMock ();
48
+ $ this ->authCodeManager = $ this ->getMockBuilder ('FOS\OAuthServerBundle\Model\AuthCodeManagerInterface ' )
49
+ ->disableOriginalConstructor ()
50
+ ->getMock ();
51
+ $ this ->userProvider = $ this ->getMockBuilder ('Symfony\Component\Security\Core\User\UserProviderInterface ' )
52
+ ->disableOriginalConstructor ()
53
+ ->getMock ();
54
+ $ this ->encoderFactory = $ this ->getMockBuilder ('Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface ' )
55
+ ->disableOriginalConstructor ()
56
+ ->getMock ();
45
57
46
58
$ this ->storage = new OAuthStorage ($ this ->clientManager , $ this ->accessTokenManager , $ this ->refreshTokenManager , $ this ->authCodeManager , $ this ->userProvider , $ this ->encoderFactory );
47
59
}
@@ -72,7 +84,9 @@ public function testGetClientReturnsNullIfNotExists()
72
84
73
85
public function testCheckClientCredentialsThrowsIfInvalidClientClass ()
74
86
{
75
- $ client = $ this ->createMock ('OAuth2\Model\IOAuth2Client ' );
87
+ $ client = $ this ->getMockBuilder ('OAuth2\Model\IOAuth2Client ' )
88
+ ->disableOriginalConstructor ()
89
+ ->getMock ();
76
90
77
91
$ this ->expectException ('InvalidArgumentException ' );
78
92
$ this ->storage ->checkClientCredentials ($ client , 'dummy ' );
@@ -120,7 +134,9 @@ public function testGetAccessTokenReturnsNullIfNotExists()
120
134
121
135
public function testCreateAccessTokenThrowsOnInvalidClientClass ()
122
136
{
123
- $ client = $ this ->createMock ('OAuth2\Model\IOAuth2Client ' );
137
+ $ client = $ this ->getMockBuilder ('OAuth2\Model\IOAuth2Client ' )
138
+ ->disableOriginalConstructor ()
139
+ ->getMock ();
124
140
125
141
$ this ->expectException ('InvalidArgumentException ' );
126
142
$ this ->storage ->createAccessToken ('foo ' , $ client , new User (42 ), 1 , 'foo bar ' );
@@ -201,7 +217,9 @@ public function testGetRefreshTokenReturnsNullIfNotExists()
201
217
202
218
public function testCreateRefreshTokenThrowsOnInvalidClientClass ()
203
219
{
204
- $ client = $ this ->createMock ('OAuth2\Model\IOAuth2Client ' );
220
+ $ client = $ this ->getMockBuilder ('OAuth2\Model\IOAuth2Client ' )
221
+ ->disableOriginalConstructor ()
222
+ ->getMock ();
205
223
206
224
$ this ->expectException ('InvalidArgumentException ' );
207
225
$ this ->storage ->createRefreshToken ('foo ' , $ client , 42 , 1 , 'foo bar ' );
@@ -260,7 +278,9 @@ public function testCreateRefreshTokenWithoutUser()
260
278
261
279
public function testCheckRestrictedGrantTypeThrowsOnInvalidClientClass ()
262
280
{
263
- $ client = $ this ->createMock ('OAuth2\Model\IOAuth2Client ' );
281
+ $ client = $ this ->getMockBuilder ('OAuth2\Model\IOAuth2Client ' )
282
+ ->disableOriginalConstructor ()
283
+ ->getMock ();
264
284
265
285
$ this ->expectException ('InvalidArgumentException ' );
266
286
@@ -279,7 +299,9 @@ public function testCheckRestrictedGrantType()
279
299
280
300
public function testCheckUserCredentialsThrowsOnInvalidClientClass ()
281
301
{
282
- $ client = $ this ->createMock ('OAuth2\Model\IOAuth2Client ' );
302
+ $ client = $ this ->getMockBuilder ('OAuth2\Model\IOAuth2Client ' )
303
+ ->disableOriginalConstructor ()
304
+ ->getMock ();
283
305
284
306
$ this ->expectException ('InvalidArgumentException ' );
285
307
@@ -298,13 +320,17 @@ public function testCheckUserCredentialsCatchesAuthenticationExceptions()
298
320
public function testCheckUserCredentialsReturnsTrueOnValidCredentials ()
299
321
{
300
322
$ client = new Client ();
301
- $ user = $ this ->createMock ('Symfony\Component\Security\Core\User\UserInterface ' );
323
+ $ user = $ this ->getMockBuilder ('Symfony\Component\Security\Core\User\UserInterface ' )
324
+ ->disableOriginalConstructor ()
325
+ ->getMock ();
302
326
$ user ->expects ($ this ->once ())
303
327
->method ('getPassword ' )->with ()->will ($ this ->returnValue ('foo ' ));
304
328
$ user ->expects ($ this ->once ())
305
329
->method ('getSalt ' )->with ()->will ($ this ->returnValue ('bar ' ));
306
330
307
- $ encoder = $ this ->createMock ('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface ' );
331
+ $ encoder = $ this ->getMockBuilder ('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface ' )
332
+ ->disableOriginalConstructor ()
333
+ ->getMock ();
308
334
$ encoder ->expects ($ this ->once ())
309
335
->method ('isPasswordValid ' )
310
336
->with ('foo ' , 'baz ' , 'bar ' )
@@ -328,13 +354,17 @@ public function testCheckUserCredentialsReturnsTrueOnValidCredentials()
328
354
public function testCheckUserCredentialsReturnsFalseOnInvalidCredentials ()
329
355
{
330
356
$ client = new Client ();
331
- $ user = $ this ->createMock ('Symfony\Component\Security\Core\User\UserInterface ' );
357
+ $ user = $ this ->getMockBuilder ('Symfony\Component\Security\Core\User\UserInterface ' )
358
+ ->disableOriginalConstructor ()
359
+ ->getMock ();
332
360
$ user ->expects ($ this ->once ())
333
361
->method ('getPassword ' )->with ()->will ($ this ->returnValue ('foo ' ));
334
362
$ user ->expects ($ this ->once ())
335
363
->method ('getSalt ' )->with ()->will ($ this ->returnValue ('bar ' ));
336
364
337
- $ encoder = $ this ->createMock ('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface ' );
365
+ $ encoder = $ this ->getMockBuilder ('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface ' )
366
+ ->disableOriginalConstructor ()
367
+ ->getMock ();
338
368
$ encoder ->expects ($ this ->once ())
339
369
->method ('isPasswordValid ' )
340
370
->with ('foo ' , 'baz ' , 'bar ' )
@@ -367,7 +397,9 @@ public function testCheckUserCredentialsReturnsFalseIfUserNotExist()
367
397
368
398
public function testCreateAuthCodeThrowsOnInvalidClientClass ()
369
399
{
370
- $ client = $ this ->createMock ('OAuth2\Model\IOAuth2Client ' );
400
+ $ client = $ this ->getMockBuilder ('OAuth2\Model\IOAuth2Client ' )
401
+ ->disableOriginalConstructor ()
402
+ ->getMock ();
371
403
372
404
$ this ->expectException ('InvalidArgumentException ' );
373
405
$ this ->storage ->createAuthCode ('foo ' , $ client , 42 , 'http://www.example.com/ ' , 1 , 'foo bar ' );
@@ -426,15 +458,19 @@ public function testGetAuthCodeReturnsNullIfNotExists()
426
458
427
459
public function testValidGrantExtension ()
428
460
{
429
- $ grantExtension = $ this ->createMock ('FOS\OAuthServerBundle\Storage\GrantExtensionInterface ' );
461
+ $ grantExtension = $ this ->getMockBuilder ('FOS\OAuthServerBundle\Storage\GrantExtensionInterface ' )
462
+ ->disableOriginalConstructor ()
463
+ ->getMock ();
430
464
$ grantExtension
431
465
->expects ($ this ->once ())
432
466
->method ('checkGrantExtension ' )
433
467
->will ($ this ->returnValue (true ))
434
468
;
435
469
$ this ->storage ->setGrantExtension ('https://friendsofsymfony.com/grants/foo ' , $ grantExtension );
436
470
437
- $ client = $ this ->createMock ('OAuth2\Model\IOAuth2Client ' );
471
+ $ client = $ this ->getMockBuilder ('OAuth2\Model\IOAuth2Client ' )
472
+ ->disableOriginalConstructor ()
473
+ ->getMock ();
438
474
$ this ->assertTrue ($ this ->storage ->checkGrantExtension ($ client , 'https://friendsofsymfony.com/grants/foo ' , array (), array ()));
439
475
}
440
476
@@ -443,14 +479,20 @@ public function testValidGrantExtension()
443
479
*/
444
480
public function testInvalidGrantExtension ()
445
481
{
446
- $ client = $ this ->createMock ('OAuth2\Model\IOAuth2Client ' );
482
+ $ client = $ this ->getMockBuilder ('OAuth2\Model\IOAuth2Client ' )
483
+ ->disableOriginalConstructor ()
484
+ ->getMock ();
447
485
$ this ->storage ->checkGrantExtension ($ client , 'https://friendsofsymfony.com/grants/bar ' , array (), array ());
448
486
}
449
487
450
488
public function testDoubleSetGrantExtension ()
451
489
{
452
- $ grantExtension = $ this ->createMock ('FOS\OAuthServerBundle\Storage\GrantExtensionInterface ' );
453
- $ grantExtension2 = $ this ->createMock ('FOS\OAuthServerBundle\Storage\GrantExtensionInterface ' );
490
+ $ grantExtension = $ this ->getMockBuilder ('FOS\OAuthServerBundle\Storage\GrantExtensionInterface ' )
491
+ ->disableOriginalConstructor ()
492
+ ->getMock ();
493
+ $ grantExtension2 = $ this ->getMockBuilder ('FOS\OAuthServerBundle\Storage\GrantExtensionInterface ' )
494
+ ->disableOriginalConstructor ()
495
+ ->getMock ();
454
496
$ this ->storage ->setGrantExtension ($ uri = 'https://friendsofsymfony.com/grants/foo ' , $ grantExtension );
455
497
$ this ->storage ->setGrantExtension ($ uri , $ grantExtension2 );
456
498
@@ -464,7 +506,9 @@ public function testDoubleSetGrantExtension()
464
506
465
507
public function testMarkAuthCodeAsUsedIfAuthCodeFound ()
466
508
{
467
- $ authCode = $ this ->createMock ('FOS\OAuthServerBundle\Model\AuthCodeInterface ' );
509
+ $ authCode = $ this ->getMockBuilder ('FOS\OAuthServerBundle\Model\AuthCodeInterface ' )
510
+ ->disableOriginalConstructor ()
511
+ ->getMock ();
468
512
469
513
$ this ->authCodeManager ->expects ($ this ->atLeastOnce ())
470
514
->method ('findAuthCodeByToken ' )
0 commit comments