From f4b32a2bc6459b553dfaa4291d1f081af4e7247f Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Wed, 8 May 2013 13:34:05 -0700 Subject: [PATCH] Optimised tests by removing unused variables and adding further assertions --- tests/authorization/AuthServerTest.php | 20 ++++---- .../ClientCredentialsGrantTest.php | 20 ++++++-- tests/authorization/PasswordGrantTest.php | 50 +++++++++++-------- tests/authorization/RefreshTokenTest.php | 13 +++-- tests/resource/ResourceServerTest.php | 2 +- tests/util/RequestTest.php | 2 +- 6 files changed, 63 insertions(+), 44 deletions(-) diff --git a/tests/authorization/AuthServerTest.php b/tests/authorization/AuthServerTest.php index 66d59c99..616d85b1 100644 --- a/tests/authorization/AuthServerTest.php +++ b/tests/authorization/AuthServerTest.php @@ -25,12 +25,12 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase */ public function test__construct_NoStorage() { - $a = new League\OAuth2\Server\Authorization; + new League\OAuth2\Server\Authorization; } public function test__contruct_WithStorage() { - $a = $this->returnDefault(); + $this->returnDefault(); } public function test_getExceptionMessage() @@ -229,7 +229,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); - $v = $a->issueAccessToken(); + $a->issueAccessToken(); } /** @@ -241,7 +241,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); - $v = $a->issueAccessToken(array('grant_type' => 'foo')); + $a->issueAccessToken(array('grant_type' => 'foo')); } /** @@ -253,7 +253,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'authorization_code' )); } @@ -267,7 +267,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'authorization_code', 'client_id' => 1234 )); @@ -282,7 +282,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'authorization_code', 'client_id' => 1234, 'client_secret' => 5678 @@ -300,7 +300,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'authorization_code', 'client_id' => 1234, 'client_secret' => 5678, @@ -319,7 +319,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'authorization_code', 'client_id' => 1234, 'client_secret' => 5678, @@ -339,7 +339,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'authorization_code', 'client_id' => 1234, 'client_secret' => 5678, diff --git a/tests/authorization/ClientCredentialsGrantTest.php b/tests/authorization/ClientCredentialsGrantTest.php index 6bcf0635..d6bbb419 100644 --- a/tests/authorization/ClientCredentialsGrantTest.php +++ b/tests/authorization/ClientCredentialsGrantTest.php @@ -32,7 +32,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'client_credentials' )); } @@ -49,7 +49,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'client_credentials', 'client_id' => 1234 )); @@ -69,7 +69,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'client_credentials', 'client_id' => 1234, 'client_secret' => 5678 @@ -98,7 +98,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); $a->requireScopeParam(true); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'client_credentials', 'client_id' => 1234, 'client_secret' => 5678 @@ -139,6 +139,11 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase 'client_secret' => 5678, 'scope' => '' )); + + $this->assertArrayHasKey('access_token', $v); + $this->assertArrayHasKey('token_type', $v); + $this->assertArrayHasKey('expires', $v); + $this->assertArrayHasKey('expires_in', $v); } /** @@ -165,7 +170,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'client_credentials', 'client_id' => 1234, 'client_secret' => 5678, @@ -205,6 +210,11 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase 'client_secret' => 5678, 'scope' => 'blah' )); + + $this->assertArrayHasKey('access_token', $v); + $this->assertArrayHasKey('token_type', $v); + $this->assertArrayHasKey('expires', $v); + $this->assertArrayHasKey('expires_in', $v); } function test_issueAccessToken_clientCredentialsGrant_passedInput() diff --git a/tests/authorization/PasswordGrantTest.php b/tests/authorization/PasswordGrantTest.php index 84ee325e..3f5f79fa 100644 --- a/tests/authorization/PasswordGrantTest.php +++ b/tests/authorization/PasswordGrantTest.php @@ -32,7 +32,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'password' )); } @@ -49,7 +49,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'password', 'client_id' => 1234 )); @@ -69,7 +69,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'password', 'client_id' => 1234, 'client_secret' => 5678 @@ -102,7 +102,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'password', 'client_id' => 1234, 'client_secret' => 5678, @@ -131,14 +131,14 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('deleteSession')->andReturn(null); $this->session->shouldReceive('updateRefreshToken')->andReturn(null); - $testCredentials = function($u, $p) { return false; }; + $testCredentials = function() { return false; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'password', 'client_id' => 1234, 'client_secret' => 5678 @@ -165,14 +165,14 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('deleteSession')->andReturn(null); $this->session->shouldReceive('updateRefreshToken')->andReturn(null); - $testCredentials = function($u, $p) { return false; }; + $testCredentials = function() { return false; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'password', 'client_id' => 1234, 'client_secret' => 5678, @@ -200,14 +200,14 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('deleteSession')->andReturn(null); $this->session->shouldReceive('updateRefreshToken')->andReturn(null); - $testCredentials = function($u, $p) { return false; }; + $testCredentials = function() { return false; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'password', 'client_id' => 1234, 'client_secret' => 5678, @@ -237,14 +237,14 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('deleteSession')->andReturn(null); $this->session->shouldReceive('updateRefreshToken')->andReturn(null); - $testCredentials = function($u, $p) { return 1; }; + $testCredentials = function() { return 1; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'password', 'client_id' => 1234, 'client_secret' => 5678, @@ -273,7 +273,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('deleteSession')->andReturn(null); $this->session->shouldReceive('updateRefreshToken')->andReturn(null); - $testCredentials = function($u, $p) { return 1; }; + $testCredentials = function() { return 1; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); @@ -281,7 +281,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $a->addGrantType($pgrant); $a->requireScopeParam(true); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'password', 'client_id' => 1234, 'client_secret' => 5678, @@ -314,7 +314,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateScope')->andReturn(null); $this->session->shouldReceive('associateAccessToken')->andReturn(1); - $testCredentials = function($u, $p) { return 1; }; + $testCredentials = function() { return 1; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); @@ -331,6 +331,11 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase 'password' => 'bar', 'scope' => '' )); + + $this->assertArrayHasKey('access_token', $v); + $this->assertArrayHasKey('token_type', $v); + $this->assertArrayHasKey('expires', $v); + $this->assertArrayHasKey('expires_in', $v); } public function test_issueAccessToken_passwordGrant_goodScope() @@ -357,7 +362,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateScope')->andReturn(null); $this->session->shouldReceive('associateAccessToken')->andReturn(1); - $testCredentials = function($u, $p) { return 1; }; + $testCredentials = function() { return 1; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); @@ -372,6 +377,11 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase 'password' => 'bar', 'scope' => 'blah' )); + + $this->assertArrayHasKey('access_token', $v); + $this->assertArrayHasKey('token_type', $v); + $this->assertArrayHasKey('expires', $v); + $this->assertArrayHasKey('expires_in', $v); } function test_issueAccessToken_passwordGrant_passedInput() @@ -391,7 +401,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('updateRefreshToken')->andReturn(null); $this->session->shouldReceive('associateAccessToken')->andReturn(1); - $testCredentials = function($u, $p) { return 1; }; + $testCredentials = function() { return 1; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); @@ -433,7 +443,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('updateRefreshToken')->andReturn(null); $this->session->shouldReceive('associateAccessToken')->andReturn(1); - $testCredentials = function($u, $p) { return 1; }; + $testCredentials = function() { return 1; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); @@ -478,7 +488,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('updateRefreshToken')->andReturn(null); $this->session->shouldReceive('associateAccessToken')->andReturn(1); - $testCredentials = function($u, $p) { return 1; }; + $testCredentials = function() { return 1; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); @@ -526,7 +536,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateAccessToken')->andReturn(1); $this->session->shouldReceive('associateRefreshToken')->andReturn(null); - $testCredentials = function($u, $p) { return 1; }; + $testCredentials = function() { return 1; }; $a = $this->returnDefault(); $pgrant = new League\OAuth2\Server\Grant\Password($a); diff --git a/tests/authorization/RefreshTokenTest.php b/tests/authorization/RefreshTokenTest.php index 09c78a4e..ae05dfba 100644 --- a/tests/authorization/RefreshTokenTest.php +++ b/tests/authorization/RefreshTokenTest.php @@ -80,7 +80,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'refresh_token' )); } @@ -97,7 +97,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'refresh_token', 'client_id' => 1234 )); @@ -117,7 +117,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'refresh_token', 'client_id' => 1234, 'client_secret' => 5678 @@ -138,11 +138,10 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'refresh_token', 'client_id' => 1234, - 'client_secret' => 5678, - //'refresh_token' => + 'client_secret' => 5678 )); } @@ -161,7 +160,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); - $v = $a->issueAccessToken(array( + $a->issueAccessToken(array( 'grant_type' => 'refresh_token', 'client_id' => 1234, 'client_secret' => 5678, diff --git a/tests/resource/ResourceServerTest.php b/tests/resource/ResourceServerTest.php index c665f79f..2bc257df 100644 --- a/tests/resource/ResourceServerTest.php +++ b/tests/resource/ResourceServerTest.php @@ -80,7 +80,7 @@ class Resource_Server_test extends PHPUnit_Framework_TestCase $method = $reflector->getMethod('determineAccessToken'); $method->setAccessible(true); - $result = $method->invoke($s); + $method->invoke($s); } public function test_determineAccessToken_fromHeader() diff --git a/tests/util/RequestTest.php b/tests/util/RequestTest.php index e8b1c43a..1b4f144b 100644 --- a/tests/util/RequestTest.php +++ b/tests/util/RequestTest.php @@ -68,6 +68,6 @@ class Request_test extends PHPUnit_Framework_TestCase $method = $reflector->getMethod('getPropertyValue'); $method->setAccessible(true); - $result = $method->invoke($this->request, 'blah'); + $method->invoke($this->request, 'blah'); } } \ No newline at end of file