Skip to content

Commit 8ccac19

Browse files
dnahrebeckidkarlovi
authored andcommitted
- remove 5.3 due to unsupported dist
- use mock builder instead of create mock in tests
1 parent bfc7f68 commit 8ccac19

File tree

10 files changed

+124
-45
lines changed

10 files changed

+124
-45
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ language: php
33
sudo: false
44

55
php:
6-
- 5.3
76
- 5.4
87
- 5.5
98
- 5.6
@@ -41,7 +40,7 @@ cache:
4140

4241
before_script:
4342
- if [ "$DEPENDENCIES" = "beta" ]; then composer config minimum-stability beta; fi;
44-
- if [[ $TRAVIS_PHP_VERSION != hhvm ]]; then phpenv config-rm xdebug.ini; fi;
43+
- if [[ $TRAVIS_PHP_VERSION != hhvm ]]; then phpenv config-rm xdebug.ini; echo "memory_limit=2G" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi;
4544
- echo "extension = mongo.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
4645
- echo "extension = mongodb.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
4746
- composer self-update

Tests/Command/CleanCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,21 @@ protected function setUp()
5454
public function testItShouldRemoveExpiredToken($class)
5555
{
5656
$expiredAccessTokens = 5;
57-
$accessTokenManager = $this->createMock($class);
57+
$accessTokenManager = $this->getMockBuilder($class)->disableOriginalConstructor()->getMock();
5858
$accessTokenManager
5959
->expects($this->once())
6060
->method('deleteExpired')
6161
->will($this->returnValue($expiredAccessTokens));
6262

6363
$expiredRefreshTokens = 183;
64-
$refreshTokenManager = $this->createMock($class);
64+
$refreshTokenManager = $this->getMockBuilder($class)->disableOriginalConstructor()->getMock();
6565
$refreshTokenManager
6666
->expects($this->once())
6767
->method('deleteExpired')
6868
->will($this->returnValue($expiredRefreshTokens));
6969

7070
$expiredAuthCodes = 0;
71-
$authCodeManager = $this->createMock($class);
71+
$authCodeManager = $this->getMockBuilder($class)->disableOriginalConstructor()->getMock();
7272
$authCodeManager
7373
->expects($this->once())
7474
->method('deleteExpired')

Tests/Document/TokenManagerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ public function setUp()
2828
}
2929

3030
$this->class = 'FOS\OAuthServerBundle\Document\AccessToken';
31-
$this->repository = $this->createMock('Doctrine\ODM\MongoDB\DocumentRepository');
32-
$this->dm = $this->createMock('Doctrine\ODM\MongoDB\DocumentManager');
31+
$this->repository = $this->getMockBuilder('Doctrine\ODM\MongoDB\DocumentRepository')
32+
->disableOriginalConstructor()
33+
->getMock();
34+
$this->dm = $this->getMockBuilder('Doctrine\ODM\MongoDB\DocumentManager')
35+
->disableOriginalConstructor()
36+
->getMock();
3337
$this->dm->expects($this->once())
3438
->method('getRepository')
3539
->with($this->class)

