From e143951111ff3f7c20426385461d6252755fccbf Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 15:47:47 +0100 Subject: [PATCH 01/25] [test] Add Symfony PHP Unit Bridge --- composer.json | 3 ++- composer.lock | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 562ae86..c0d00ec 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ }, "require-dev": { "fabpot/php-cs-fixer": "^1.9", - "phpunit/phpunit": "~5.1" + "phpunit/phpunit": "~5.1", + "symfony/phpunit-bridge": "^3.0" }, "require": { "php": ">=5.6", diff --git a/composer.lock b/composer.lock index 56f1411..e59629d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "77df1d2735511f683bc3a75e7c4fd630", - "content-hash": "f6b51a231d8fcdf71b3816016f22eb31", + "hash": "13e591ddfbce60f08dea143e413098da", + "content-hash": "490f3823af1a08fe13c4b0be306021c4", "packages": [ { "name": "doctrine/annotations", @@ -555,6 +555,61 @@ ], "time": "2012-12-21 11:40:51" }, + { + "name": "symfony/phpunit-bridge", + "version": "v3.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/phpunit-bridge.git", + "reference": "4580ae86cde5497d38fc971192cd2c37e546eb4f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/4580ae86cde5497d38fc971192cd2c37e546eb4f", + "reference": "4580ae86cde5497d38fc971192cd2c37e546eb4f", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "suggest": { + "symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" + }, + "type": "symfony-bridge", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Bridge\\PhpUnit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony PHPUnit Bridge", + "homepage": "https://symfony.com", + "time": "2016-01-21 09:38:31" + }, { "name": "symfony/polyfill-intl-icu", "version": "v1.1.1", From 28ee3b255176eccdf9e484396249e04eb9f4b769 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 15:48:20 +0100 Subject: [PATCH 02/25] [test] Add test for Token --- .../OAuth/Tests/Entity/TokenTest.php | 221 ++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/TokenTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/TokenTest.php b/src/Majora/Component/OAuth/Tests/Entity/TokenTest.php new file mode 100644 index 0000000..fe81945 --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/TokenTest.php @@ -0,0 +1,221 @@ +prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $this->token = new MockedToken( + $this->application = $application->reveal(), + $this->account = $account->reveal(), + 42 + ); + } + + + /** + * Roles testing provider + */ + public function rolesProvider() + { + return [ + [ + ['ROLE_1', 'ROLE_3'], + ['ROLE_1', 'ROLE_2', 'ROLE_3'], + ['ROLE_1', 'ROLE_3'] + ], + [ + ['ROLE_1', 'ROLE_3'], + ['ROLE_1', 'ROLE_2'], + ['ROLE_1'] + ], + [ + ['ROLE_4', 'ROLE_3'], + ['ROLE_1', 'ROLE_2'], + [] + ], + [ + ['ROLE_1', 'ROLE_2', 'ROLE_3'], + ['ROLE_1', 'ROLE_2', 'ROLE_3'], + ['ROLE_1', 'ROLE_2', 'ROLE_3'] + ] + ]; + } + + /** + * Test the getRoles() method. + * + * @dataProvider rolesProvider + */ + public function testRoles(array $applicationRoles, array $accountRoles, array $expectedRoles) + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->shouldBeCalled(); + $application + ->getRoles() + ->willReturn($applicationRoles) + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->shouldBeCalled(); + $account + ->getRoles() + ->willReturn($accountRoles) + ->shouldBeCalled(); + + $token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42 + ); + + $this->assertEquals($expectedRoles, $token->getRoles(), '', 0.0, 10, true); + } + + /** + * Test the expiration datetime is the datetime when the token expires in. + */ + public function testExpireAt() + { + ClockMock::withClockMock(true); + + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $this->token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42 + ); + + $this->assertEquals(\DateTime::createFromFormat('U', time() + intval(42)), $this->token->getExpireAt()); + } + + /** + * Test if the expiration datetime given in constructor is equals to returned by the getter. + */ + public function testConstructorExpireAt() + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $this->token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42, + $expectedExpireAt = \DateTime::createFromFormat('U', time() + intval(42)) + ); + + $this->assertEquals($expectedExpireAt, $this->token->getExpireAt()); + } + + /** + * Test if the account given in constructor is equals to returned by the getter. + */ + public function testConstructorAccount() + { + $this->assertEquals($this->account, $this->token->getAccount()); + } + + /** + * Test if the application given in constructor is equals to returned by the getter. + */ + public function testConstructorApplication() + { + $this->assertEquals($this->application, $this->token->getApplication()); + } + + /** + * Test if the expiration seconds given in constructor is equals to returned by the getter. + */ + public function testConstructorExpireIn() + { + $this->assertEquals(42, $this->token->getExpireIn()); + } + + /** + * Test if the hash given in constructor is equals to returned by the getter. + */ + public function testConstructorHash() + { + $application = $this->prophesize(ApplicationInterface::class); + $account = $this->prophesize(AccountInterface::class); + + $this->token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42, + null, + 'mocked_hash' + ); + + $this->assertEquals('mocked_hash', $this->token->getHash()); + $this->assertEquals('mocked_hash', (string)$this->token); + } +} + +class MockedToken extends Token +{ +} From aaed56a4846f27ccf516369a8a2c427403db7607 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:21:59 +0100 Subject: [PATCH 03/25] [test] add test for the AccessToken entity --- .../OAuth/Tests/Entity/AccessTokenTest.php | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php new file mode 100644 index 0000000..41ea6e8 --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php @@ -0,0 +1,74 @@ + + */ +class AccessTokenTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test if the refresh token given in constructor is equals to returned by the getter. + */ + public function testConstructorRefreshToken() + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $refreshToken = $this->prophesize(RefreshTokenInterface::class); + + $token = new AccessToken( + $application->reveal(), + $account->reveal(), + 42, + null, + null, + $refreshToken->reveal() + ); + + $this->assertEquals($refreshToken->reveal(), $token->getRefreshToken()); + } + + /** + * Test getScopes() method. + */ + public function testScopes() + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $token = new AccessToken( + $application->reveal(), + $account->reveal() + ); + + $expectedScopes = [ + 'default' => ['id', 'hash', 'refresh_token', 'expire_in', 'application@id', 'account@id'], + ]; + $this->assertEquals($expectedScopes, $token->getScopes(), '', 0.0, 10, true); + } +} From 155e5efe1233e1ce34c0fb7bcdd117e6977ac714 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:39:54 +0100 Subject: [PATCH 04/25] [test] Add test for the Account entity --- .../OAuth/Tests/Entity/AccountTest.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/AccountTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php new file mode 100644 index 0000000..cb17b7e --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php @@ -0,0 +1,67 @@ + + */ +class AccountTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Account + */ + protected $account; + + /** + * @inheritdoc + */ + protected function setUp() + { + $this->account = new Account(); + } + + /** + * Test the ownerId property. + */ + public function testOwnerId() + { + $self = $this->account->setOwnerId(42); + $this->assertSame($this->account, $self); + $this->assertEquals(42, $this->account->getOwnerId()); + } + + /** + * Test the username property. + */ + public function testUsername() + { + $self = $this->account->setUsername('mocked_username'); + $this->assertSame($this->account, $self); + $this->assertEquals('mocked_username', $this->account->getUsername()); + } + + /** + * Test the password property. + */ + public function testPassword() + { + $self = $this->account->setPassword('mocked_password'); + $this->assertSame($this->account, $self); + $this->assertEquals('mocked_password', $this->account->getPassword()); + } + + public function testSalt() + { + $this->assertNotEmpty($this->account->getSalt()); + } + + public function testApplications() + { + $self = $this->account->setApplications([]); + $this->assertSame($this->account, $self); + $this->assertEquals([], $this->account->getApplications()); + } +} From f4f2fad32be7218f8ae0a59dac5c6a985960c88a Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:40:28 +0100 Subject: [PATCH 05/25] [fix] Fix fluent setter --- src/Majora/Component/OAuth/Entity/Account.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Majora/Component/OAuth/Entity/Account.php b/src/Majora/Component/OAuth/Entity/Account.php index 6ecf4ca..7682366 100644 --- a/src/Majora/Component/OAuth/Entity/Account.php +++ b/src/Majora/Component/OAuth/Entity/Account.php @@ -183,9 +183,13 @@ public function getApplications() /** * @param array $applications + * + * @return self */ public function setApplications($applications) { $this->applications = $applications; + + return $this; } } From 7e3cdcbbac61741192329bc5d2ab2aa0a0a8e467 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:46:09 +0100 Subject: [PATCH 06/25] [test] Add getScope() method test --- .../Component/OAuth/Tests/Entity/AccountTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php index cb17b7e..c5a6d08 100644 --- a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php +++ b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php @@ -23,6 +23,18 @@ protected function setUp() $this->account = new Account(); } + /** + * Test getScopes() method. + */ + public function testScopes() + { + $expectedScopes = [ + 'id' => 'id', + 'default' => ['id', 'owner_id', 'username'], + ]; + $this->assertEquals($expectedScopes, $this->account->getScopes(), '', 0.0, 10, true); + } + /** * Test the ownerId property. */ From d416ad70b65fb49762c21fe1b850166742678ed4 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:09:36 +0100 Subject: [PATCH 07/25] [fix] replace SerializableTrait deprecation by NormalizableTrait --- src/Majora/Component/OAuth/Entity/AccessToken.php | 4 ++-- src/Majora/Component/OAuth/Entity/Account.php | 4 ++-- src/Majora/Component/OAuth/Entity/Application.php | 4 ++-- src/Majora/Component/OAuth/Entity/RefreshToken.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Majora/Component/OAuth/Entity/AccessToken.php b/src/Majora/Component/OAuth/Entity/AccessToken.php index 417da66..474ed14 100644 --- a/src/Majora/Component/OAuth/Entity/AccessToken.php +++ b/src/Majora/Component/OAuth/Entity/AccessToken.php @@ -8,14 +8,14 @@ use Majora\Component\OAuth\Model\RefreshTokenInterface; use Majora\Framework\Model\CollectionableInterface; use Majora\Framework\Model\CollectionableTrait; -use Majora\Framework\Serializer\Model\SerializableTrait; +use Majora\Framework\Normalizer\Model\NormalizableTrait; /** * Access token class. */ class AccessToken extends Token implements AccessTokenInterface, CollectionableInterface { - use CollectionableTrait, SerializableTrait; + use CollectionableTrait, NormalizableTrait; /** * @var RefreshTokenInterface diff --git a/src/Majora/Component/OAuth/Entity/Account.php b/src/Majora/Component/OAuth/Entity/Account.php index 7682366..2d01201 100644 --- a/src/Majora/Component/OAuth/Entity/Account.php +++ b/src/Majora/Component/OAuth/Entity/Account.php @@ -5,14 +5,14 @@ use Majora\Component\OAuth\Model\AccountInterface; use Majora\Framework\Model\CollectionableInterface; use Majora\Framework\Model\CollectionableTrait; -use Majora\Framework\Serializer\Model\SerializableTrait; +use Majora\Framework\Normalizer\Model\NormalizableTrait; /** * Basic implementation on AccountInterface. */ class Account implements AccountInterface, CollectionableInterface { - use CollectionableTrait, SerializableTrait; + use CollectionableTrait, NormalizableTrait; /** * @var int diff --git a/src/Majora/Component/OAuth/Entity/Application.php b/src/Majora/Component/OAuth/Entity/Application.php index fd1e8ad..f39ab58 100644 --- a/src/Majora/Component/OAuth/Entity/Application.php +++ b/src/Majora/Component/OAuth/Entity/Application.php @@ -5,14 +5,14 @@ use Majora\Component\OAuth\Model\ApplicationInterface; use Majora\Framework\Model\CollectionableInterface; use Majora\Framework\Model\CollectionableTrait; -use Majora\Framework\Serializer\Model\SerializableTrait; +use Majora\Framework\Normalizer\Model\NormalizableTrait; /** * Basic implementation on ApplicationInterface. */ class Application implements ApplicationInterface, CollectionableInterface { - use CollectionableTrait, SerializableTrait; + use CollectionableTrait, NormalizableTrait; /** * @var int diff --git a/src/Majora/Component/OAuth/Entity/RefreshToken.php b/src/Majora/Component/OAuth/Entity/RefreshToken.php index 85829b1..6f00a2e 100644 --- a/src/Majora/Component/OAuth/Entity/RefreshToken.php +++ b/src/Majora/Component/OAuth/Entity/RefreshToken.php @@ -5,14 +5,14 @@ use Majora\Component\OAuth\Model\RefreshTokenInterface; use Majora\Framework\Model\CollectionableInterface; use Majora\Framework\Model\CollectionableTrait; -use Majora\Framework\Serializer\Model\SerializableTrait; +use Majora\Framework\Normalizer\Model\NormalizableTrait; /** * Class RefreshToken is the default implementation of RefreshTokenInterface. */ class RefreshToken extends Token implements RefreshTokenInterface, CollectionableInterface { - use CollectionableTrait, SerializableTrait; + use CollectionableTrait, NormalizableTrait; /** * {@inheritdoc} From 1a8bbf1553b35b5ec78da4378591ebb8a27f9595 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 15:47:47 +0100 Subject: [PATCH 08/25] [test] Add Symfony PHP Unit Bridge --- composer.json | 3 ++- composer.lock | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 562ae86..c0d00ec 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ }, "require-dev": { "fabpot/php-cs-fixer": "^1.9", - "phpunit/phpunit": "~5.1" + "phpunit/phpunit": "~5.1", + "symfony/phpunit-bridge": "^3.0" }, "require": { "php": ">=5.6", diff --git a/composer.lock b/composer.lock index 56f1411..e59629d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "77df1d2735511f683bc3a75e7c4fd630", - "content-hash": "f6b51a231d8fcdf71b3816016f22eb31", + "hash": "13e591ddfbce60f08dea143e413098da", + "content-hash": "490f3823af1a08fe13c4b0be306021c4", "packages": [ { "name": "doctrine/annotations", @@ -555,6 +555,61 @@ ], "time": "2012-12-21 11:40:51" }, + { + "name": "symfony/phpunit-bridge", + "version": "v3.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/phpunit-bridge.git", + "reference": "4580ae86cde5497d38fc971192cd2c37e546eb4f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/4580ae86cde5497d38fc971192cd2c37e546eb4f", + "reference": "4580ae86cde5497d38fc971192cd2c37e546eb4f", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "suggest": { + "symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" + }, + "type": "symfony-bridge", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Bridge\\PhpUnit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony PHPUnit Bridge", + "homepage": "https://symfony.com", + "time": "2016-01-21 09:38:31" + }, { "name": "symfony/polyfill-intl-icu", "version": "v1.1.1", From 600d7b7fb310a04761d9f35cac131f86a4715faa Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 15:48:20 +0100 Subject: [PATCH 09/25] [test] Add test for Token --- .../OAuth/Tests/Entity/TokenTest.php | 221 ++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/TokenTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/TokenTest.php b/src/Majora/Component/OAuth/Tests/Entity/TokenTest.php new file mode 100644 index 0000000..fe81945 --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/TokenTest.php @@ -0,0 +1,221 @@ +prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $this->token = new MockedToken( + $this->application = $application->reveal(), + $this->account = $account->reveal(), + 42 + ); + } + + + /** + * Roles testing provider + */ + public function rolesProvider() + { + return [ + [ + ['ROLE_1', 'ROLE_3'], + ['ROLE_1', 'ROLE_2', 'ROLE_3'], + ['ROLE_1', 'ROLE_3'] + ], + [ + ['ROLE_1', 'ROLE_3'], + ['ROLE_1', 'ROLE_2'], + ['ROLE_1'] + ], + [ + ['ROLE_4', 'ROLE_3'], + ['ROLE_1', 'ROLE_2'], + [] + ], + [ + ['ROLE_1', 'ROLE_2', 'ROLE_3'], + ['ROLE_1', 'ROLE_2', 'ROLE_3'], + ['ROLE_1', 'ROLE_2', 'ROLE_3'] + ] + ]; + } + + /** + * Test the getRoles() method. + * + * @dataProvider rolesProvider + */ + public function testRoles(array $applicationRoles, array $accountRoles, array $expectedRoles) + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->shouldBeCalled(); + $application + ->getRoles() + ->willReturn($applicationRoles) + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->shouldBeCalled(); + $account + ->getRoles() + ->willReturn($accountRoles) + ->shouldBeCalled(); + + $token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42 + ); + + $this->assertEquals($expectedRoles, $token->getRoles(), '', 0.0, 10, true); + } + + /** + * Test the expiration datetime is the datetime when the token expires in. + */ + public function testExpireAt() + { + ClockMock::withClockMock(true); + + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $this->token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42 + ); + + $this->assertEquals(\DateTime::createFromFormat('U', time() + intval(42)), $this->token->getExpireAt()); + } + + /** + * Test if the expiration datetime given in constructor is equals to returned by the getter. + */ + public function testConstructorExpireAt() + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $this->token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42, + $expectedExpireAt = \DateTime::createFromFormat('U', time() + intval(42)) + ); + + $this->assertEquals($expectedExpireAt, $this->token->getExpireAt()); + } + + /** + * Test if the account given in constructor is equals to returned by the getter. + */ + public function testConstructorAccount() + { + $this->assertEquals($this->account, $this->token->getAccount()); + } + + /** + * Test if the application given in constructor is equals to returned by the getter. + */ + public function testConstructorApplication() + { + $this->assertEquals($this->application, $this->token->getApplication()); + } + + /** + * Test if the expiration seconds given in constructor is equals to returned by the getter. + */ + public function testConstructorExpireIn() + { + $this->assertEquals(42, $this->token->getExpireIn()); + } + + /** + * Test if the hash given in constructor is equals to returned by the getter. + */ + public function testConstructorHash() + { + $application = $this->prophesize(ApplicationInterface::class); + $account = $this->prophesize(AccountInterface::class); + + $this->token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42, + null, + 'mocked_hash' + ); + + $this->assertEquals('mocked_hash', $this->token->getHash()); + $this->assertEquals('mocked_hash', (string)$this->token); + } +} + +class MockedToken extends Token +{ +} From 05d37aaba8aec568aa9afe2dc1c8f6f18bdb47a3 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:21:59 +0100 Subject: [PATCH 10/25] [test] add test for the AccessToken entity --- .../OAuth/Tests/Entity/AccessTokenTest.php | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php new file mode 100644 index 0000000..41ea6e8 --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php @@ -0,0 +1,74 @@ + + */ +class AccessTokenTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test if the refresh token given in constructor is equals to returned by the getter. + */ + public function testConstructorRefreshToken() + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $refreshToken = $this->prophesize(RefreshTokenInterface::class); + + $token = new AccessToken( + $application->reveal(), + $account->reveal(), + 42, + null, + null, + $refreshToken->reveal() + ); + + $this->assertEquals($refreshToken->reveal(), $token->getRefreshToken()); + } + + /** + * Test getScopes() method. + */ + public function testScopes() + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $token = new AccessToken( + $application->reveal(), + $account->reveal() + ); + + $expectedScopes = [ + 'default' => ['id', 'hash', 'refresh_token', 'expire_in', 'application@id', 'account@id'], + ]; + $this->assertEquals($expectedScopes, $token->getScopes(), '', 0.0, 10, true); + } +} From 989c71fad83bd8c9f52f21b728678e44519d788b Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:39:54 +0100 Subject: [PATCH 11/25] [test] Add test for the Account entity --- .../OAuth/Tests/Entity/AccountTest.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/AccountTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php new file mode 100644 index 0000000..cb17b7e --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php @@ -0,0 +1,67 @@ + + */ +class AccountTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Account + */ + protected $account; + + /** + * @inheritdoc + */ + protected function setUp() + { + $this->account = new Account(); + } + + /** + * Test the ownerId property. + */ + public function testOwnerId() + { + $self = $this->account->setOwnerId(42); + $this->assertSame($this->account, $self); + $this->assertEquals(42, $this->account->getOwnerId()); + } + + /** + * Test the username property. + */ + public function testUsername() + { + $self = $this->account->setUsername('mocked_username'); + $this->assertSame($this->account, $self); + $this->assertEquals('mocked_username', $this->account->getUsername()); + } + + /** + * Test the password property. + */ + public function testPassword() + { + $self = $this->account->setPassword('mocked_password'); + $this->assertSame($this->account, $self); + $this->assertEquals('mocked_password', $this->account->getPassword()); + } + + public function testSalt() + { + $this->assertNotEmpty($this->account->getSalt()); + } + + public function testApplications() + { + $self = $this->account->setApplications([]); + $this->assertSame($this->account, $self); + $this->assertEquals([], $this->account->getApplications()); + } +} From 7d0a3563d36393bad13aa66cf6fb002b451053a1 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:46:09 +0100 Subject: [PATCH 12/25] [test] Add getScope() method test --- .../Component/OAuth/Tests/Entity/AccountTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php index cb17b7e..c5a6d08 100644 --- a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php +++ b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php @@ -23,6 +23,18 @@ protected function setUp() $this->account = new Account(); } + /** + * Test getScopes() method. + */ + public function testScopes() + { + $expectedScopes = [ + 'id' => 'id', + 'default' => ['id', 'owner_id', 'username'], + ]; + $this->assertEquals($expectedScopes, $this->account->getScopes(), '', 0.0, 10, true); + } + /** * Test the ownerId property. */ From b093a3d40dd7f4090bf1bdbc82f2e743e75391dc Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 17:06:29 +0100 Subject: [PATCH 13/25] [test] Add the test for the Application entity --- .../OAuth/Tests/Entity/ApplicationTest.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/ApplicationTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/ApplicationTest.php b/src/Majora/Component/OAuth/Tests/Entity/ApplicationTest.php new file mode 100644 index 0000000..b2074fd --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/ApplicationTest.php @@ -0,0 +1,107 @@ + + */ +class ApplicationTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Application + */ + protected $application; + + /** + * @inheritdoc + */ + protected function setUp() + { + $this->application = new Application(); + } + + /** + * Test getScopes() method. + */ + public function testScopes() + { + $expectedScopes = [ + 'id' => 'id', + 'default' => ['id', 'domain', 'allowed_scopes'], + ]; + $this->assertEquals($expectedScopes, $this->application->getScopes(), '', 0.0, 10, true); + } + + /** + * Test the apiKey property. + */ + public function testApiKey() + { + $self = $this->application->setApiKey('mocked_apikey'); + $this->assertSame($this->application, $self); + $this->assertEquals('mocked_apikey', $this->application->getApiKey()); + } + + /** + * Test the secret property. + */ + public function testSecret() + { + $self = $this->application->setSecret('mocked_secret'); + $this->assertSame($this->application, $self); + $this->assertEquals('mocked_secret', $this->application->getSecret()); + } + + /** + * Test the domain property. + */ + public function testDomain() + { + $self = $this->application->setDomain('mocked_domain'); + $this->assertSame($this->application, $self); + $this->assertEquals('mocked_domain', $this->application->getDomain()); + } + + /** + * Test the allowedScopes property. + */ + public function testAllowedScopes() + { + $self = $this->application->setAllowedScopes([]); + $this->assertSame($this->application, $self); + $this->assertEquals([], $this->application->getAllowedScopes()); + } + + /** + * Test the allowedGrantTypes property. + */ + public function testAllowedGrantTypes() + { + $self = $this->application->setAllowedGrantTypes([]); + $this->assertSame($this->application, $self); + $this->assertEquals([], $this->application->getAllowedGrantTypes()); + } + + /** + * Test roles property. + */ + public function testRoles() + { + $self = $this->application->setRoles([]); + $this->assertSame($this->application, $self); + $this->assertEquals([], $this->application->getRoles()); + } + + /** + * Test accounts property. + */ + public function testAccounts() + { + $self = $this->application->setAccounts([]); + $this->assertSame($this->application, $self); + $this->assertEquals([], $this->application->getAccounts()); + } +} From 99e53872c5d48d4fa71a3b5b75e2d7acfa3a477f Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 17:07:06 +0100 Subject: [PATCH 14/25] [fix] Fix fluent setter --- src/Majora/Component/OAuth/Entity/Application.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Majora/Component/OAuth/Entity/Application.php b/src/Majora/Component/OAuth/Entity/Application.php index f39ab58..e44d939 100644 --- a/src/Majora/Component/OAuth/Entity/Application.php +++ b/src/Majora/Component/OAuth/Entity/Application.php @@ -225,9 +225,13 @@ public function getAccounts() /** * @param array $accounts + * + * @return self */ public function setAccounts($accounts) { $this->accounts = $accounts; + + return $this; } } From 0974c1354ecfc4677fa9fec3373a081294d0c1dc Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 17:10:11 +0100 Subject: [PATCH 15/25] [fix] Fix fluent setter --- src/Majora/Component/OAuth/Entity/Application.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Majora/Component/OAuth/Entity/Application.php b/src/Majora/Component/OAuth/Entity/Application.php index fd1e8ad..713a892 100644 --- a/src/Majora/Component/OAuth/Entity/Application.php +++ b/src/Majora/Component/OAuth/Entity/Application.php @@ -225,9 +225,13 @@ public function getAccounts() /** * @param array $accounts + * + * @return self */ public function setAccounts($accounts) { $this->accounts = $accounts; + + return $this; } } From d3c19200ba5576797194ba28f45cdad6b4ad5f2a Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 15:47:47 +0100 Subject: [PATCH 16/25] [test] Add Symfony PHP Unit Bridge --- composer.json | 3 ++- composer.lock | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 562ae86..c0d00ec 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,8 @@ }, "require-dev": { "fabpot/php-cs-fixer": "^1.9", - "phpunit/phpunit": "~5.1" + "phpunit/phpunit": "~5.1", + "symfony/phpunit-bridge": "^3.0" }, "require": { "php": ">=5.6", diff --git a/composer.lock b/composer.lock index 56f1411..e59629d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "77df1d2735511f683bc3a75e7c4fd630", - "content-hash": "f6b51a231d8fcdf71b3816016f22eb31", + "hash": "13e591ddfbce60f08dea143e413098da", + "content-hash": "490f3823af1a08fe13c4b0be306021c4", "packages": [ { "name": "doctrine/annotations", @@ -555,6 +555,61 @@ ], "time": "2012-12-21 11:40:51" }, + { + "name": "symfony/phpunit-bridge", + "version": "v3.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/phpunit-bridge.git", + "reference": "4580ae86cde5497d38fc971192cd2c37e546eb4f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/phpunit-bridge/zipball/4580ae86cde5497d38fc971192cd2c37e546eb4f", + "reference": "4580ae86cde5497d38fc971192cd2c37e546eb4f", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "suggest": { + "symfony/debug": "For tracking deprecated interfaces usages at runtime with DebugClassLoader" + }, + "type": "symfony-bridge", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Bridge\\PhpUnit\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony PHPUnit Bridge", + "homepage": "https://symfony.com", + "time": "2016-01-21 09:38:31" + }, { "name": "symfony/polyfill-intl-icu", "version": "v1.1.1", From 3dace1e1c5572a934d82986d13674d0f4e03b38f Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 15:48:20 +0100 Subject: [PATCH 17/25] [test] Add test for Token --- .../OAuth/Tests/Entity/TokenTest.php | 221 ++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/TokenTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/TokenTest.php b/src/Majora/Component/OAuth/Tests/Entity/TokenTest.php new file mode 100644 index 0000000..fe81945 --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/TokenTest.php @@ -0,0 +1,221 @@ +prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $this->token = new MockedToken( + $this->application = $application->reveal(), + $this->account = $account->reveal(), + 42 + ); + } + + + /** + * Roles testing provider + */ + public function rolesProvider() + { + return [ + [ + ['ROLE_1', 'ROLE_3'], + ['ROLE_1', 'ROLE_2', 'ROLE_3'], + ['ROLE_1', 'ROLE_3'] + ], + [ + ['ROLE_1', 'ROLE_3'], + ['ROLE_1', 'ROLE_2'], + ['ROLE_1'] + ], + [ + ['ROLE_4', 'ROLE_3'], + ['ROLE_1', 'ROLE_2'], + [] + ], + [ + ['ROLE_1', 'ROLE_2', 'ROLE_3'], + ['ROLE_1', 'ROLE_2', 'ROLE_3'], + ['ROLE_1', 'ROLE_2', 'ROLE_3'] + ] + ]; + } + + /** + * Test the getRoles() method. + * + * @dataProvider rolesProvider + */ + public function testRoles(array $applicationRoles, array $accountRoles, array $expectedRoles) + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->shouldBeCalled(); + $application + ->getRoles() + ->willReturn($applicationRoles) + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->shouldBeCalled(); + $account + ->getRoles() + ->willReturn($accountRoles) + ->shouldBeCalled(); + + $token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42 + ); + + $this->assertEquals($expectedRoles, $token->getRoles(), '', 0.0, 10, true); + } + + /** + * Test the expiration datetime is the datetime when the token expires in. + */ + public function testExpireAt() + { + ClockMock::withClockMock(true); + + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $this->token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42 + ); + + $this->assertEquals(\DateTime::createFromFormat('U', time() + intval(42)), $this->token->getExpireAt()); + } + + /** + * Test if the expiration datetime given in constructor is equals to returned by the getter. + */ + public function testConstructorExpireAt() + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $this->token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42, + $expectedExpireAt = \DateTime::createFromFormat('U', time() + intval(42)) + ); + + $this->assertEquals($expectedExpireAt, $this->token->getExpireAt()); + } + + /** + * Test if the account given in constructor is equals to returned by the getter. + */ + public function testConstructorAccount() + { + $this->assertEquals($this->account, $this->token->getAccount()); + } + + /** + * Test if the application given in constructor is equals to returned by the getter. + */ + public function testConstructorApplication() + { + $this->assertEquals($this->application, $this->token->getApplication()); + } + + /** + * Test if the expiration seconds given in constructor is equals to returned by the getter. + */ + public function testConstructorExpireIn() + { + $this->assertEquals(42, $this->token->getExpireIn()); + } + + /** + * Test if the hash given in constructor is equals to returned by the getter. + */ + public function testConstructorHash() + { + $application = $this->prophesize(ApplicationInterface::class); + $account = $this->prophesize(AccountInterface::class); + + $this->token = new MockedToken( + $application->reveal(), + $account->reveal(), + 42, + null, + 'mocked_hash' + ); + + $this->assertEquals('mocked_hash', $this->token->getHash()); + $this->assertEquals('mocked_hash', (string)$this->token); + } +} + +class MockedToken extends Token +{ +} From aeaba503a3b7459be02ab0682960408591838f71 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:21:59 +0100 Subject: [PATCH 18/25] [test] add test for the AccessToken entity --- .../OAuth/Tests/Entity/AccessTokenTest.php | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php new file mode 100644 index 0000000..41ea6e8 --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php @@ -0,0 +1,74 @@ + + */ +class AccessTokenTest extends \PHPUnit_Framework_TestCase +{ + /** + * Test if the refresh token given in constructor is equals to returned by the getter. + */ + public function testConstructorRefreshToken() + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $refreshToken = $this->prophesize(RefreshTokenInterface::class); + + $token = new AccessToken( + $application->reveal(), + $account->reveal(), + 42, + null, + null, + $refreshToken->reveal() + ); + + $this->assertEquals($refreshToken->reveal(), $token->getRefreshToken()); + } + + /** + * Test getScopes() method. + */ + public function testScopes() + { + $application = $this->prophesize(ApplicationInterface::class); + $application + ->getSecret() + ->willReturn('mock_secret') + ->shouldBeCalled(); + + $account = $this->prophesize(AccountInterface::class); + $account + ->getPassword() + ->willReturn('mock_password') + ->shouldBeCalled(); + + $token = new AccessToken( + $application->reveal(), + $account->reveal() + ); + + $expectedScopes = [ + 'default' => ['id', 'hash', 'refresh_token', 'expire_in', 'application@id', 'account@id'], + ]; + $this->assertEquals($expectedScopes, $token->getScopes(), '', 0.0, 10, true); + } +} From 457ec5ca0e67b0febd6d150edc70d7bed06b2ab5 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:39:54 +0100 Subject: [PATCH 19/25] [test] Add test for the Account entity --- .../OAuth/Tests/Entity/AccountTest.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/AccountTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php new file mode 100644 index 0000000..cb17b7e --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php @@ -0,0 +1,67 @@ + + */ +class AccountTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Account + */ + protected $account; + + /** + * @inheritdoc + */ + protected function setUp() + { + $this->account = new Account(); + } + + /** + * Test the ownerId property. + */ + public function testOwnerId() + { + $self = $this->account->setOwnerId(42); + $this->assertSame($this->account, $self); + $this->assertEquals(42, $this->account->getOwnerId()); + } + + /** + * Test the username property. + */ + public function testUsername() + { + $self = $this->account->setUsername('mocked_username'); + $this->assertSame($this->account, $self); + $this->assertEquals('mocked_username', $this->account->getUsername()); + } + + /** + * Test the password property. + */ + public function testPassword() + { + $self = $this->account->setPassword('mocked_password'); + $this->assertSame($this->account, $self); + $this->assertEquals('mocked_password', $this->account->getPassword()); + } + + public function testSalt() + { + $this->assertNotEmpty($this->account->getSalt()); + } + + public function testApplications() + { + $self = $this->account->setApplications([]); + $this->assertSame($this->account, $self); + $this->assertEquals([], $this->account->getApplications()); + } +} From f7893d98c1a2540c5b0e043c4fe5fc7bdd52cc13 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:40:28 +0100 Subject: [PATCH 20/25] [fix] Fix fluent setter --- src/Majora/Component/OAuth/Entity/Account.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Majora/Component/OAuth/Entity/Account.php b/src/Majora/Component/OAuth/Entity/Account.php index 6ecf4ca..7682366 100644 --- a/src/Majora/Component/OAuth/Entity/Account.php +++ b/src/Majora/Component/OAuth/Entity/Account.php @@ -183,9 +183,13 @@ public function getApplications() /** * @param array $applications + * + * @return self */ public function setApplications($applications) { $this->applications = $applications; + + return $this; } } From 3de0b8473abe32412df2f19275df10d062e926ee Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:46:09 +0100 Subject: [PATCH 21/25] [test] Add getScope() method test --- .../Component/OAuth/Tests/Entity/AccountTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php index cb17b7e..c5a6d08 100644 --- a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php +++ b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php @@ -23,6 +23,18 @@ protected function setUp() $this->account = new Account(); } + /** + * Test getScopes() method. + */ + public function testScopes() + { + $expectedScopes = [ + 'id' => 'id', + 'default' => ['id', 'owner_id', 'username'], + ]; + $this->assertEquals($expectedScopes, $this->account->getScopes(), '', 0.0, 10, true); + } + /** * Test the ownerId property. */ From 1e01eb5921a52c2cfa27adcd67e97f2fe446548c Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:09:36 +0100 Subject: [PATCH 22/25] [fix] replace SerializableTrait deprecation by NormalizableTrait --- src/Majora/Component/OAuth/Entity/AccessToken.php | 4 ++-- src/Majora/Component/OAuth/Entity/Account.php | 4 ++-- src/Majora/Component/OAuth/Entity/Application.php | 4 ++-- src/Majora/Component/OAuth/Entity/RefreshToken.php | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Majora/Component/OAuth/Entity/AccessToken.php b/src/Majora/Component/OAuth/Entity/AccessToken.php index 417da66..474ed14 100644 --- a/src/Majora/Component/OAuth/Entity/AccessToken.php +++ b/src/Majora/Component/OAuth/Entity/AccessToken.php @@ -8,14 +8,14 @@ use Majora\Component\OAuth\Model\RefreshTokenInterface; use Majora\Framework\Model\CollectionableInterface; use Majora\Framework\Model\CollectionableTrait; -use Majora\Framework\Serializer\Model\SerializableTrait; +use Majora\Framework\Normalizer\Model\NormalizableTrait; /** * Access token class. */ class AccessToken extends Token implements AccessTokenInterface, CollectionableInterface { - use CollectionableTrait, SerializableTrait; + use CollectionableTrait, NormalizableTrait; /** * @var RefreshTokenInterface diff --git a/src/Majora/Component/OAuth/Entity/Account.php b/src/Majora/Component/OAuth/Entity/Account.php index 7682366..2d01201 100644 --- a/src/Majora/Component/OAuth/Entity/Account.php +++ b/src/Majora/Component/OAuth/Entity/Account.php @@ -5,14 +5,14 @@ use Majora\Component\OAuth\Model\AccountInterface; use Majora\Framework\Model\CollectionableInterface; use Majora\Framework\Model\CollectionableTrait; -use Majora\Framework\Serializer\Model\SerializableTrait; +use Majora\Framework\Normalizer\Model\NormalizableTrait; /** * Basic implementation on AccountInterface. */ class Account implements AccountInterface, CollectionableInterface { - use CollectionableTrait, SerializableTrait; + use CollectionableTrait, NormalizableTrait; /** * @var int diff --git a/src/Majora/Component/OAuth/Entity/Application.php b/src/Majora/Component/OAuth/Entity/Application.php index 713a892..e44d939 100644 --- a/src/Majora/Component/OAuth/Entity/Application.php +++ b/src/Majora/Component/OAuth/Entity/Application.php @@ -5,14 +5,14 @@ use Majora\Component\OAuth\Model\ApplicationInterface; use Majora\Framework\Model\CollectionableInterface; use Majora\Framework\Model\CollectionableTrait; -use Majora\Framework\Serializer\Model\SerializableTrait; +use Majora\Framework\Normalizer\Model\NormalizableTrait; /** * Basic implementation on ApplicationInterface. */ class Application implements ApplicationInterface, CollectionableInterface { - use CollectionableTrait, SerializableTrait; + use CollectionableTrait, NormalizableTrait; /** * @var int diff --git a/src/Majora/Component/OAuth/Entity/RefreshToken.php b/src/Majora/Component/OAuth/Entity/RefreshToken.php index 85829b1..6f00a2e 100644 --- a/src/Majora/Component/OAuth/Entity/RefreshToken.php +++ b/src/Majora/Component/OAuth/Entity/RefreshToken.php @@ -5,14 +5,14 @@ use Majora\Component\OAuth\Model\RefreshTokenInterface; use Majora\Framework\Model\CollectionableInterface; use Majora\Framework\Model\CollectionableTrait; -use Majora\Framework\Serializer\Model\SerializableTrait; +use Majora\Framework\Normalizer\Model\NormalizableTrait; /** * Class RefreshToken is the default implementation of RefreshTokenInterface. */ class RefreshToken extends Token implements RefreshTokenInterface, CollectionableInterface { - use CollectionableTrait, SerializableTrait; + use CollectionableTrait, NormalizableTrait; /** * {@inheritdoc} From dd54db9c570074d0ad6aa966b824727633e2fbb9 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 16:46:09 +0100 Subject: [PATCH 23/25] [test] Add getScope() method test --- .../Component/OAuth/Tests/Entity/AccountTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php index c5a6d08..1bbbf53 100644 --- a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php +++ b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php @@ -35,6 +35,18 @@ public function testScopes() $this->assertEquals($expectedScopes, $this->account->getScopes(), '', 0.0, 10, true); } + /** + * Test getScopes() method. + */ + public function testScopes() + { + $expectedScopes = [ + 'id' => 'id', + 'default' => ['id', 'owner_id', 'username'], + ]; + $this->assertEquals($expectedScopes, $this->account->getScopes(), '', 0.0, 10, true); + } + /** * Test the ownerId property. */ From a237cb8a489e5ae32c85eb33e84354a6fb5c37d5 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 17:06:29 +0100 Subject: [PATCH 24/25] [test] Add the test for the Application entity --- .../OAuth/Tests/Entity/ApplicationTest.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/Majora/Component/OAuth/Tests/Entity/ApplicationTest.php diff --git a/src/Majora/Component/OAuth/Tests/Entity/ApplicationTest.php b/src/Majora/Component/OAuth/Tests/Entity/ApplicationTest.php new file mode 100644 index 0000000..b2074fd --- /dev/null +++ b/src/Majora/Component/OAuth/Tests/Entity/ApplicationTest.php @@ -0,0 +1,107 @@ + + */ +class ApplicationTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var Application + */ + protected $application; + + /** + * @inheritdoc + */ + protected function setUp() + { + $this->application = new Application(); + } + + /** + * Test getScopes() method. + */ + public function testScopes() + { + $expectedScopes = [ + 'id' => 'id', + 'default' => ['id', 'domain', 'allowed_scopes'], + ]; + $this->assertEquals($expectedScopes, $this->application->getScopes(), '', 0.0, 10, true); + } + + /** + * Test the apiKey property. + */ + public function testApiKey() + { + $self = $this->application->setApiKey('mocked_apikey'); + $this->assertSame($this->application, $self); + $this->assertEquals('mocked_apikey', $this->application->getApiKey()); + } + + /** + * Test the secret property. + */ + public function testSecret() + { + $self = $this->application->setSecret('mocked_secret'); + $this->assertSame($this->application, $self); + $this->assertEquals('mocked_secret', $this->application->getSecret()); + } + + /** + * Test the domain property. + */ + public function testDomain() + { + $self = $this->application->setDomain('mocked_domain'); + $this->assertSame($this->application, $self); + $this->assertEquals('mocked_domain', $this->application->getDomain()); + } + + /** + * Test the allowedScopes property. + */ + public function testAllowedScopes() + { + $self = $this->application->setAllowedScopes([]); + $this->assertSame($this->application, $self); + $this->assertEquals([], $this->application->getAllowedScopes()); + } + + /** + * Test the allowedGrantTypes property. + */ + public function testAllowedGrantTypes() + { + $self = $this->application->setAllowedGrantTypes([]); + $this->assertSame($this->application, $self); + $this->assertEquals([], $this->application->getAllowedGrantTypes()); + } + + /** + * Test roles property. + */ + public function testRoles() + { + $self = $this->application->setRoles([]); + $this->assertSame($this->application, $self); + $this->assertEquals([], $this->application->getRoles()); + } + + /** + * Test accounts property. + */ + public function testAccounts() + { + $self = $this->application->setAccounts([]); + $this->assertSame($this->application, $self); + $this->assertEquals([], $this->application->getAccounts()); + } +} From f15d85c488710ed0fe2b24523893f2600f96c463 Mon Sep 17 00:00:00 2001 From: Raphael De Freitas Date: Fri, 18 Mar 2016 17:12:52 +0100 Subject: [PATCH 25/25] Rebase --- .../Component/OAuth/Tests/Entity/AccountTest.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php index 1bbbf53..c5a6d08 100644 --- a/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php +++ b/src/Majora/Component/OAuth/Tests/Entity/AccountTest.php @@ -35,18 +35,6 @@ public function testScopes() $this->assertEquals($expectedScopes, $this->account->getScopes(), '', 0.0, 10, true); } - /** - * Test getScopes() method. - */ - public function testScopes() - { - $expectedScopes = [ - 'id' => 'id', - 'default' => ['id', 'owner_id', 'username'], - ]; - $this->assertEquals($expectedScopes, $this->account->getScopes(), '', 0.0, 10, true); - } - /** * Test the ownerId property. */