From add1aa59495230af6750facad0b98c80abeabb0c Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 16 Jan 2014 16:51:06 +0000 Subject: [PATCH] Updated tests --- phpunit.xml | 26 +--- tests/AbstractServerTest.php | 26 ++++ tests/AuthorizationTest.php | 107 ++++++++++++++ tests/Entities/AbstractTokenTest.php | 102 +++++++++++++ tests/Entities/AccessTokenTest.php | 51 +++++++ tests/Entities/ClientTest.php | 24 +++ tests/Entities/RefreshTokenTest.php | 75 ++++++++++ tests/Entities/ScopeTest.php | 20 +++ tests/Entities/SessionTest.php | 130 ++++++++++++++++ tests/ResourceTest.php | 214 +++++++++++++++++++++++++++ tests/Storage/AdapterTest.php | 24 +++ tests/Stubs/StubAbstractServer.php | 8 + tests/Stubs/StubAbstractToken.php | 16 ++ 13 files changed, 805 insertions(+), 18 deletions(-) create mode 100644 tests/AbstractServerTest.php create mode 100644 tests/AuthorizationTest.php create mode 100644 tests/Entities/AbstractTokenTest.php create mode 100644 tests/Entities/AccessTokenTest.php create mode 100644 tests/Entities/ClientTest.php create mode 100644 tests/Entities/RefreshTokenTest.php create mode 100644 tests/Entities/ScopeTest.php create mode 100644 tests/Entities/SessionTest.php create mode 100644 tests/ResourceTest.php create mode 100644 tests/Storage/AdapterTest.php create mode 100644 tests/Stubs/StubAbstractServer.php create mode 100644 tests/Stubs/StubAbstractToken.php diff --git a/phpunit.xml b/phpunit.xml index ec749a08..723a1f1f 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,27 +1,17 @@ - - tests/authorization - - - tests/resource - - - tests/util - + + ./tests/ + - - PEAR_INSTALL_DIR - PHP_LIBDIR - vendor - tests - testing - + + src + - - + + diff --git a/tests/AbstractServerTest.php b/tests/AbstractServerTest.php new file mode 100644 index 00000000..231105dc --- /dev/null +++ b/tests/AbstractServerTest.php @@ -0,0 +1,26 @@ +assertTrue($server->getRequest() instanceof \Symfony\Component\HttpFoundation\Request); + + $server2 = new StubAbstractServer(); + $server2->setRequest((new \Symfony\Component\HttpFoundation\Request)); + $this->assertTrue($server2->getRequest() instanceof \Symfony\Component\HttpFoundation\Request); + } + + function testGetStorageException() + { + $this->setExpectedException('League\OAuth2\Server\Exception\ServerException'); + $server = new StubAbstractServer(); + $server->getStorage('foobar'); + } +} \ No newline at end of file diff --git a/tests/AuthorizationTest.php b/tests/AuthorizationTest.php new file mode 100644 index 00000000..b267da90 --- /dev/null +++ b/tests/AuthorizationTest.php @@ -0,0 +1,107 @@ +getProperty('exceptionMessages'); + $exceptionMessages->setAccessible(true); + $v = $exceptionMessages->getValue(); + + $this->assertEquals($v['access_denied'], $m); + } + + public function testGetExceptionCode() + { + $this->assertEquals('access_denied', Authorization::getExceptionType(2)); + } + + public function testGetExceptionHttpHeaders() + { + $this->assertEquals(array('HTTP/1.1 401 Unauthorized'), Authorization::getExceptionHttpHeaders('access_denied')); + $this->assertEquals(array('HTTP/1.1 500 Internal Server Error'), Authorization::getExceptionHttpHeaders('server_error')); + $this->assertEquals(array('HTTP/1.1 501 Not Implemented'), Authorization::getExceptionHttpHeaders('unsupported_grant_type')); + $this->assertEquals(array('HTTP/1.1 400 Bad Request'), Authorization::getExceptionHttpHeaders('invalid_refresh')); + } + + public function testSetGet() + { + $server = new Authorization; + $server->requireScopeParam(true); + $server->requireStateParam(true); + $server->setDefaultScope('foobar'); + $server->setScopeDelimeter(','); + $server->setAccessTokenTTL(1); + + $grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface'); + $grant->shouldReceive('getIdentifier')->andReturn('foobar'); + $grant->shouldReceive('getResponseType')->andReturn('foobar'); + $grant->shouldReceive('setAuthorizationServer'); + + $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); + $scopeStorage->shouldReceive('setServer'); + + $server->addGrantType($grant); + $server->setScopeStorage($scopeStorage); + + $this->assertTrue($server->hasGrantType('foobar')); + $this->assertTrue($server->getGrantType('foobar') instanceof GrantTypeInterface); + $this->assertSame($server->getResponseTypes(), ['foobar']); + $this->assertTrue($server->scopeParamRequired()); + $this->assertTrue($server->stateParamRequired()); + $this->assertTrue($server->getStorage('scope') instanceof ScopeInterface); + $this->assertEquals('foobar', $server->getDefaultScope()); + $this->assertEquals(',', $server->getScopeDelimeter()); + $this->assertEquals(1, $server->getAccessTokenTTL()); + } + + public function testInvalidGrantType() + { + $this->setExpectedException('League\OAuth2\Server\Exception\InvalidGrantTypeException'); + $server = new Authorization; + $server->getGrantType('foobar'); + } + + public function testIssueAccessToken() + { + $grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface'); + $grant->shouldReceive('getIdentifier')->andReturn('foobar'); + $grant->shouldReceive('getResponseType')->andReturn('foobar'); + $grant->shouldReceive('setAuthorizationServer'); + $grant->shouldReceive('completeFlow')->andReturn(true); + + $_POST['grant_type'] = 'foobar'; + + $server = new Authorization; + $server->addGrantType($grant); + + $this->assertTrue($server->issueAccessToken()); + } + + public function testIssueAccessTokenEmptyGrantType() + { + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + $server = new Authorization; + $this->assertTrue($server->issueAccessToken()); + } + + public function testIssueAccessTokenInvalidGrantType() + { + $this->setExpectedException('League\OAuth2\Server\Exception\ClientException'); + + $_POST['grant_type'] = 'foobar'; + + $server = new Authorization; + $this->assertTrue($server->issueAccessToken()); + } +} diff --git a/tests/Entities/AbstractTokenTest.php b/tests/Entities/AbstractTokenTest.php new file mode 100644 index 00000000..099a05d5 --- /dev/null +++ b/tests/Entities/AbstractTokenTest.php @@ -0,0 +1,102 @@ +setToken('foobar'); + $entity->setExpireTime($time); + $entity->setSession((new Session($server))); + $entity->associateScope((new Scope($server))->setId('foo')); + + $this->assertEquals('foobar', $entity->getToken()); + $this->assertEquals($time, $entity->getExpireTime()); + $this->assertTrue($entity->getSession() instanceof Session); + $this->assertTrue($entity->hasScope('foo')); + + $result = $entity->getScopes(); + $this->assertTrue(isset($result['foo'])); + } + + public function testGetSession() + { + $server = new Authorization(); + + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('getByAccessToken')->andReturn( + (new Session($server)) + ); + $sessionStorage->shouldReceive('setServer'); + + $server->setSessionStorage($sessionStorage); + + $entity = new StubAbstractToken($server); + $this->assertTrue($entity->getSession() instanceof Session); + } + + public function testGetScopes() + { + $server = new Authorization(); + + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('getScopes')->andReturn( + [] + ); + $accessTokenStorage->shouldReceive('setServer'); + + $server->setAccessTokenStorage($accessTokenStorage); + + $entity = new StubAbstractToken($server); + $this->assertEquals($entity->getScopes(), []); + } + + public function testHasScopes() + { + $server = new Authorization(); + + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('getScopes')->andReturn( + [] + ); + $accessTokenStorage->shouldReceive('setServer'); + + $server->setAccessTokenStorage($accessTokenStorage); + + $entity = new StubAbstractToken($server); + $this->assertFalse($entity->hasScope('foo')); + } + + public function testFormatScopes() + { + $server = M::mock('League\OAuth2\Server\AbstractServer'); + + $entity = new StubAbstractToken($server); + $reflectedEntity = new \ReflectionClass('LeagueTests\Stubs\StubAbstractToken'); + $method = $reflectedEntity->getMethod('formatScopes'); + $method->setAccessible(true); + + $scopes = [ + (new Scope($server))->setId('scope1')->setDescription('foo'), + (new Scope($server))->setId('scope2')->setDescription('bar') + ]; + + $result = $method->invokeArgs($entity, [$scopes]); + + $this->assertTrue(isset($result['scope1'])); + $this->assertTrue(isset($result['scope2'])); + $this->assertTrue($result['scope1'] instanceof Scope); + $this->assertTrue($result['scope2'] instanceof Scope); + } +} diff --git a/tests/Entities/AccessTokenTest.php b/tests/Entities/AccessTokenTest.php new file mode 100644 index 00000000..027fd633 --- /dev/null +++ b/tests/Entities/AccessTokenTest.php @@ -0,0 +1,51 @@ +shouldReceive('create'); + $accessTokenStorage->shouldReceive('associateScope'); + $accessTokenStorage->shouldReceive('setServer'); + $accessTokenStorage->shouldReceive('getScopes')->andReturn([ + (new Scope($server))->setId('foo') + ]); + + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('getByAccessToken')->andReturn( + (new Session($server)) + ); + $sessionStorage->shouldReceive('setServer'); + + $server->setAccessTokenStorage($accessTokenStorage); + $server->setSessionStorage($sessionStorage); + + $entity = new AccessToken($server); + $this->assertTrue($entity->save() instanceof AccessToken); + } + + function testExpire() + { + $server = new Authorization(); + + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('delete'); + $accessTokenStorage->shouldReceive('setServer'); + + $server->setAccessTokenStorage($accessTokenStorage); + + $entity = new AccessToken($server); + $this->assertSame($entity->expire(), null); + } +} diff --git a/tests/Entities/ClientTest.php b/tests/Entities/ClientTest.php new file mode 100644 index 00000000..71e39fe5 --- /dev/null +++ b/tests/Entities/ClientTest.php @@ -0,0 +1,24 @@ +setId('foobar'); + $client->setSecret('barfoo'); + $client->setName('Test Client'); + $client->setRedirectUri('http://foo/bar'); + + $this->assertEquals('foobar', $client->getId()); + $this->assertEquals('barfoo', $client->getSecret()); + $this->assertEquals('Test Client', $client->getName()); + $this->assertEquals('http://foo/bar', $client->getRedirectUri()); + } +} \ No newline at end of file diff --git a/tests/Entities/RefreshTokenTest.php b/tests/Entities/RefreshTokenTest.php new file mode 100644 index 00000000..e762326c --- /dev/null +++ b/tests/Entities/RefreshTokenTest.php @@ -0,0 +1,75 @@ +$property; + }, $object, $object)->__invoke(); + + return $value; + }; + + $server = M::mock('League\OAuth2\Server\AbstractServer'); + $entity = new RefreshToken($server); + $entity->setAccessToken((new AccessToken($server))); + + $this->assertTrue($reader($entity, 'accessToken') instanceof AccessToken); + } + + function testSave() + { + $server = new Authorization(); + + $refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface'); + $refreshTokenStorage->shouldReceive('create'); + $refreshTokenStorage->shouldReceive('setServer'); + $refreshTokenStorage->shouldReceive('associateScope'); + + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('setServer'); + $accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn( + (new AccessToken($server))->setToken('foobar') + ); + $accessTokenStorage->shouldReceive('getScopes')->andReturn([ + (new Scope($server))->setId('foo') + ]); + + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('getByAccessToken')->andReturn( + (new Session($server)) + ); + $sessionStorage->shouldReceive('setServer'); + + $server->setAccessTokenStorage($accessTokenStorage); + $server->setRefreshTokenStorage($refreshTokenStorage); + + $entity = new RefreshToken($server); + $this->assertSame(null, $entity->save()); + } + + function testExpire() + { + $server = new Authorization(); + + $refreshTokenStorage = M::mock('League\OAuth2\Server\Storage\RefreshTokenInterface'); + $refreshTokenStorage->shouldReceive('delete'); + $refreshTokenStorage->shouldReceive('setServer'); + + $server->setRefreshTokenStorage($refreshTokenStorage); + + $entity = new RefreshToken($server); + $this->assertSame($entity->expire(), null); + } +} diff --git a/tests/Entities/ScopeTest.php b/tests/Entities/ScopeTest.php new file mode 100644 index 00000000..372c7c67 --- /dev/null +++ b/tests/Entities/ScopeTest.php @@ -0,0 +1,20 @@ +setId('foobar'); + $scope->setDescription('barfoo'); + + $this->assertEquals('foobar', $scope->getId()); + $this->assertEquals('barfoo', $scope->getDescription()); + } +} \ No newline at end of file diff --git a/tests/Entities/SessionTest.php b/tests/Entities/SessionTest.php new file mode 100644 index 00000000..100001dd --- /dev/null +++ b/tests/Entities/SessionTest.php @@ -0,0 +1,130 @@ +setId('foobar'); + $entity->setOwner('user', 123); + $entity->associateAccessToken((new AccessToken($server))); + $entity->associateRefreshToken((new RefreshToken($server))); + $entity->associateClient((new Client($server))); + $entity->associateScope((new Scope($server))->setId('foo')); + // $entity->associateAuthCode((new AuthCode($server))); + + $reader = function & ($object, $property) { + $value = & \Closure::bind(function & () use ($property) { + return $this->$property; + }, $object, $object)->__invoke(); + + return $value; + }; + + $this->assertEquals('foobar', $entity->getId()); + $this->assertEquals('user', $entity->getOwnerType()); + $this->assertEquals(123, $entity->getOwnerId()); + $this->assertTrue($reader($entity, 'accessToken') instanceof AccessToken); + $this->assertTrue($reader($entity, 'refreshToken') instanceof RefreshToken); + $this->assertTrue($entity->getClient() instanceof Client); + $this->assertTrue($entity->hasScope('foo')); + // $this->assertTrue($reader($entity, 'authCode') instanceof AuthCode); + } + + public function testFormatScopes() + { + $server = M::mock('League\OAuth2\Server\AbstractServer'); + + $entity = new Session($server); + $reflectedEntity = new \ReflectionClass('League\OAuth2\Server\Entity\Session'); + $method = $reflectedEntity->getMethod('formatScopes'); + $method->setAccessible(true); + + $scopes = [ + (new Scope($server))->setId('scope1')->setDescription('foo'), + (new Scope($server))->setId('scope2')->setDescription('bar') + ]; + + $result = $method->invokeArgs($entity, [$scopes]); + + $this->assertTrue(isset($result['scope1'])); + $this->assertTrue(isset($result['scope2'])); + $this->assertTrue($result['scope1'] instanceof Scope); + $this->assertTrue($result['scope2'] instanceof Scope); + } + + public function testGetScopes() + { + $server = new Authorization(); + + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('setServer'); + $server->setAccessTokenStorage($accessTokenStorage); + + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('getScopes')->andReturn( + [] + ); + $sessionStorage->shouldReceive('setServer'); + $server->setSessionStorage($sessionStorage); + + $entity = new Session($server); + $this->assertEquals($entity->getScopes(), []); + } + + public function testHasScopes() + { + $server = new Authorization(); + + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('setServer'); + $server->setAccessTokenStorage($accessTokenStorage); + + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('getScopes')->andReturn( + [] + ); + $sessionStorage->shouldReceive('setServer'); + $server->setSessionStorage($sessionStorage); + + $entity = new Session($server); + $this->assertFalse($entity->hasScope('foo')); + } + + function testSave() + { + $server = new Authorization(); + + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('create'); + $sessionStorage->shouldReceive('associateScope'); + $sessionStorage->shouldReceive('setServer'); + $sessionStorage->shouldReceive('getScopes')->andReturn([ + (new Scope($server))->setId('foo') + ]); + + $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); + $clientStorage->shouldReceive('getBySession')->andReturn( + (new Client($server))->setId('foo') + ); + $clientStorage->shouldReceive('setServer'); + + $server->setSessionStorage($sessionStorage); + $server->setClientStorage($clientStorage); + + $entity = new Session($server); + $this->assertEquals(null, $entity->save()); + } +} \ No newline at end of file diff --git a/tests/ResourceTest.php b/tests/ResourceTest.php new file mode 100644 index 00000000..aaf276e0 --- /dev/null +++ b/tests/ResourceTest.php @@ -0,0 +1,214 @@ +shouldReceive('setServer'); + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('setServer'); + $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); + $clientStorage->shouldReceive('setServer'); + $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); + $scopeStorage->shouldReceive('setServer'); + + $server = new Resource( + $sessionStorage, + $accessTokenStorage, + $clientStorage, + $scopeStorage + ); + + return $server; + } + + function testGetSet() + { + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('setServer'); + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('setServer'); + $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); + $clientStorage->shouldReceive('setServer'); + $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); + $scopeStorage->shouldReceive('setServer'); + + $server = new Resource( + $sessionStorage, + $accessTokenStorage, + $clientStorage, + $scopeStorage + ); + } + + public function testDetermineAccessTokenMissingToken() + { + $this->setExpectedException('League\OAuth2\Server\Exception\InvalidAccessTokenException'); + + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('setServer'); + + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('setServer'); + $accessTokenStorage->shouldReceive('get')->andReturn(false); + + $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); + $clientStorage->shouldReceive('setServer'); + + $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); + $scopeStorage->shouldReceive('setServer'); + + $server = new Resource( + $sessionStorage, + $accessTokenStorage, + $clientStorage, + $scopeStorage + ); + + $request = new \Symfony\Component\HttpFoundation\Request(); + $request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([ + 'HTTP_AUTHORIZATION' => 'Bearer' + ]); + $server->setRequest($request); + + $reflector = new \ReflectionClass($server); + $method = $reflector->getMethod('determineAccessToken'); + $method->setAccessible(true); + + $method->invoke($server); + } + + public function testDetermineAccessTokenBrokenCurlRequest() + { + $this->setExpectedException('League\OAuth2\Server\Exception\InvalidAccessTokenException'); + + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('setServer'); + + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('setServer'); + $accessTokenStorage->shouldReceive('get')->andReturn(false); + + $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); + $clientStorage->shouldReceive('setServer'); + + $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); + $scopeStorage->shouldReceive('setServer'); + + $server = new Resource( + $sessionStorage, + $accessTokenStorage, + $clientStorage, + $scopeStorage + ); + + $request = new \Symfony\Component\HttpFoundation\Request(); + $request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([ + 'Authorization' => 'Bearer, Bearer abcdef' + ]); + $server->setRequest($request); + + $reflector = new \ReflectionClass($server); + $method = $reflector->getMethod('determineAccessToken'); + $method->setAccessible(true); + + $method->invoke($server); + } + + public function testIsValidNotValid() + { + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('setServer'); + + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('setServer'); + $accessTokenStorage->shouldReceive('get')->andReturn(false); + + $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); + $clientStorage->shouldReceive('setServer'); + + $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); + $scopeStorage->shouldReceive('setServer'); + + $server = new Resource( + $sessionStorage, + $accessTokenStorage, + $clientStorage, + $scopeStorage + ); + + $this->assertFalse($server->isValid()); + } + + public function testIsValid() + { + $sessionStorage = M::mock('League\OAuth2\Server\Storage\SessionInterface'); + $sessionStorage->shouldReceive('setServer'); + + $accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface'); + $accessTokenStorage->shouldReceive('setServer'); + + $clientStorage = M::mock('League\OAuth2\Server\Storage\ClientInterface'); + $clientStorage->shouldReceive('setServer'); + + $scopeStorage = M::mock('League\OAuth2\Server\Storage\ScopeInterface'); + $scopeStorage->shouldReceive('setServer'); + + $server = new Resource( + $sessionStorage, + $accessTokenStorage, + $clientStorage, + $scopeStorage + ); + + $server->setTokenKey('at'); + + $accessTokenStorage->shouldReceive('get')->andReturn( + (new AccessToken($server))->setToken('abcdef') + ); + + $accessTokenStorage->shouldReceive('getScopes')->andReturn([ + (new Scope($server))->setId('foo'), + (new Scope($server))->setId('bar') + ]); + + $sessionStorage->shouldReceive('getByAccessToken')->andReturn( + (new Session($server))->setId('foobar')->setOwner('user', 123) + ); + + $clientStorage->shouldReceive('getBySession')->andReturn( + (new Client($server))->setId('testapp') + ); + + $request = new \Symfony\Component\HttpFoundation\Request(); + $request->headers = new \Symfony\Component\HttpFoundation\ParameterBag([ + 'Authorization' => 'Bearer abcdef' + ]); + $server->setRequest($request); + + $this->assertTrue($server->isValid()); + $this->assertEquals('at', $server->getTokenKey()); + $this->assertEquals(123, $server->getOwnerId()); + $this->assertEquals('user', $server->getOwnerType()); + $this->assertEquals('abcdef', $server->getAccessToken()); + $this->assertEquals('testapp', $server->getClientId()); + $this->assertTrue($server->hasScope('foo')); + $this->assertTrue($server->hasScope('bar')); + $this->assertTrue($server->hasScope(['foo', 'bar'])); + $this->assertTrue(isset($server->getScopes()['foo'])); + $this->assertTrue(isset($server->getScopes()['bar'])); + $this->assertFalse($server->hasScope(['foobar'])); + $this->assertFalse($server->hasScope('foobar')); + } +} diff --git a/tests/Storage/AdapterTest.php b/tests/Storage/AdapterTest.php new file mode 100644 index 00000000..a96f1564 --- /dev/null +++ b/tests/Storage/AdapterTest.php @@ -0,0 +1,24 @@ +getMethod('setServer'); + $setMethod->setAccessible(true); + $setMethod->invokeArgs($adapter, [new StubAbstractServer]); + $getMethod = $reflector->getMethod('getServer'); + $getMethod->setAccessible(true); + + $this->assertTrue($getMethod->invoke($adapter) instanceof StubAbstractServer); + } +} \ No newline at end of file diff --git a/tests/Stubs/StubAbstractServer.php b/tests/Stubs/StubAbstractServer.php new file mode 100644 index 00000000..31a6641e --- /dev/null +++ b/tests/Stubs/StubAbstractServer.php @@ -0,0 +1,8 @@ +