mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-26 16:52:04 +05:30
Optimised tests by removing unused variables and adding further assertions
This commit is contained in:
parent
e2350a65b1
commit
f4b32a2bc6
@ -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,
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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()
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user