Tests/Entity/TokenManagerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ class TokenManagerTest extends \PHPUnit_Framework_TestCase
2727
public function setUp()
2828
{
2929
$this->class = 'FOS\OAuthServerBundle\Entity\AccessToken';
30-
$this->repository = $this->createMock('Doctrine\ORM\EntityRepository');
31-
$this->em = $this->createMock('Doctrine\ORM\EntityManager');
30+
$this->repository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')
31+
->disableOriginalConstructor()
32+
->getMock();
33+
$this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
34+
->disableOriginalConstructor()
35+
->getMock();
3236
$this->em->expects($this->once())
3337
->method('getRepository')
3438
->with($this->class)

Tests/Propel/AuthCodeManagerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public function testCreateClass()
4141

4242
public function testUpdate()
4343
{
44-
$authCode = $this->createMock('FOS\OAuthServerBundle\Propel\AuthCode');
44+
$authCode = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\AuthCode')
45+
->disableOriginalConstructor()
46+
->getMock();
4547
$authCode
4648
->expects($this->once())
4749
->method('save');
@@ -51,7 +53,9 @@ public function testUpdate()
5153

5254
public function testDelete()
5355
{
54-
$authCode = $this->createMock('FOS\OAuthServerBundle\Propel\AuthCode');
56+
$authCode = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\AuthCode')
57+
->disableOriginalConstructor()
58+
->getMock();
5559
$authCode
5660
->expects($this->once())
5761
->method('delete');

Tests/Propel/ClientManagerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ public function testCreateClass()
4141

4242
public function testUpdate()
4343
{
44-
$client = $this->createMock('FOS\OAuthServerBundle\Propel\Client');
44+
$client = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\Client')
45+
->disableOriginalConstructor()
46+
->getMock();
4547
$client
4648
->expects($this->once())
4749
->method('save');
@@ -51,7 +53,9 @@ public function testUpdate()
5153

5254
public function testDelete()
5355
{
54-
$client = $this->createMock('FOS\OAuthServerBundle\Propel\Client');
56+
$client = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\Client')
57+
->disableOriginalConstructor()
58+
->getMock();
5559
$client
5660
->expects($this->once())
5761
->method('delete');

Tests/Propel/TokenManagerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function testCreateClass()
4242

4343
public function testUpdate()
4444
{
45-
$token = $this->createMock('FOS\OAuthServerBundle\Propel\Token');
45+
$token = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\Token')
46+
->disableOriginalConstructor()
47+
->getMock();
4648
$token
4749
->expects($this->once())
4850
->method('save');
@@ -52,7 +54,9 @@ public function testUpdate()
5254

5355
public function testDelete()
5456
{
55-
$token = $this->createMock('FOS\OAuthServerBundle\Propel\Token');
57+
$token = $this->getMockBuilder('FOS\OAuthServerBundle\Propel\Token')
58+
->disableOriginalConstructor()
59+
->getMock();
5660
$token
5761
->expects($this->once())
5862
->method('delete');

Tests/Security/Authentification/Provider/OAuthProviderTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ class OAuthProviderTest extends \PHPUnit_Framework_TestCase
2525

2626
public function setUp()
2727
{
28-
$this->user = $this->createMock('Symfony\Component\Security\Core\User\UserInterface');
29-
$this->userProvider = $this->createMock('Symfony\Component\Security\Core\User\UserProviderInterface');
28+
$this->user = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')
29+
->disableOriginalConstructor()
30+
->getMock();
31+
$this->userProvider = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserProviderInterface')
32+
->disableOriginalConstructor()
33+
->getMock();
3034
$this->serverService = $this->getMockBuilder('OAuth2\OAuth2')
3135
->disableOriginalConstructor()
3236
->setMethods(array('verifyAccessToken'))
3337
->getMock();
34-
$this->userChecker = $this->createMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
38+
$this->userChecker = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserCheckerInterface')
39+
->disableOriginalConstructor()
40+
->getMock();
3541
$this->provider = new OAuthProvider($this->userProvider, $this->serverService, $this->userChecker);
3642
}
3743

Tests/Security/Firewall/OAuthListenerTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,24 @@ class OAuthListenerTest extends TestCase
2626

2727
public function setUp()
2828
{
29-
$this->serverService = $this->createMock('OAuth2\OAuth2');
29+
$this->serverService = $this->getMockBuilder('OAuth2\OAuth2')
30+
->disableOriginalConstructor()
31+
->getMock();
3032

3133
$this->authManager = $this
32-
->createMock('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface');
34+
->getMockBuilder('Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface')
35+
->disableOriginalConstructor()
36+
->getMock();
3337

3438
if (interface_exists('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')) {
3539
$this->securityContext = $this
36-
->createMock('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface');
40+
->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')
41+
->disableOriginalConstructor()
42+
->getMock();
3743
} else {
38-
$this->securityContext = $this->createMock('Symfony\Component\Security\Core\SecurityContextInterface');
44+
$this->securityContext = $this->getMockBuilder('Symfony\Component\Security\Core\SecurityContextInterface')
45+
->disableOriginalConstructor()
46+
->getMock();
3947
}
4048

4149
$this->event = $this
@@ -78,7 +86,9 @@ public function testHandleResponse()
7886
->method('getBearerToken')
7987
->will($this->returnValue('a-token'));
8088

81-
$response = $this->createMock('Symfony\Component\HttpFoundation\Response');
89+
$response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response')
90+
->disableOriginalConstructor()
91+
->getMock();
8292

8393
$this->authManager
8494
->expects($this->once())

Tests/Storage/OAuthStorageTest.php

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,24 @@ class OAuthStorageTest extends \PHPUnit_Framework_TestCase
3636

3737
public function setUp()
3838
{
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();
4557

4658
$this->storage = new OAuthStorage($this->clientManager, $this->accessTokenManager, $this->refreshTokenManager, $this->authCodeManager, $this->userProvider, $this->encoderFactory);
4759
}
@@ -72,7 +84,9 @@ public function testGetClientReturnsNullIfNotExists()
7284

7385
public function testCheckClientCredentialsThrowsIfInvalidClientClass()
7486
{
75-
$client = $this->createMock('OAuth2\Model\IOAuth2Client');
87+
$client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client')
88+
->disableOriginalConstructor()
89+
->getMock();
7690

7791
$this->expectException('InvalidArgumentException');
7892
$this->storage->checkClientCredentials($client, 'dummy');
@@ -120,7 +134,9 @@ public function testGetAccessTokenReturnsNullIfNotExists()
120134

121135
public function testCreateAccessTokenThrowsOnInvalidClientClass()
122136
{
123-
$client = $this->createMock('OAuth2\Model\IOAuth2Client');
137+
$client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client')
138+
->disableOriginalConstructor()
139+
->getMock();
124140

125141
$this->expectException('InvalidArgumentException');
126142
$this->storage->createAccessToken('foo', $client, new User(42), 1, 'foo bar');
@@ -201,7 +217,9 @@ public function testGetRefreshTokenReturnsNullIfNotExists()
201217

202218
public function testCreateRefreshTokenThrowsOnInvalidClientClass()
203219
{
204-
$client = $this->createMock('OAuth2\Model\IOAuth2Client');
220+
$client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client')
221+
->disableOriginalConstructor()
222+
->getMock();
205223

206224
$this->expectException('InvalidArgumentException');
207225
$this->storage->createRefreshToken('foo', $client, 42, 1, 'foo bar');
@@ -260,7 +278,9 @@ public function testCreateRefreshTokenWithoutUser()
260278

261279
public function testCheckRestrictedGrantTypeThrowsOnInvalidClientClass()
262280
{
263-
$client = $this->createMock('OAuth2\Model\IOAuth2Client');
281+
$client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client')
282+
->disableOriginalConstructor()
283+
->getMock();
264284

265285
$this->expectException('InvalidArgumentException');
266286

@@ -279,7 +299,9 @@ public function testCheckRestrictedGrantType()
279299

280300
public function testCheckUserCredentialsThrowsOnInvalidClientClass()
281301
{
282-
$client = $this->createMock('OAuth2\Model\IOAuth2Client');
302+
$client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client')
303+
->disableOriginalConstructor()
304+
->getMock();
283305

284306
$this->expectException('InvalidArgumentException');
285307

@@ -298,13 +320,17 @@ public function testCheckUserCredentialsCatchesAuthenticationExceptions()
298320
public function testCheckUserCredentialsReturnsTrueOnValidCredentials()
299321
{
300322
$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();
302326
$user->expects($this->once())
303327
->method('getPassword')->with()->will($this->returnValue('foo'));
304328
$user->expects($this->once())
305329
->method('getSalt')->with()->will($this->returnValue('bar'));
306330

307-
$encoder = $this->createMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
331+
$encoder = $this->getMockBuilder('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface')
332+
->disableOriginalConstructor()
333+
->getMock();
308334
$encoder->expects($this->once())
309335
->method('isPasswordValid')
310336
->with('foo', 'baz', 'bar')
@@ -328,13 +354,17 @@ public function testCheckUserCredentialsReturnsTrueOnValidCredentials()
328354
public function testCheckUserCredentialsReturnsFalseOnInvalidCredentials()
329355
{
330356
$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();
332360
$user->expects($this->once())
333361
->method('getPassword')->with()->will($this->returnValue('foo'));
334362
$user->expects($this->once())
335363
->method('getSalt')->with()->will($this->returnValue('bar'));
336364

337-
$encoder = $this->createMock('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface');
365+
$encoder = $this->getMockBuilder('Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface')
366+
->disableOriginalConstructor()
367+
->getMock();
338368
$encoder->expects($this->once())
339369
->method('isPasswordValid')
340370
->with('foo', 'baz', 'bar')
@@ -367,7 +397,9 @@ public function testCheckUserCredentialsReturnsFalseIfUserNotExist()
367397

368398
public function testCreateAuthCodeThrowsOnInvalidClientClass()
369399
{
370-
$client = $this->createMock('OAuth2\Model\IOAuth2Client');
400+
$client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client')
401+
->disableOriginalConstructor()
402+
->getMock();
371403

372404
$this->expectException('InvalidArgumentException');
373405
$this->storage->createAuthCode('foo', $client, 42, 'http://www.example.com/', 1, 'foo bar');
@@ -426,15 +458,19 @@ public function testGetAuthCodeReturnsNullIfNotExists()
426458

427459
public function testValidGrantExtension()
428460
{
429-
$grantExtension = $this->createMock('FOS\OAuthServerBundle\Storage\GrantExtensionInterface');
461+
$grantExtension = $this->getMockBuilder('FOS\OAuthServerBundle\Storage\GrantExtensionInterface')
462+
->disableOriginalConstructor()
463+
->getMock();
430464
$grantExtension
431465
->expects($this->once())
432466
->method('checkGrantExtension')
433467
->will($this->returnValue(true))
434468
;
435469
$this->storage->setGrantExtension('https://friendsofsymfony.com/grants/foo', $grantExtension);
436470

437-
$client = $this->createMock('OAuth2\Model\IOAuth2Client');
471+
$client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client')
472+
->disableOriginalConstructor()
473+
->getMock();
438474
$this->assertTrue($this->storage->checkGrantExtension($client, 'https://friendsofsymfony.com/grants/foo', array(), array()));
439475
}
440476

@@ -443,14 +479,20 @@ public function testValidGrantExtension()
443479
*/
444480
public function testInvalidGrantExtension()
445481
{
446-
$client = $this->createMock('OAuth2\Model\IOAuth2Client');
482+
$client = $this->getMockBuilder('OAuth2\Model\IOAuth2Client')
483+
->disableOriginalConstructor()
484+
->getMock();
447485
$this->storage->checkGrantExtension($client, 'https://friendsofsymfony.com/grants/bar', array(), array());
448486
}
449487

450488
public function testDoubleSetGrantExtension()
451489
{
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();
454496
$this->storage->setGrantExtension($uri = 'https://friendsofsymfony.com/grants/foo', $grantExtension);
455497
$this->storage->setGrantExtension($uri, $grantExtension2);
456498

@@ -464,7 +506,9 @@ public function testDoubleSetGrantExtension()
464506

465507
public function testMarkAuthCodeAsUsedIfAuthCodeFound()
466508
{
467-
$authCode = $this->createMock('FOS\OAuthServerBundle\Model\AuthCodeInterface');
509+
$authCode = $this->getMockBuilder('FOS\OAuthServerBundle\Model\AuthCodeInterface')
510+
->disableOriginalConstructor()
511+
->getMock();
468512

469513
$this->authCodeManager->expects($this->atLeastOnce())
470514
->method('findAuthCodeByToken')

0 commit comments

Comments
 (0)