Skip to content
This repository was archived by the owner on Jul 9, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e143951
[test] Add Symfony PHP Unit Bridge
Mar 18, 2016
28ee3b2
[test] Add test for Token
Mar 18, 2016
aaed56a
[test] add test for the AccessToken entity
Mar 18, 2016
155e5ef
[test] Add test for the Account entity
Mar 18, 2016
f4f2fad
[fix] Fix fluent setter
Mar 18, 2016
7e3cdcb
[test] Add getScope() method test
Mar 18, 2016
d416ad7
[fix] replace SerializableTrait deprecation by NormalizableTrait
Mar 18, 2016
1a8bbf1
[test] Add Symfony PHP Unit Bridge
Mar 18, 2016
600d7b7
[test] Add test for Token
Mar 18, 2016
05d37aa
[test] add test for the AccessToken entity
Mar 18, 2016
989c71f
[test] Add test for the Account entity
Mar 18, 2016
7d0a356
[test] Add getScope() method test
Mar 18, 2016
b6d8722
Merge branch 'unit-test-entity' of github.com:LinkValue/MajoraOAuthSe…
Mar 18, 2016
b093a3d
[test] Add the test for the Application entity
Mar 18, 2016
99e5387
[fix] Fix fluent setter
Mar 18, 2016
0974c13
[fix] Fix fluent setter
Mar 18, 2016
d3c1920
[test] Add Symfony PHP Unit Bridge
Mar 18, 2016
3dace1e
[test] Add test for Token
Mar 18, 2016
aeaba50
[test] add test for the AccessToken entity
Mar 18, 2016
457ec5c
[test] Add test for the Account entity
Mar 18, 2016
f7893d9
[fix] Fix fluent setter
Mar 18, 2016
3de0b84
[test] Add getScope() method test
Mar 18, 2016
1e01eb5
[fix] replace SerializableTrait deprecation by NormalizableTrait
Mar 18, 2016
dd54db9
[test] Add getScope() method test
Mar 18, 2016
a237cb8
[test] Add the test for the Application entity
Mar 18, 2016
f15d85c
Rebase
Mar 18, 2016
244c5b9
Rebase
Mar 18, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
59 changes: 57 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Majora/Component/OAuth/Entity/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/Majora/Component/OAuth/Entity/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -183,9 +183,13 @@ public function getApplications()

/**
* @param array $applications
*
* @return self
*/
public function setApplications($applications)
{
$this->applications = $applications;

return $this;
}
}
8 changes: 6 additions & 2 deletions src/Majora/Component/OAuth/Entity/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -225,9 +225,13 @@ public function getAccounts()

/**
* @param array $accounts
*
* @return self
*/
public function setAccounts($accounts)
{
$this->accounts = $accounts;

return $this;
}
}
4 changes: 2 additions & 2 deletions src/Majora/Component/OAuth/Entity/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
74 changes: 74 additions & 0 deletions src/Majora/Component/OAuth/Tests/Entity/AccessTokenTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
namespace Majora\Component\OAuth\Tests\Entity;

use Majora\Component\OAuth\Entity\AccessToken;
use Majora\Component\OAuth\Model\AccountInterface;
use Majora\Component\OAuth\Model\ApplicationInterface;
use Majora\Component\OAuth\Model\RefreshTokenInterface;

/**
* Class AccessTokenTest
*
* @author Raphael De Freitas <raphael@de-freitas.net>
*/
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);
}
}
79 changes: 79 additions & 0 deletions src/Majora/Component/OAuth/Tests/Entity/AccountTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
namespace Majora\Component\OAuth\Tests\Entity;

use Majora\Component\OAuth\Entity\Account;

/**
* Class AccountTest
*
* @author Raphael De Freitas <raphael@de-freitas.net>
*/
class AccountTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Account
*/
protected $account;

/**
* @inheritdoc
*/
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.
*/
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());
}
}
Loading