From 1911c3d47fe4b6d153f1183ff859952e712f239e Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Fri, 21 Sep 2018 17:04:25 +0200 Subject: [PATCH 01/10] WIP: improving unit tests --- test/Entity/AccessTokenEntityTest.php | 24 +++++++++ test/Entity/AuthCodeEntityTest.php | 24 +++++++++ test/Entity/ClientEntityTest.php | 51 +++++++++++++++++++ test/Entity/RefreshTokenEntityTest.php | 24 +++++++++ test/Entity/RevokableTraitTest.php | 27 ++++++++++ test/Entity/ScopeEntityTest.php | 34 +++++++++++++ test/Entity/TimestampableTraitTest.php | 43 ++++++++++++++++ test/Entity/UserEntityTest.php | 37 ++++++++++++++ .../Repository/Pdo/AbstractRepositoryTest.php | 2 +- .../Pdo/AccessTokenRepositoryFactoryTest.php | 40 +++++++++++++++ .../Pdo/AuthCodeRepositoryFactoryTest.php | 40 +++++++++++++++ .../Pdo/ClientRepositoryFactoryTest.php | 40 +++++++++++++++ .../Pdo/RefreshTokenRepositoryFactoryTest.php | 40 +++++++++++++++ .../Pdo/ScopeRepositoryFactoryTest.php | 40 +++++++++++++++ 14 files changed, 465 insertions(+), 1 deletion(-) create mode 100644 test/Entity/AccessTokenEntityTest.php create mode 100644 test/Entity/AuthCodeEntityTest.php create mode 100644 test/Entity/ClientEntityTest.php create mode 100644 test/Entity/RefreshTokenEntityTest.php create mode 100644 test/Entity/RevokableTraitTest.php create mode 100644 test/Entity/ScopeEntityTest.php create mode 100644 test/Entity/TimestampableTraitTest.php create mode 100644 test/Entity/UserEntityTest.php create mode 100644 test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php create mode 100644 test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php create mode 100644 test/Repository/Pdo/ClientRepositoryFactoryTest.php create mode 100644 test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php create mode 100644 test/Repository/Pdo/ScopeRepositoryFactoryTest.php diff --git a/test/Entity/AccessTokenEntityTest.php b/test/Entity/AccessTokenEntityTest.php new file mode 100644 index 0000000..7be3ca7 --- /dev/null +++ b/test/Entity/AccessTokenEntityTest.php @@ -0,0 +1,24 @@ +assertInstanceOf(AccessTokenEntityInterface::class, $entity); + } +} diff --git a/test/Entity/AuthCodeEntityTest.php b/test/Entity/AuthCodeEntityTest.php new file mode 100644 index 0000000..2ab7530 --- /dev/null +++ b/test/Entity/AuthCodeEntityTest.php @@ -0,0 +1,24 @@ +assertInstanceOf(AuthCodeEntityInterface::class, $entity); + } +} diff --git a/test/Entity/ClientEntityTest.php b/test/Entity/ClientEntityTest.php new file mode 100644 index 0000000..4ea2ba7 --- /dev/null +++ b/test/Entity/ClientEntityTest.php @@ -0,0 +1,51 @@ +entity = new ClientEntity('foo', 'bar', 'http://localhost'); + } + public function testConstructor() + { + $this->assertInstanceOf(ClientEntityInterface::class, $this->entity); + } + + public function testSecret() + { + $this->entity->setSecret('secret'); + $this->assertEquals('secret', $this->entity->getSecret()); + } + + public function testPersonalAccessClient() + { + $this->entity->setPersonalAccessClient(true); + $this->assertTrue($this->entity->hasPersonalAccessClient()); + + $this->entity->setPersonalAccessClient(false); + $this->assertFalse($this->entity->hasPersonalAccessClient()); + } + + public function testPasswordClient() + { + $this->entity->setPasswordClient(true); + $this->assertTrue($this->entity->hasPasswordClient()); + + $this->entity->setPasswordClient(false); + $this->assertFalse($this->entity->hasPasswordClient()); + } +} diff --git a/test/Entity/RefreshTokenEntityTest.php b/test/Entity/RefreshTokenEntityTest.php new file mode 100644 index 0000000..06f8a2c --- /dev/null +++ b/test/Entity/RefreshTokenEntityTest.php @@ -0,0 +1,24 @@ +assertInstanceOf(RefreshTokenEntityInterface::class, $entity); + } +} diff --git a/test/Entity/RevokableTraitTest.php b/test/Entity/RevokableTraitTest.php new file mode 100644 index 0000000..60e0931 --- /dev/null +++ b/test/Entity/RevokableTraitTest.php @@ -0,0 +1,27 @@ +getMockForTrait(RevokableTrait::class); + + $mock->setRevoked(true); + $this->assertTrue($mock->isRevoked()); + $mock->setRevoked(false); + $this->assertFalse($mock->isRevoked()); + } +} diff --git a/test/Entity/ScopeEntityTest.php b/test/Entity/ScopeEntityTest.php new file mode 100644 index 0000000..0cfa65c --- /dev/null +++ b/test/Entity/ScopeEntityTest.php @@ -0,0 +1,34 @@ +entity = new ScopeEntity(); + } + + public function testConstructor() + { + $this->assertInstanceOf(ScopeEntityInterface::class, $this->entity); + } + + public function testJsonSerialize() + { + $this->entity->setIdentifier('foo'); + $this->assertEquals('"foo"', json_encode($this->entity)); + } +} diff --git a/test/Entity/TimestampableTraitTest.php b/test/Entity/TimestampableTraitTest.php new file mode 100644 index 0000000..59c6a94 --- /dev/null +++ b/test/Entity/TimestampableTraitTest.php @@ -0,0 +1,43 @@ +trait = $this->getMockForTrait(TimestampableTrait::class); + } + + public function testCreatedAt() + { + $now = new DateTime(); + $this->trait->setCreatedAt($now); + $this->assertEquals($now, $this->trait->getCreatedAt()); + } + + public function testUpdatedAt() + { + $now = new DateTime(); + $this->trait->setUpdatedAt($now); + $this->assertEquals($now, $this->trait->getUpdatedAt()); + } + + public function testTimestampOnCreate() + { + $this->trait->timestampOnCreate(); + $this->assertNotEmpty($this->trait->getCreatedAt()); + } +} diff --git a/test/Entity/UserEntityTest.php b/test/Entity/UserEntityTest.php new file mode 100644 index 0000000..c7b10bd --- /dev/null +++ b/test/Entity/UserEntityTest.php @@ -0,0 +1,37 @@ +entity = new UserEntity('foo'); + } + + /** + * @expectedException ArgumentCountError + */ + public function testConstructorWithoutParam() + { + $entity = new UserEntity(); + } + + public function testConstructor() + { + $this->assertInstanceOf(UserEntityInterface::class, $this->entity); + $this->assertEquals('foo', $this->entity->getIdentifier()); + } +} diff --git a/test/Repository/Pdo/AbstractRepositoryTest.php b/test/Repository/Pdo/AbstractRepositoryTest.php index 6d93b25..8317661 100644 --- a/test/Repository/Pdo/AbstractRepositoryTest.php +++ b/test/Repository/Pdo/AbstractRepositoryTest.php @@ -27,7 +27,7 @@ public function testConstructor() $this->assertInstanceOf(AbstractRepository::class, $abstract); } - public function testScopesToString() + public function testScopesToStringWithEmptyArray() { $proxy = new class($this->pdo->reveal()) extends AbstractRepository { public function scopesToString(array $scopes): string diff --git a/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php b/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php new file mode 100644 index 0000000..d30f058 --- /dev/null +++ b/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php @@ -0,0 +1,40 @@ +container = $this->prophesize(ContainerInterface::class); + $this->pdo = $this->prophesize(PdoService::class); + } + + public function testFactory() + { + $this->container->get(PdoService::class) + ->willReturn($this->pdo->reveal()); + + $factory = (new AccessTokenRepositoryFactory)($this->container->reveal()); + $this->assertInstanceOf(AccessTokenRepository::class, $factory); + } +} diff --git a/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php b/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php new file mode 100644 index 0000000..25d215c --- /dev/null +++ b/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php @@ -0,0 +1,40 @@ +container = $this->prophesize(ContainerInterface::class); + $this->pdo = $this->prophesize(PdoService::class); + } + + public function testFactory() + { + $this->container->get(PdoService::class) + ->willReturn($this->pdo->reveal()); + + $factory = (new AuthCodeRepositoryFactory)($this->container->reveal()); + $this->assertInstanceOf(AuthCodeRepository::class, $factory); + } +} diff --git a/test/Repository/Pdo/ClientRepositoryFactoryTest.php b/test/Repository/Pdo/ClientRepositoryFactoryTest.php new file mode 100644 index 0000000..cfd49a6 --- /dev/null +++ b/test/Repository/Pdo/ClientRepositoryFactoryTest.php @@ -0,0 +1,40 @@ +container = $this->prophesize(ContainerInterface::class); + $this->pdo = $this->prophesize(PdoService::class); + } + + public function testFactory() + { + $this->container->get(PdoService::class) + ->willReturn($this->pdo->reveal()); + + $factory = (new ClientRepositoryFactory)($this->container->reveal()); + $this->assertInstanceOf(ClientRepository::class, $factory); + } +} diff --git a/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php b/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php new file mode 100644 index 0000000..35b441d --- /dev/null +++ b/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php @@ -0,0 +1,40 @@ +container = $this->prophesize(ContainerInterface::class); + $this->pdo = $this->prophesize(PdoService::class); + } + + public function testFactory() + { + $this->container->get(PdoService::class) + ->willReturn($this->pdo->reveal()); + + $factory = (new RefreshTokenRepositoryFactory)($this->container->reveal()); + $this->assertInstanceOf(RefreshTokenRepository::class, $factory); + } +} diff --git a/test/Repository/Pdo/ScopeRepositoryFactoryTest.php b/test/Repository/Pdo/ScopeRepositoryFactoryTest.php new file mode 100644 index 0000000..30c99e2 --- /dev/null +++ b/test/Repository/Pdo/ScopeRepositoryFactoryTest.php @@ -0,0 +1,40 @@ +container = $this->prophesize(ContainerInterface::class); + $this->pdo = $this->prophesize(PdoService::class); + } + + public function testFactory() + { + $this->container->get(PdoService::class) + ->willReturn($this->pdo->reveal()); + + $factory = (new ScopeRepositoryFactory)($this->container->reveal()); + $this->assertInstanceOf(ScopeRepository::class, $factory); + } +} From a03545a4221fc913b5d0f424affcecdd4a821eb7 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Mon, 24 Sep 2018 17:33:44 +0200 Subject: [PATCH 02/10] Improve unit tests completed --- src/ConfigTrait.php | 7 +- test/ConfigTraitTest.php | 154 +++++++++++++++++ test/Entity/RevokableTraitTest.php | 2 +- .../Pdo/AccessTokenRepositoryTest.php | 24 +++ .../Repository/Pdo/AuthCodeRepositoryTest.php | 36 +++- .../Pdo/RefreshTokenRepositoryTest.php | 38 ++++ test/Repository/Pdo/ScopeRepositoryTest.php | 27 +++ test/Repository/Pdo/UserRepositoryTest.php | 26 +++ test/RepositoryTraitTest.php | 163 ++++++++++++++++++ 9 files changed, 474 insertions(+), 3 deletions(-) create mode 100644 test/ConfigTraitTest.php create mode 100644 test/RepositoryTraitTest.php diff --git a/src/ConfigTrait.php b/src/ConfigTrait.php index 0f1c358..401b758 100644 --- a/src/ConfigTrait.php +++ b/src/ConfigTrait.php @@ -90,11 +90,16 @@ protected function getGrantsConfig(ContainerInterface $container) : array { $config = $container->get('config')['authentication'] ?? []; - if (empty($config['grants']) || ! is_array($config['grants'])) { + if (empty($config['grants'])) { throw new InvalidConfigException( 'The grant value is missing in config authentication' ); } + if (! is_array($config['grants'])) { + throw new InvalidConfigException( + 'The grant must be an array value' + ); + } return $config['grants']; } diff --git a/test/ConfigTraitTest.php b/test/ConfigTraitTest.php new file mode 100644 index 0000000..c973104 --- /dev/null +++ b/test/ConfigTraitTest.php @@ -0,0 +1,154 @@ +trait = $trait = new class { + use ConfigTrait; + + public function proxy(string $name, ContainerInterface $container) + { + return $this->$name($container); + } + }; + $this->config = [ + 'authentication' => [ + 'private_key' => 'xxx', + 'encryption_key' => 'xxx', + 'access_token_expire' => '3600', + 'refresh_token_expire' => '3600', + 'auth_code_expire' => '120', + 'grants' => ['xxx'] + ] + ]; + $this->container = $this->prophesize(ContainerInterface::class); + $this->container->get('config') + ->willReturn($this->config); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetPrivateKeyNoConfig() + { + $this->container->get('config') + ->willReturn([]); + $this->trait->proxy('getPrivateKey', $this->container->reveal()); + } + + public function testGetPrivateKey() + { + $result = $this->trait->proxy('getPrivateKey', $this->container->reveal()); + $this->assertEquals($this->config['authentication']['private_key'], $result); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetEncryptionKeyNoConfig() + { + $this->container->get('config') + ->willReturn([]); + $this->trait->proxy('getEncryptionKey', $this->container->reveal()); + } + + public function testGetEncryptionKey() + { + $result = $this->trait->proxy('getEncryptionKey', $this->container->reveal()); + $this->assertEquals($this->config['authentication']['encryption_key'], $result); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetAccessTokenExpireNoConfig() + { + $this->container->get('config') + ->willReturn([]); + $this->trait->proxy('getAccessTokenExpire', $this->container->reveal()); + } + + public function testGetAccessTokenExpire() + { + $result = $this->trait->proxy('getAccessTokenExpire', $this->container->reveal()); + $this->assertEquals($this->config['authentication']['access_token_expire'], $result); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetRefreshTokenExpireNoConfig() + { + $this->container->get('config') + ->willReturn([]); + $this->trait->proxy('getRefreshTokenExpire', $this->container->reveal()); + } + + public function testGetRefreshTokenExpire() + { + $result = $this->trait->proxy('getRefreshTokenExpire', $this->container->reveal()); + $this->assertEquals($this->config['authentication']['refresh_token_expire'], $result); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetAuthCodeExpireNoConfig() + { + $this->container->get('config') + ->willReturn([]); + $this->trait->proxy('getAuthCodeExpire', $this->container->reveal()); + } + + public function testGetAuthCodeExpire() + { + $result = $this->trait->proxy('getAuthCodeExpire', $this->container->reveal()); + $this->assertEquals($this->config['authentication']['auth_code_expire'], $result); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetGrantsConfigNoConfig() + { + $this->container->get('config') + ->willReturn([]); + $this->trait->proxy('getGrantsConfig', $this->container->reveal()); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetGrantsConfigNoArrayValue() + { + $this->container->get('config') + ->willReturn([ + 'authentication' => [ + 'grants' => 'xxx' + ] + ]); + + $this->trait->proxy('getGrantsConfig', $this->container->reveal()); + } + + public function testGetGrantsConfig() + { + $result = $this->trait->proxy('getGrantsConfig', $this->container->reveal()); + $this->assertEquals($this->config['authentication']['grants'], $result); + } +} diff --git a/test/Entity/RevokableTraitTest.php b/test/Entity/RevokableTraitTest.php index 60e0931..1255f26 100644 --- a/test/Entity/RevokableTraitTest.php +++ b/test/Entity/RevokableTraitTest.php @@ -18,7 +18,7 @@ class RevokableTraitTest extends TestCase public function testRevoked() { $mock = $this->getMockForTrait(RevokableTrait::class); - + $mock->setRevoked(true); $this->assertTrue($mock->isRevoked()); $mock->setRevoked(false); diff --git a/test/Repository/Pdo/AccessTokenRepositoryTest.php b/test/Repository/Pdo/AccessTokenRepositoryTest.php index 9e97186..07f9f4c 100644 --- a/test/Repository/Pdo/AccessTokenRepositoryTest.php +++ b/test/Repository/Pdo/AccessTokenRepositoryTest.php @@ -14,10 +14,12 @@ use League\OAuth2\Server\Entities\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\ClientEntityInterface; use League\OAuth2\Server\Entities\ScopeEntityInterface; +use League\OAuth2\Server\Entities\Traits\AccessTokenTrait; use League\OAuth2\Server\Exception\UniqueTokenIdentifierConstraintViolationException; use PDOStatement; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Zend\Expressive\Authentication\OAuth2\Entity\AccessTokenEntity; use Zend\Expressive\Authentication\OAuth2\Repository\Pdo\AccessTokenRepository; use Zend\Expressive\Authentication\OAuth2\Repository\Pdo\PdoService; @@ -144,4 +146,26 @@ public function testRevokeAccessToken() $this->repo->revokeAccessToken('token_id'); } + + public function testGetNewToken() + { + $client = $this->prophesize(ClientEntityInterface::class)->reveal(); + $accessToken = $this->repo->getNewToken($client, []); + $this->assertInstanceOf(AccessTokenEntity::class, $accessToken); + $this->assertEquals($client, $accessToken->getClient()); + $this->assertEquals([], $accessToken->getScopes()); + } + + public function testGetNewTokenWithScopeAndIndentifier() + { + $client = $this->prophesize(ClientEntityInterface::class)->reveal(); + $scopes = [ $this->prophesize(ScopeEntityInterface::class)->reveal() ]; + $userIdentifier = 'foo'; + + $accessToken = $this->repo->getNewToken($client, $scopes, $userIdentifier); + $this->assertInstanceOf(AccessTokenEntity::class, $accessToken); + $this->assertEquals($client, $accessToken->getClient()); + $this->assertEquals($scopes, $accessToken->getScopes()); + $this->assertEquals($userIdentifier, $accessToken->getUserIdentifier()); + } } diff --git a/test/Repository/Pdo/AuthCodeRepositoryTest.php b/test/Repository/Pdo/AuthCodeRepositoryTest.php index d960fb0..0605a0f 100644 --- a/test/Repository/Pdo/AuthCodeRepositoryTest.php +++ b/test/Repository/Pdo/AuthCodeRepositoryTest.php @@ -31,7 +31,7 @@ public function setUp() $this->repo = new AuthCodeRepository($this->pdo->reveal()); } - public function testPeristNewAuthCodeRaisesExceptionWhenStatementExecutionFails() + public function testPersistNewAuthCodeRaisesExceptionWhenStatementExecutionFails() { $client = $this->prophesize(ClientEntityInterface::class); $client->getIdentifier()->willReturn('client_id'); @@ -81,4 +81,38 @@ public function testIsAuthCodeRevokedReturnsFalseForStatementExecutionFailure() $this->assertFalse($this->repo->isAuthCodeRevoked('code_identifier')); } + + public function testIsAuthCodeRevokedReturnsTrue() + { + $statement = $this->prophesize(PDOStatement::class); + $statement->bindParam(':codeId', 'code_identifier')->shouldBeCalled(); + $statement->execute()->willReturn(true); + $statement->fetch()->willReturn(['revoked' => true]); + + $this->pdo + ->prepare(Argument::containingString('SELECT revoked FROM oauth_auth_codes')) + ->will([$statement, 'reveal']); + + $this->assertTrue($this->repo->isAuthCodeRevoked('code_identifier')); + } + + public function testNewAuthCode() + { + $result = $this->repo->getNewAuthCode(); + $this->assertInstanceOf(AuthCodeEntity::class, $result); + } + + public function testRevokeAuthCode() + { + $statement = $this->prophesize(PDOStatement::class); + $statement->bindParam(':codeId', 'code_identifier')->shouldBeCalled(); + $statement->bindValue(':revoked', 1)->shouldBeCalled(); + $statement->execute()->willReturn(true); + + $this->pdo + ->prepare(Argument::containingString('UPDATE oauth_auth_codes SET revoked=:revoked WHERE id = :codeId')) + ->will([$statement, 'reveal']); + + $this->repo->revokeAuthCode('code_identifier'); + } } diff --git a/test/Repository/Pdo/RefreshTokenRepositoryTest.php b/test/Repository/Pdo/RefreshTokenRepositoryTest.php index f00ccf6..53ef3d6 100644 --- a/test/Repository/Pdo/RefreshTokenRepositoryTest.php +++ b/test/Repository/Pdo/RefreshTokenRepositoryTest.php @@ -17,6 +17,7 @@ use PDOStatement; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Zend\Expressive\Authentication\OAuth2\Entity\RefreshTokenEntity; use Zend\Expressive\Authentication\OAuth2\Repository\Pdo\PdoService; use Zend\Expressive\Authentication\OAuth2\Repository\Pdo\RefreshTokenRepository; @@ -73,4 +74,41 @@ public function testIsRefreshTokenRevokedReturnsFalseWhenStatementFailsExecution $this->assertFalse($this->repo->isRefreshTokenRevoked('token_id')); } + + public function testIsRefreshTokenRevokedReturnsTrue() + { + $statement = $this->prophesize(PDOStatement::class); + $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); + $statement->execute()->willReturn(true)->shouldBeCalled(); + $statement->fetch()->willReturn(['revoked' => true]); + + $this->pdo + ->prepare(Argument::containingString('SELECT revoked FROM oauth_refresh_tokens')) + ->will([$statement, 'reveal']); + + $this->assertTrue($this->repo->isRefreshTokenRevoked('token_id')); + } + + public function testGetNewRefreshToken() + { + $result = $this->repo->getNewRefreshToken(); + $this->assertInstanceOf(RefreshTokenEntity::class, $result); + } + + public function testRevokeRefreshToken() + { + $statement = $this->prophesize(PDOStatement::class); + $statement->bindParam(':tokenId', 'token_id')->shouldBeCalled(); + $statement->bindValue(':revoked', 1)->shouldBeCalled(); + $statement->execute()->willReturn(true)->shouldBeCalled(); + $statement->fetch()->shouldNotBeCalled(); + + $this->pdo + ->prepare(Argument::containingString( + 'UPDATE oauth_refresh_tokens SET revoked=:revoked WHERE id = :tokenId' + )) + ->will([$statement, 'reveal']); + + $this->repo->revokeRefreshToken('token_id'); + } } diff --git a/test/Repository/Pdo/ScopeRepositoryTest.php b/test/Repository/Pdo/ScopeRepositoryTest.php index fce2cc1..985d78e 100644 --- a/test/Repository/Pdo/ScopeRepositoryTest.php +++ b/test/Repository/Pdo/ScopeRepositoryTest.php @@ -10,9 +10,11 @@ namespace ZendTest\Expressive\Authentication\OAuth2\Repository\Pdo; +use League\OAuth2\Server\Entities\ClientEntityInterface; use PDOStatement; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Zend\Expressive\Authentication\OAuth2\Entity\ScopeEntity; use Zend\Expressive\Authentication\OAuth2\Repository\Pdo\PdoService; use Zend\Expressive\Authentication\OAuth2\Repository\Pdo\ScopeRepository; @@ -51,4 +53,29 @@ public function testGetScopeEntityByIdentifierReturnsNullWhenReturnedRowDoesNotH $this->assertNull($this->repo->getScopeEntityByIdentifier('id')); } + + public function testGetScopeEntityByIndentifierReturnsScopes() + { + $statement = $this->prophesize(PDOStatement::class); + $statement->bindParam(':identifier', 'id')->shouldBeCalled(); + $statement->execute()->shouldBeCalled(); + $statement->fetch()->willReturn([ + 'id' => 'foo' + ])->shouldBeCalled(); + + $this->pdo + ->prepare(Argument::containingString('SELECT id FROM oauth_scopes')) + ->will([$statement, 'reveal']); + + $scope = $this->repo->getScopeEntityByIdentifier('id'); + $this->assertInstanceOf(ScopeEntity::class, $scope); + $this->assertEquals('foo', $scope->getIdentifier()); + } + + public function testFinalizeScopesWithEmptyScopes() + { + $clientEntity = $this->prophesize(ClientEntityInterface::class); + $scopes = $this->repo->finalizeScopes([], 'foo', $clientEntity->reveal()); + $this->assertEquals([], $scopes); + } } diff --git a/test/Repository/Pdo/UserRepositoryTest.php b/test/Repository/Pdo/UserRepositoryTest.php index 6cd1e4e..35f4ca1 100644 --- a/test/Repository/Pdo/UserRepositoryTest.php +++ b/test/Repository/Pdo/UserRepositoryTest.php @@ -14,6 +14,7 @@ use PDOStatement; use PHPUnit\Framework\TestCase; use Prophecy\Argument; +use Zend\Expressive\Authentication\OAuth2\Entity\UserEntity; use Zend\Expressive\Authentication\OAuth2\Repository\Pdo\PdoService; use Zend\Expressive\Authentication\OAuth2\Repository\Pdo\UserRepository; @@ -98,4 +99,29 @@ public function testGetUserEntityByCredentialsReturnsNullIfUserIsNotFound() ) ); } + + public function testGetUserEntityByCredentialsReturnsEntity() + { + $statement = $this->prophesize(PDOStatement::class); + $statement->bindParam(':username', 'username')->shouldBeCalled(); + $statement->execute()->willReturn(true); + $statement->fetch()->willReturn([ + 'password' => password_hash('password', PASSWORD_DEFAULT) + ]); + + $this->pdo + ->prepare(Argument::containingString('SELECT password FROM oauth_users WHERE username = :username')) + ->will([$statement, 'reveal']); + + $client = $this->prophesize(ClientEntityInterface::class); + + $entity = $this->repo->getUserEntityByUserCredentials( + 'username', + 'password', + 'auth', + $client->reveal() + ); + $this->assertInstanceOf(UserEntity::class, $entity); + $this->assertEquals('username', $entity->getIdentifier()); + } } diff --git a/test/RepositoryTraitTest.php b/test/RepositoryTraitTest.php new file mode 100644 index 0000000..cad42ce --- /dev/null +++ b/test/RepositoryTraitTest.php @@ -0,0 +1,163 @@ +trait = $trait = new class { + use RepositoryTrait; + + public function proxy(string $name, ContainerInterface $container) + { + return $this->$name($container); + } + }; + $this->container = $this->prophesize(ContainerInterface::class); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetUserRepositoryWithoutService() + { + $this->container->has(UserRepositoryInterface::class) + ->willReturn(false); + $this->trait->proxy('getUserRepository', $this->container->reveal()); + } + + public function testGetUserRepository() + { + $this->container->has(UserRepositoryInterface::class) + ->willReturn(true); + $this->container->get(UserRepositoryInterface::class) + ->willReturn($this->prophesize(UserRepositoryInterface::class)->reveal()); + + $result = $this->trait->proxy('getUserRepository', $this->container->reveal()); + $this->assertInstanceOf(UserRepositoryInterface::class, $result); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetScopeRepositoryWithoutService() + { + $this->container->has(ScopeRepositoryInterface::class) + ->willReturn(false); + $this->trait->proxy('getScopeRepository', $this->container->reveal()); + } + + public function testGetScopeRepository() + { + $this->container->has(ScopeRepositoryInterface::class) + ->willReturn(true); + $this->container->get(ScopeRepositoryInterface::class) + ->willReturn($this->prophesize(ScopeRepositoryInterface::class)->reveal()); + + $result = $this->trait->proxy('getScopeRepository', $this->container->reveal()); + $this->assertInstanceOf(ScopeRepositoryInterface::class, $result); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetAccessTokenRepositoryWithoutService() + { + $this->container->has(AccessTokenRepositoryInterface::class) + ->willReturn(false); + $this->trait->proxy('getAccessTokenRepository', $this->container->reveal()); + } + + public function testGetAccessTokenRepository() + { + $this->container->has(AccessTokenRepositoryInterface::class) + ->willReturn(true); + $this->container->get(AccessTokenRepositoryInterface::class) + ->willReturn($this->prophesize(AccessTokenRepositoryInterface::class)->reveal()); + + $result = $this->trait->proxy('getAccessTokenRepository', $this->container->reveal()); + $this->assertInstanceOf(AccessTokenRepositoryInterface::class, $result); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetClientRepositoryWithoutService() + { + $this->container->has(ClientRepositoryInterface::class) + ->willReturn(false); + $this->trait->proxy('getClientRepository', $this->container->reveal()); + } + + public function testGetClientRepository() + { + $this->container->has(ClientRepositoryInterface::class) + ->willReturn(true); + $this->container->get(ClientRepositoryInterface::class) + ->willReturn($this->prophesize(ClientRepositoryInterface::class)->reveal()); + + $result = $this->trait->proxy('getClientRepository', $this->container->reveal()); + $this->assertInstanceOf(ClientRepositoryInterface::class, $result); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetRefreshTokenRepositoryWithoutService() + { + $this->container->has(RefreshTokenRepositoryInterface::class) + ->willReturn(false); + $this->trait->proxy('getRefreshTokenRepository', $this->container->reveal()); + } + + public function testGetRefreshTokenRepository() + { + $this->container->has(RefreshTokenRepositoryInterface::class) + ->willReturn(true); + $this->container->get(RefreshTokenRepositoryInterface::class) + ->willReturn($this->prophesize(RefreshTokenRepositoryInterface::class)->reveal()); + + $result = $this->trait->proxy('getRefreshTokenRepository', $this->container->reveal()); + $this->assertInstanceOf(RefreshTokenRepositoryInterface::class, $result); + } + + /** + * @expectedException Zend\Expressive\Authentication\OAuth2\Exception\InvalidConfigException + */ + public function testGetAuthCodeRepositoryWithoutService() + { + $this->container->has(AuthCodeRepositoryInterface::class) + ->willReturn(false); + $this->trait->proxy('getAuthCodeRepository', $this->container->reveal()); + } + + public function testGetAuthCodeRepository() + { + $this->container->has(AuthCodeRepositoryInterface::class) + ->willReturn(true); + $this->container->get(AuthCodeRepositoryInterface::class) + ->willReturn($this->prophesize(AuthCodeRepositoryInterface::class)->reveal()); + + $result = $this->trait->proxy('getAuthCodeRepository', $this->container->reveal()); + $this->assertInstanceOf(AuthCodeRepositoryInterface::class, $result); + } +} From bba9b21160527f727e1c34da38e8966940d77004 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Wed, 26 Sep 2018 15:13:26 +0200 Subject: [PATCH 03/10] Resolved comments on PR #49 --- src/ConfigProvider.php | 3 +++ src/ConfigTrait.php | 4 ++-- src/Entity/TimestampableTrait.php | 16 +++++++++------- test/ConfigTraitTest.php | 4 ++-- test/Entity/AccessTokenEntityTest.php | 2 +- test/Entity/AuthCodeEntityTest.php | 2 +- test/Entity/ClientEntityTest.php | 2 +- test/Entity/RefreshTokenEntityTest.php | 2 +- test/Entity/RevokableTraitTest.php | 19 +++++++++++++------ test/Entity/ScopeEntityTest.php | 2 +- test/Entity/TimestampableTraitTest.php | 6 +++--- test/Entity/UserEntityTest.php | 8 ++++++-- 12 files changed, 43 insertions(+), 27 deletions(-) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index d59fc0a..14190f7 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -31,6 +31,9 @@ use Zend\Expressive\Authentication\OAuth2\Grant\RefreshTokenGrantFactory; use Zend\Expressive\Authentication\OAuth2\Repository\Pdo; +/** + * @codeCoverageIgnore + */ class ConfigProvider { /** diff --git a/src/ConfigTrait.php b/src/ConfigTrait.php index 401b758..1c01e51 100644 --- a/src/ConfigTrait.php +++ b/src/ConfigTrait.php @@ -92,12 +92,12 @@ protected function getGrantsConfig(ContainerInterface $container) : array if (empty($config['grants'])) { throw new InvalidConfigException( - 'The grant value is missing in config authentication' + 'The grants value is missing in config authentication and must be an array' ); } if (! is_array($config['grants'])) { throw new InvalidConfigException( - 'The grant must be an array value' + 'The grants must be an array value' ); } diff --git a/src/Entity/TimestampableTrait.php b/src/Entity/TimestampableTrait.php index 4f710ba..fdf54ff 100644 --- a/src/Entity/TimestampableTrait.php +++ b/src/Entity/TimestampableTrait.php @@ -10,7 +10,8 @@ namespace Zend\Expressive\Authentication\OAuth2\Entity; -use DateTime; +use DateTimeImmutable; +use DateTimeInterface; use DateTimeZone; use function method_exists; @@ -27,22 +28,22 @@ trait TimestampableTrait */ protected $updatedAt; - public function getCreatedAt() : DateTime + public function getCreatedAt() : DateTimeInterface { return $this->createdAt; } - public function setCreatedAt(DateTime $createdAt) : void + public function setCreatedAt(DateTimeInterface $createdAt) : void { $this->createdAt = $createdAt; } - public function getUpdatedAt() : DateTime + public function getUpdatedAt() : DateTimeInterface { return $this->updatedAt; } - public function setUpdatedAt(DateTime $updatedAt) : void + public function setUpdatedAt(DateTimeInterface $updatedAt) : void { $this->updatedAt = $updatedAt; } @@ -54,9 +55,10 @@ public function setUpdatedAt(DateTime $updatedAt) : void public function timestampOnCreate() : void { if (! $this->createdAt) { - $this->createdAt = new DateTime(); if (method_exists($this, 'getTimezone')) { - $this->createdAt->setTimezone(new DateTimeZone($this->getTimezone()->getValue())); + $this->createdAt = new DateTimeImmutable('now', new DateTimeZone($this->getTimezone()->getValue())); + } else { + $this->createdAt = new DateTimeImmutable(); } } } diff --git a/test/ConfigTraitTest.php b/test/ConfigTraitTest.php index c973104..cbaa883 100644 --- a/test/ConfigTraitTest.php +++ b/test/ConfigTraitTest.php @@ -1,7 +1,7 @@ container->get('config') ->willReturn([]); diff --git a/test/Entity/AccessTokenEntityTest.php b/test/Entity/AccessTokenEntityTest.php index 7be3ca7..a2965ff 100644 --- a/test/Entity/AccessTokenEntityTest.php +++ b/test/Entity/AccessTokenEntityTest.php @@ -16,7 +16,7 @@ class AccessTokenEntityTest extends TestCase { - public function testConstructor() + public function testImplementsInstanceAccessTokenEntityInterface() { $entity = new AccessTokenEntity(); $this->assertInstanceOf(AccessTokenEntityInterface::class, $entity); diff --git a/test/Entity/AuthCodeEntityTest.php b/test/Entity/AuthCodeEntityTest.php index 2ab7530..d5a10c6 100644 --- a/test/Entity/AuthCodeEntityTest.php +++ b/test/Entity/AuthCodeEntityTest.php @@ -16,7 +16,7 @@ class AuthCodeEntityTest extends TestCase { - public function testConstructor() + public function testImplementsInstanceAuthCodeEntityInterface() { $entity = new AuthCodeEntity(); $this->assertInstanceOf(AuthCodeEntityInterface::class, $entity); diff --git a/test/Entity/ClientEntityTest.php b/test/Entity/ClientEntityTest.php index 4ea2ba7..e77782b 100644 --- a/test/Entity/ClientEntityTest.php +++ b/test/Entity/ClientEntityTest.php @@ -20,7 +20,7 @@ public function setUp() { $this->entity = new ClientEntity('foo', 'bar', 'http://localhost'); } - public function testConstructor() + public function testImplementsAuthCodeEntityInterface() { $this->assertInstanceOf(ClientEntityInterface::class, $this->entity); } diff --git a/test/Entity/RefreshTokenEntityTest.php b/test/Entity/RefreshTokenEntityTest.php index 06f8a2c..8f00bc7 100644 --- a/test/Entity/RefreshTokenEntityTest.php +++ b/test/Entity/RefreshTokenEntityTest.php @@ -16,7 +16,7 @@ class RefreshTokenEntityTest extends TestCase { - public function testConstructor() + public function testImplementsRefreshTokenEntityInterface() { $entity = new RefreshTokenEntity(); $this->assertInstanceOf(RefreshTokenEntityInterface::class, $entity); diff --git a/test/Entity/RevokableTraitTest.php b/test/Entity/RevokableTraitTest.php index 1255f26..a16dc8c 100644 --- a/test/Entity/RevokableTraitTest.php +++ b/test/Entity/RevokableTraitTest.php @@ -15,13 +15,20 @@ class RevokableTraitTest extends TestCase { - public function testRevoked() + public function setUp() { - $mock = $this->getMockForTrait(RevokableTrait::class); + $this->trait = $this->getMockForTrait(RevokableTrait::class); + } - $mock->setRevoked(true); - $this->assertTrue($mock->isRevoked()); - $mock->setRevoked(false); - $this->assertFalse($mock->isRevoked()); + public function testSetRevokedToTrue() + { + $this->trait->setRevoked(true); + $this->assertTrue($this->trait->isRevoked()); + } + + public function testSetREvokedToFalse() + { + $this->trait->setRevoked(false); + $this->assertFalse($this->trait->isRevoked()); } } diff --git a/test/Entity/ScopeEntityTest.php b/test/Entity/ScopeEntityTest.php index 0cfa65c..bf586cd 100644 --- a/test/Entity/ScopeEntityTest.php +++ b/test/Entity/ScopeEntityTest.php @@ -21,7 +21,7 @@ public function setUp() $this->entity = new ScopeEntity(); } - public function testConstructor() + public function testImplementsScopeEntityInterface() { $this->assertInstanceOf(ScopeEntityInterface::class, $this->entity); } diff --git a/test/Entity/TimestampableTraitTest.php b/test/Entity/TimestampableTraitTest.php index 59c6a94..0b3769c 100644 --- a/test/Entity/TimestampableTraitTest.php +++ b/test/Entity/TimestampableTraitTest.php @@ -10,7 +10,7 @@ namespace ZendTest\Expressive\Authentication\OAuth2\Entity; -use DateTime; +use DateTimeImmutable; use PHPUnit\Framework\TestCase; use Zend\Expressive\Authentication\OAuth2\Entity\TimestampableTrait; @@ -23,14 +23,14 @@ public function setUp() public function testCreatedAt() { - $now = new DateTime(); + $now = new DateTimeImmutable(); $this->trait->setCreatedAt($now); $this->assertEquals($now, $this->trait->getCreatedAt()); } public function testUpdatedAt() { - $now = new DateTime(); + $now = new DateTimeImmutable(); $this->trait->setUpdatedAt($now); $this->assertEquals($now, $this->trait->getUpdatedAt()); } diff --git a/test/Entity/UserEntityTest.php b/test/Entity/UserEntityTest.php index c7b10bd..0957993 100644 --- a/test/Entity/UserEntityTest.php +++ b/test/Entity/UserEntityTest.php @@ -24,14 +24,18 @@ public function setUp() /** * @expectedException ArgumentCountError */ - public function testConstructorWithoutParam() + public function testConstructorWithoutParamWillResultInAnException() { $entity = new UserEntity(); } - public function testConstructor() + public function testImplementsUserEntityInterface() { $this->assertInstanceOf(UserEntityInterface::class, $this->entity); + } + + public function testGetIdentifier() + { $this->assertEquals('foo', $this->entity->getIdentifier()); } } From 458d26a49f2279ab591f73f5948f39cec666e8f1 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 26 Sep 2018 11:19:21 -0500 Subject: [PATCH 04/10] Minor CS/consistency changes - Commas after all array entries - When splitting to multiple lines, move all arrow operations to their own lines when operating on an object --- test/ConfigTraitTest.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/test/ConfigTraitTest.php b/test/ConfigTraitTest.php index cbaa883..f1e9659 100644 --- a/test/ConfigTraitTest.php +++ b/test/ConfigTraitTest.php @@ -37,7 +37,8 @@ public function proxy(string $name, ContainerInterface $container) ] ]; $this->container = $this->prophesize(ContainerInterface::class); - $this->container->get('config') + $this->container + ->get('config') ->willReturn($this->config); } @@ -46,7 +47,8 @@ public function proxy(string $name, ContainerInterface $container) */ public function testGetPrivateKeyWhenNoConfigPresentWillResultInAnException() { - $this->container->get('config') + $this->container + ->get('config') ->willReturn([]); $this->trait->proxy('getPrivateKey', $this->container->reveal()); } @@ -62,7 +64,8 @@ public function testGetPrivateKey() */ public function testGetEncryptionKeyNoConfig() { - $this->container->get('config') + $this->container + ->get('config') ->willReturn([]); $this->trait->proxy('getEncryptionKey', $this->container->reveal()); } @@ -78,7 +81,8 @@ public function testGetEncryptionKey() */ public function testGetAccessTokenExpireNoConfig() { - $this->container->get('config') + $this->container + ->get('config') ->willReturn([]); $this->trait->proxy('getAccessTokenExpire', $this->container->reveal()); } @@ -94,7 +98,8 @@ public function testGetAccessTokenExpire() */ public function testGetRefreshTokenExpireNoConfig() { - $this->container->get('config') + $this->container + ->get('config') ->willReturn([]); $this->trait->proxy('getRefreshTokenExpire', $this->container->reveal()); } @@ -110,7 +115,8 @@ public function testGetRefreshTokenExpire() */ public function testGetAuthCodeExpireNoConfig() { - $this->container->get('config') + $this->container + ->get('config') ->willReturn([]); $this->trait->proxy('getAuthCodeExpire', $this->container->reveal()); } @@ -126,7 +132,8 @@ public function testGetAuthCodeExpire() */ public function testGetGrantsConfigNoConfig() { - $this->container->get('config') + $this->container + ->get('config') ->willReturn([]); $this->trait->proxy('getGrantsConfig', $this->container->reveal()); } @@ -136,11 +143,12 @@ public function testGetGrantsConfigNoConfig() */ public function testGetGrantsConfigNoArrayValue() { - $this->container->get('config') + $this->container + ->get('config') ->willReturn([ 'authentication' => [ - 'grants' => 'xxx' - ] + 'grants' => 'xxx', + ], ]); $this->trait->proxy('getGrantsConfig', $this->container->reveal()); From c569c1cbda8ea33d4cb97f0c3e74437ca6e432d7 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 26 Sep 2018 11:23:25 -0500 Subject: [PATCH 05/10] Write tests for ClientEntity constructor Writes three test methods that ensure the arguments passed to the constructor affect the instance state. --- test/Entity/ClientEntityTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/Entity/ClientEntityTest.php b/test/Entity/ClientEntityTest.php index e77782b..afa3938 100644 --- a/test/Entity/ClientEntityTest.php +++ b/test/Entity/ClientEntityTest.php @@ -20,11 +20,27 @@ public function setUp() { $this->entity = new ClientEntity('foo', 'bar', 'http://localhost'); } + public function testImplementsAuthCodeEntityInterface() { $this->assertInstanceOf(ClientEntityInterface::class, $this->entity); } + public function testConstructorSetsIdentifier() + { + $this->assertSame('foo', $this->entity->getIdentifier()); + } + + public function testConstructorSetsName() + { + $this->assertSame('bar', $this->entity->getName()); + } + + public function testConstructorSetsRedirectUri() + { + $this->assertSame(['http://localhost'], $this->entity->getRedirectUri()); + } + public function testSecret() { $this->entity->setSecret('secret'); From c64113861b74d12d6db7b0a12eeb5c88d1a6a863 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 26 Sep 2018 11:24:01 -0500 Subject: [PATCH 06/10] Fixes typo in method name of RevokableTraitTest --- test/Entity/RevokableTraitTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Entity/RevokableTraitTest.php b/test/Entity/RevokableTraitTest.php index a16dc8c..dade9ba 100644 --- a/test/Entity/RevokableTraitTest.php +++ b/test/Entity/RevokableTraitTest.php @@ -26,7 +26,7 @@ public function testSetRevokedToTrue() $this->assertTrue($this->trait->isRevoked()); } - public function testSetREvokedToFalse() + public function testSetRevokedToFalse() { $this->trait->setRevoked(false); $this->assertFalse($this->trait->isRevoked()); From 3c4a3561bcda3968f7fd7e74e1f65d813c30ade8 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 26 Sep 2018 11:25:11 -0500 Subject: [PATCH 07/10] Better test method name in ScopeEntityTest s/testJsonSerialize/testEntityIsJsonSerializable/ --- test/Entity/ScopeEntityTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Entity/ScopeEntityTest.php b/test/Entity/ScopeEntityTest.php index bf586cd..ef62884 100644 --- a/test/Entity/ScopeEntityTest.php +++ b/test/Entity/ScopeEntityTest.php @@ -26,7 +26,7 @@ public function testImplementsScopeEntityInterface() $this->assertInstanceOf(ScopeEntityInterface::class, $this->entity); } - public function testJsonSerialize() + public function testEntityIsJsonSerializable() { $this->entity->setIdentifier('foo'); $this->assertEquals('"foo"', json_encode($this->entity)); From 0a83f1259e89c3311cadecce34298f0a6713bc8a Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 26 Sep 2018 11:26:34 -0500 Subject: [PATCH 08/10] One line per object operation --- .../Pdo/AccessTokenRepositoryFactoryTest.php | 3 +- .../Pdo/AuthCodeRepositoryFactoryTest.php | 3 +- .../Pdo/ClientRepositoryFactoryTest.php | 3 +- .../Pdo/RefreshTokenRepositoryFactoryTest.php | 3 +- .../Pdo/ScopeRepositoryFactoryTest.php | 3 +- test/RepositoryTraitTest.php | 54 ++++++++++++------- 6 files changed, 46 insertions(+), 23 deletions(-) diff --git a/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php b/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php index d30f058..1c9ef49 100644 --- a/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php +++ b/test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php @@ -31,7 +31,8 @@ public function setUp() public function testFactory() { - $this->container->get(PdoService::class) + $this->container + ->get(PdoService::class) ->willReturn($this->pdo->reveal()); $factory = (new AccessTokenRepositoryFactory)($this->container->reveal()); diff --git a/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php b/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php index 25d215c..7c32774 100644 --- a/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php +++ b/test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php @@ -31,7 +31,8 @@ public function setUp() public function testFactory() { - $this->container->get(PdoService::class) + $this->container + ->get(PdoService::class) ->willReturn($this->pdo->reveal()); $factory = (new AuthCodeRepositoryFactory)($this->container->reveal()); diff --git a/test/Repository/Pdo/ClientRepositoryFactoryTest.php b/test/Repository/Pdo/ClientRepositoryFactoryTest.php index cfd49a6..4e2574a 100644 --- a/test/Repository/Pdo/ClientRepositoryFactoryTest.php +++ b/test/Repository/Pdo/ClientRepositoryFactoryTest.php @@ -31,7 +31,8 @@ public function setUp() public function testFactory() { - $this->container->get(PdoService::class) + $this->container + ->get(PdoService::class) ->willReturn($this->pdo->reveal()); $factory = (new ClientRepositoryFactory)($this->container->reveal()); diff --git a/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php b/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php index 35b441d..0f75b6a 100644 --- a/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php +++ b/test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php @@ -31,7 +31,8 @@ public function setUp() public function testFactory() { - $this->container->get(PdoService::class) + $this->container + ->get(PdoService::class) ->willReturn($this->pdo->reveal()); $factory = (new RefreshTokenRepositoryFactory)($this->container->reveal()); diff --git a/test/Repository/Pdo/ScopeRepositoryFactoryTest.php b/test/Repository/Pdo/ScopeRepositoryFactoryTest.php index 30c99e2..2a46fdf 100644 --- a/test/Repository/Pdo/ScopeRepositoryFactoryTest.php +++ b/test/Repository/Pdo/ScopeRepositoryFactoryTest.php @@ -31,7 +31,8 @@ public function setUp() public function testFactory() { - $this->container->get(PdoService::class) + $this->container + ->get(PdoService::class) ->willReturn($this->pdo->reveal()); $factory = (new ScopeRepositoryFactory)($this->container->reveal()); diff --git a/test/RepositoryTraitTest.php b/test/RepositoryTraitTest.php index cad42ce..90c69a4 100644 --- a/test/RepositoryTraitTest.php +++ b/test/RepositoryTraitTest.php @@ -40,16 +40,19 @@ public function proxy(string $name, ContainerInterface $container) */ public function testGetUserRepositoryWithoutService() { - $this->container->has(UserRepositoryInterface::class) + $this->container + ->has(UserRepositoryInterface::class) ->willReturn(false); $this->trait->proxy('getUserRepository', $this->container->reveal()); } public function testGetUserRepository() { - $this->container->has(UserRepositoryInterface::class) + $this->container + ->has(UserRepositoryInterface::class) ->willReturn(true); - $this->container->get(UserRepositoryInterface::class) + $this->container + ->get(UserRepositoryInterface::class) ->willReturn($this->prophesize(UserRepositoryInterface::class)->reveal()); $result = $this->trait->proxy('getUserRepository', $this->container->reveal()); @@ -61,16 +64,19 @@ public function testGetUserRepository() */ public function testGetScopeRepositoryWithoutService() { - $this->container->has(ScopeRepositoryInterface::class) + $this->container + ->has(ScopeRepositoryInterface::class) ->willReturn(false); $this->trait->proxy('getScopeRepository', $this->container->reveal()); } public function testGetScopeRepository() { - $this->container->has(ScopeRepositoryInterface::class) + $this->container + ->has(ScopeRepositoryInterface::class) ->willReturn(true); - $this->container->get(ScopeRepositoryInterface::class) + $this->container + ->get(ScopeRepositoryInterface::class) ->willReturn($this->prophesize(ScopeRepositoryInterface::class)->reveal()); $result = $this->trait->proxy('getScopeRepository', $this->container->reveal()); @@ -82,16 +88,19 @@ public function testGetScopeRepository() */ public function testGetAccessTokenRepositoryWithoutService() { - $this->container->has(AccessTokenRepositoryInterface::class) + $this->container + ->has(AccessTokenRepositoryInterface::class) ->willReturn(false); $this->trait->proxy('getAccessTokenRepository', $this->container->reveal()); } public function testGetAccessTokenRepository() { - $this->container->has(AccessTokenRepositoryInterface::class) + $this->container + ->has(AccessTokenRepositoryInterface::class) ->willReturn(true); - $this->container->get(AccessTokenRepositoryInterface::class) + $this->container + ->get(AccessTokenRepositoryInterface::class) ->willReturn($this->prophesize(AccessTokenRepositoryInterface::class)->reveal()); $result = $this->trait->proxy('getAccessTokenRepository', $this->container->reveal()); @@ -103,16 +112,19 @@ public function testGetAccessTokenRepository() */ public function testGetClientRepositoryWithoutService() { - $this->container->has(ClientRepositoryInterface::class) + $this->container + ->has(ClientRepositoryInterface::class) ->willReturn(false); $this->trait->proxy('getClientRepository', $this->container->reveal()); } public function testGetClientRepository() { - $this->container->has(ClientRepositoryInterface::class) + $this->container + ->has(ClientRepositoryInterface::class) ->willReturn(true); - $this->container->get(ClientRepositoryInterface::class) + $this->container + ->get(ClientRepositoryInterface::class) ->willReturn($this->prophesize(ClientRepositoryInterface::class)->reveal()); $result = $this->trait->proxy('getClientRepository', $this->container->reveal()); @@ -124,16 +136,19 @@ public function testGetClientRepository() */ public function testGetRefreshTokenRepositoryWithoutService() { - $this->container->has(RefreshTokenRepositoryInterface::class) + $this->container + ->has(RefreshTokenRepositoryInterface::class) ->willReturn(false); $this->trait->proxy('getRefreshTokenRepository', $this->container->reveal()); } public function testGetRefreshTokenRepository() { - $this->container->has(RefreshTokenRepositoryInterface::class) + $this->container + ->has(RefreshTokenRepositoryInterface::class) ->willReturn(true); - $this->container->get(RefreshTokenRepositoryInterface::class) + $this->container + ->get(RefreshTokenRepositoryInterface::class) ->willReturn($this->prophesize(RefreshTokenRepositoryInterface::class)->reveal()); $result = $this->trait->proxy('getRefreshTokenRepository', $this->container->reveal()); @@ -145,16 +160,19 @@ public function testGetRefreshTokenRepository() */ public function testGetAuthCodeRepositoryWithoutService() { - $this->container->has(AuthCodeRepositoryInterface::class) + $this->container + ->has(AuthCodeRepositoryInterface::class) ->willReturn(false); $this->trait->proxy('getAuthCodeRepository', $this->container->reveal()); } public function testGetAuthCodeRepository() { - $this->container->has(AuthCodeRepositoryInterface::class) + $this->container + ->has(AuthCodeRepositoryInterface::class) ->willReturn(true); - $this->container->get(AuthCodeRepositoryInterface::class) + $this->container + ->get(AuthCodeRepositoryInterface::class) ->willReturn($this->prophesize(AuthCodeRepositoryInterface::class)->reveal()); $result = $this->trait->proxy('getAuthCodeRepository', $this->container->reveal()); From cc0a998507662c29a8f5cf81cc01e5ea100b582e Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Wed, 26 Sep 2018 11:41:07 -0500 Subject: [PATCH 09/10] Updates copyright dates on all files touched by this patch - New files: 2018 - Existing files: range adds "-2018" --- src/ConfigProvider.php | 2 +- src/ConfigTrait.php | 2 +- src/Entity/TimestampableTrait.php | 2 +- test/Entity/AccessTokenEntityTest.php | 2 +- test/Entity/AuthCodeEntityTest.php | 2 +- test/Entity/ClientEntityTest.php | 2 +- test/Entity/RefreshTokenEntityTest.php | 2 +- test/Entity/RevokableTraitTest.php | 2 +- test/Entity/ScopeEntityTest.php | 2 +- test/Entity/TimestampableTraitTest.php | 2 +- test/Entity/UserEntityTest.php | 2 +- test/Repository/Pdo/AbstractRepositoryTest.php | 2 +- test/Repository/Pdo/AccessTokenRepositoryFactoryTest.php | 2 +- test/Repository/Pdo/AccessTokenRepositoryTest.php | 2 +- test/Repository/Pdo/AuthCodeRepositoryFactoryTest.php | 2 +- test/Repository/Pdo/AuthCodeRepositoryTest.php | 2 +- test/Repository/Pdo/ClientRepositoryFactoryTest.php | 2 +- test/Repository/Pdo/RefreshTokenRepositoryFactoryTest.php | 2 +- test/Repository/Pdo/RefreshTokenRepositoryTest.php | 2 +- test/Repository/Pdo/ScopeRepositoryFactoryTest.php | 2 +- test/Repository/Pdo/ScopeRepositoryTest.php | 2 +- test/Repository/Pdo/UserRepositoryTest.php | 2 +- test/RepositoryTraitTest.php | 2 +- 23 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 14190f7..d8950e3 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -1,7 +1,7 @@ Date: Wed, 26 Sep 2018 11:45:11 -0500 Subject: [PATCH 10/10] Adds php-nightly build to travis So we can test against PHP 7.3. --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 05e0d40..0dee3e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,6 +33,9 @@ matrix: - php: 7.2 env: - DEPS=latest + - php: nightly + env: + - DEPS=latest before_install: - if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi