Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
basz committed Mar 10, 2017
1 parent dc0160e commit 381852c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions tests/src/Container/ResourceServerMiddlewareFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Psr\Container\ContainerInterface;
use ZfrOAuth2\Server\Container\ResourceServerMiddlewareFactory;
use ZfrOAuth2\Server\Middleware\ResourceServerMiddleware;
use ZfrOAuth2\Server\Options\ServerOptions;
use ZfrOAuth2\Server\ResourceServerInterface;

/**
Expand All @@ -42,6 +43,11 @@ public function testCanCreateFromFactory()
->with(ResourceServerInterface::class)
->willReturn($this->createMock(ResourceServerInterface::class));

$container->expects($this->at(1))
->method('get')
->with(ServerOptions::class)
->willReturn(ServerOptions::fromArray());

$factory = new ResourceServerMiddlewareFactory();
$service = $factory($container);

Expand Down
7 changes: 4 additions & 3 deletions tests/src/Middleware/ResourceServerMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use ZfrOAuth2\Server\Exception\InvalidAccessTokenException;
use ZfrOAuth2\Server\Middleware\ResourceServerMiddleware;
use ZfrOAuth2\Server\Model\AccessToken;
use ZfrOAuth2\Server\Options\ServerOptions;
use ZfrOAuth2\Server\ResourceServer;

/**
Expand All @@ -39,7 +40,7 @@ class ResourceServerMiddlewareTest extends TestCase
public function testWillGetAccessTokenWithAccessTokenAsResult()
{
$resourceServer = $this->createMock(ResourceServer::class);
$middleware = new ResourceServerMiddleware($resourceServer);
$middleware = new ResourceServerMiddleware($resourceServer, ServerOptions::fromArray());
$accessToken = $this->createMock(AccessToken::class);
$request = $this->createMock(RequestInterface::class);
$response = $this->createMock(ResponseInterface::class);
Expand All @@ -65,7 +66,7 @@ public function testWillGetAccessTokenWithAccessTokenAsResult()
public function testWillGetAccessTokenWithNullAsResult()
{
$resourceServer = $this->createMock(ResourceServer::class);
$middleware = new ResourceServerMiddleware($resourceServer);
$middleware = new ResourceServerMiddleware($resourceServer, ServerOptions::fromArray());
$accessToken = null;
$request = $this->createMock(RequestInterface::class);
$response = $this->createMock(ResponseInterface::class);
Expand All @@ -91,7 +92,7 @@ public function testWillGetAccessTokenWithNullAsResult()
public function testWillCallGetAccessTokenWithException()
{
$resourceServer = $this->createMock(ResourceServer::class);
$middleware = new ResourceServerMiddleware($resourceServer);
$middleware = new ResourceServerMiddleware($resourceServer, ServerOptions::fromArray());
$request = $this->createMock(RequestInterface::class);
$response = $this->createMock(ResponseInterface::class);

Expand Down
3 changes: 3 additions & 0 deletions tests/src/Options/ServerOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function testDefaults()
$this->assertFalse($options->getRotateRefreshTokens());
$this->assertTrue($options->getRevokeRotatedRefreshTokens());
$this->assertEquals('owner', $options->getOwnerRequestAttribute());
$this->assertEquals('oauth_token', $options->getTokenRequestAttribute());
}

public function testGetters()
Expand All @@ -60,6 +61,7 @@ public function testGetters()
'owner_callable' => $callable,
'grants' => [ClientCredentialsGrant::class],
'owner_request_attribute' => 'something',
'token_request_attribute' => 'else',
]);

$this->assertEquals(300, $options->getAuthorizationCodeTtl());
Expand All @@ -70,5 +72,6 @@ public function testGetters()
$this->assertSame($callable, $options->getOwnerCallable());
$this->assertEquals([ClientCredentialsGrant::class], $options->getGrants());
$this->assertEquals('something', $options->getOwnerRequestAttribute());
$this->assertEquals('else', $options->getTokenRequestAttribute());
}
}

0 comments on commit 381852c

Please sign in to comment.