This repository was archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Improving unit tests coverage #49
Merged
weierophinney
merged 10 commits into
zendframework:master
from
ezimuel:fix/improving-test-coverage
Sep 26, 2018
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1911c3d
WIP: improving unit tests
ezimuel a03545a
Improve unit tests completed
ezimuel bba9b21
Resolved comments on PR #49
ezimuel 458d26a
Minor CS/consistency changes
weierophinney c569c1c
Write tests for ClientEntity constructor
weierophinney c641138
Fixes typo in method name of RevokableTraitTest
weierophinney 3c4a356
Better test method name in ScopeEntityTest
weierophinney 0a83f12
One line per object operation
weierophinney cc0a998
Updates copyright dates on all files touched by this patch
weierophinney 7acf6b8
Adds php-nightly build to travis
weierophinney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| <?php | ||
| /** | ||
| * @see https://github.com/zendframework/zend-expressive-authentication-oauth2 for the canonical source repository | ||
| * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
| * @license https://github.com/zendframework/zend-expressive-authentication-oauth2/blob/master/LICENSE.md | ||
| * New BSD License | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ZendTest\Expressive\Authentication\OAuth2; | ||
|
|
||
| use PHPUnit\Framework\TestCase; | ||
| use Psr\Container\ContainerInterface; | ||
| use Zend\Expressive\Authentication\OAuth2\ConfigTrait; | ||
|
|
||
| class ConfigTraitTest extends TestCase | ||
| { | ||
| public function setUp() | ||
| { | ||
| $this->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 testGetPrivateKeyWhenNoConfigPresentWillResultInAnException() | ||
| { | ||
| $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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
| /** | ||
| * @see https://github.com/zendframework/zend-expressive-authentication-oauth2 for the canonical source repository | ||
| * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
| * @license https://github.com/zendframework/zend-expressive-authentication-oauth2/blob/master/LICENSE.md | ||
| * New BSD License | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ZendTest\Expressive\Authentication\OAuth2\Entity; | ||
|
|
||
| use League\OAuth2\Server\Entities\AccessTokenEntityInterface; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Zend\Expressive\Authentication\OAuth2\Entity\AccessTokenEntity; | ||
|
|
||
| class AccessTokenEntityTest extends TestCase | ||
| { | ||
| public function testImplementsInstanceAccessTokenEntityInterface() | ||
| { | ||
| $entity = new AccessTokenEntity(); | ||
| $this->assertInstanceOf(AccessTokenEntityInterface::class, $entity); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
| /** | ||
| * @see https://github.com/zendframework/zend-expressive-authentication-oauth2 for the canonical source repository | ||
| * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
| * @license https://github.com/zendframework/zend-expressive-authentication-oauth2/blob/master/LICENSE.md | ||
| * New BSD License | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ZendTest\Expressive\Authentication\OAuth2\Entity; | ||
|
|
||
| use League\OAuth2\Server\Entities\AuthCodeEntityInterface; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Zend\Expressive\Authentication\OAuth2\Entity\AuthCodeEntity; | ||
|
|
||
| class AuthCodeEntityTest extends TestCase | ||
| { | ||
| public function testImplementsInstanceAuthCodeEntityInterface() | ||
| { | ||
| $entity = new AuthCodeEntity(); | ||
| $this->assertInstanceOf(AuthCodeEntityInterface::class, $entity); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?php | ||
| /** | ||
| * @see https://github.com/zendframework/zend-expressive-authentication-oauth2 for the canonical source repository | ||
| * @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com) | ||
| * @license https://github.com/zendframework/zend-expressive-authentication-oauth2/blob/master/LICENSE.md | ||
| * New BSD License | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ZendTest\Expressive\Authentication\OAuth2\Entity; | ||
|
|
||
| use League\OAuth2\Server\Entities\ClientEntityInterface; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Zend\Expressive\Authentication\OAuth2\Entity\ClientEntity; | ||
|
|
||
| class ClientEntityTest extends TestCase | ||
| { | ||
| public function setUp() | ||
| { | ||
| $this->entity = new ClientEntity('foo', 'bar', 'http://localhost'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would write tests that ensure that the values passed to the constructor affected the state of the constructed entity. |
||
| } | ||
|
|
||
| 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'); | ||
| $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()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this test. If it's just testing that the constructor returns an instance of the class, that's something we know already.
If there's other behavior to test — e.g., default property values, property values based on constructor arguments, etc. — then tests make sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remove the AccessTokenEntityTest we need to use
@codeCoverageIgnoreto omit this class from the code coverage. IMHO I think a test class like this, even if just checking for constructor, can be useful as a constrain for future changes. For instance, if someone changes theAccessTokenEntityInterfacethis test is able to intercept it.