100% test coverage

This commit is contained in:
Alex Bilbie
2014-06-20 14:29:47 +01:00
parent f24d1be3e9
commit 9af1d2a201
4 changed files with 65 additions and 5 deletions

View File

@@ -198,4 +198,55 @@ class ClientCredentialsGrantTest extends \PHPUnit_Framework_TestCase
$server->addGrantType($grant);
$server->issueAccessToken();
}
public function testClientNotAuthorizedToUseGrant()
{
$this->setExpectedException('\League\OAuth2\Server\Exception\UnauthorizedClientException');
$_POST = [
'grant_type' => 'client_credentials',
'client_id' => 'testapp',
'client_secret' => 'foobar',
'scope' => 'foo'
];
$server = new AuthorizationServer;
$grant = new ClientCredentialsGrant;
$clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface');
$clientStorage->shouldReceive('setServer');
$clientStorage->shouldReceive('get')->andThrow(
new \League\OAuth2\Server\Exception\UnauthorizedClientException
);
$sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface');
$sessionStorage->shouldReceive('setServer');
// $sessionStorage->shouldReceive('create')->andreturn(123);
// $sessionStorage->shouldReceive('getScopes')->shouldReceive('getScopes')->andReturn([
// (new ScopeEntity($server))->setId('foo')
// ]);
// $sessionStorage->shouldReceive('associateScope');
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
$accessTokenStorage->shouldReceive('setServer');
// $accessTokenStorage->shouldReceive('create');
// $accessTokenStorage->shouldReceive('getScopes')->andReturn([
// (new ScopeEntity($server))->setId('foo')
// ]);
// $accessTokenStorage->shouldReceive('associateScope');
$scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface');
$scopeStorage->shouldReceive('setServer');
$scopeStorage->shouldReceive('get')->andReturn(
(new ScopeEntity($server))->setId('foo')
);
$server->setClientStorage($clientStorage);
$server->setScopeStorage($scopeStorage);
$server->setSessionStorage($sessionStorage);
$server->setAccessTokenStorage($accessTokenStorage);
$server->addGrantType($grant);
$server->issueAccessToken();
}
}