PSR fixes

This commit is contained in:
Alex Bilbie 2012-12-23 21:36:30 +00:00
parent 0f30b2a803
commit df85c98e53

View File

@ -1,18 +1,21 @@
<?php <?php
class Authentication_Server_test extends PHPUnit_Framework_TestCase { class Authentication_Server_test extends PHPUnit_Framework_TestCase
function setUp()
{ {
public function setUp()
{
require 'src/OAuth2/Authentication/Server.php';
require 'src/OAuth2/Authentication/Database.php';
$this->oauth = new Oauth2\Authentication\Server(); $this->oauth = new Oauth2\Authentication\Server();
require_once('database_mock.php'); require_once 'database_mock.php';
$this->oauthdb = new OAuthdb(); $this->oauthdb = new OAuthdb();
$this->assertInstanceOf('Oauth2\Authentication\Database', $this->oauthdb); $this->assertInstanceOf('Oauth2\Authentication\Database', $this->oauthdb);
$this->oauth->registerDbAbstractor($this->oauthdb); $this->oauth->registerDbAbstractor($this->oauthdb);
} }
function test_generateCode() public function test_generateCode()
{ {
$reflector = new ReflectionClass($this->oauth); $reflector = new ReflectionClass($this->oauth);
$method = $reflector->getMethod('generateCode'); $method = $reflector->getMethod('generateCode');
@ -25,7 +28,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
$this->assertNotEquals($result, $result2); $this->assertNotEquals($result, $result2);
} }
function test_redirectUri() public function test_redirectUri()
{ {
$result1 = $this->oauth->redirectUri('http://example.com/foo'); $result1 = $this->oauth->redirectUri('http://example.com/foo');
$result2 = $this->oauth->redirectUri('http://example.com/foo', array('foo' => 'bar')); $result2 = $this->oauth->redirectUri('http://example.com/foo', array('foo' => 'bar'));
@ -36,7 +39,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://example.com/foo#foo=bar', $result3); $this->assertEquals('http://example.com/foo#foo=bar', $result3);
} }
function test_checkClientAuthoriseParams_GET() public function test_checkClientAuthoriseParams_GET()
{ {
$_GET['client_id'] = 'test'; $_GET['client_id'] = 'test';
$_GET['redirect_uri'] = 'http://example.com/test'; $_GET['redirect_uri'] = 'http://example.com/test';
@ -62,7 +65,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
$this->assertEquals($expect, $result); $this->assertEquals($expect, $result);
} }
function test_checkClientAuthoriseParams_PassedParams() public function test_checkClientAuthoriseParams_PassedParams()
{ {
unset($_GET['client_id']); unset($_GET['client_id']);
unset($_GET['redirect_uri']); unset($_GET['redirect_uri']);
@ -93,7 +96,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_checkClientAuthoriseParams_missingClientId() public function test_checkClientAuthoriseParams_missingClientId()
{ {
$this->oauth->checkClientAuthoriseParams(); $this->oauth->checkClientAuthoriseParams();
} }
@ -102,7 +105,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_checkClientAuthoriseParams_missingRedirectUri() public function test_checkClientAuthoriseParams_missingRedirectUri()
{ {
$_GET['client_id'] = 'test'; $_GET['client_id'] = 'test';
@ -113,7 +116,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_checkClientAuthoriseParams_missingResponseType() public function test_checkClientAuthoriseParams_missingResponseType()
{ {
$_GET['client_id'] = 'test'; $_GET['client_id'] = 'test';
$_GET['redirect_uri'] = 'http://example.com/test'; $_GET['redirect_uri'] = 'http://example.com/test';
@ -125,7 +128,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_checkClientAuthoriseParams_missingScopes() public function test_checkClientAuthoriseParams_missingScopes()
{ {
$_GET['client_id'] = 'test'; $_GET['client_id'] = 'test';
$_GET['redirect_uri'] = 'http://example.com/test'; $_GET['redirect_uri'] = 'http://example.com/test';
@ -139,7 +142,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 4 * @expectedExceptionCode 4
*/ */
function test_checkClientAuthoriseParams_invalidScopes() public function test_checkClientAuthoriseParams_invalidScopes()
{ {
$_GET['client_id'] = 'test'; $_GET['client_id'] = 'test';
$_GET['redirect_uri'] = 'http://example.com/test'; $_GET['redirect_uri'] = 'http://example.com/test';
@ -149,7 +152,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
$this->oauth->checkClientAuthoriseParams(); $this->oauth->checkClientAuthoriseParams();
} }
function test_newAuthoriseRequest() public function test_newAuthoriseRequest()
{ {
$result = $this->oauth->newAuthoriseRequest('user', '123', array( $result = $this->oauth->newAuthoriseRequest('user', '123', array(
'client_id' => 'test', 'client_id' => 'test',
@ -165,7 +168,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
$this->assertEquals(40, strlen($result)); $this->assertEquals(40, strlen($result));
} }
function test_newAuthoriseRequest_isUnique() public function test_newAuthoriseRequest_isUnique()
{ {
$result1 = $this->oauth->newAuthoriseRequest('user', '123', array( $result1 = $this->oauth->newAuthoriseRequest('user', '123', array(
'client_id' => 'test', 'client_id' => 'test',
@ -192,7 +195,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
$this->assertNotEquals($result1, $result2); $this->assertNotEquals($result1, $result2);
} }
function test_issueAccessToken_POST() public function test_issueAccessToken_POST()
{ {
$auth_code = $this->oauth->newAuthoriseRequest('user', '123', array( $auth_code = $this->oauth->newAuthoriseRequest('user', '123', array(
'client_id' => 'test', 'client_id' => 'test',
@ -219,7 +222,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
$this->assertArrayHasKey('expires_in', $result); $this->assertArrayHasKey('expires_in', $result);
} }
function test_issueAccessToken_PassedParams() public function test_issueAccessToken_PassedParams()
{ {
$auth_code = $this->oauth->newAuthoriseRequest('user', '123', array( $auth_code = $this->oauth->newAuthoriseRequest('user', '123', array(
'client_id' => 'test', 'client_id' => 'test',
@ -250,7 +253,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_issueAccessToken_missingGrantType() public function test_issueAccessToken_missingGrantType()
{ {
$this->oauth->issueAccessToken(); $this->oauth->issueAccessToken();
} }
@ -259,7 +262,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 7 * @expectedExceptionCode 7
*/ */
function test_issueAccessToken_unsupportedGrantType() public function test_issueAccessToken_unsupportedGrantType()
{ {
$params['grant_type'] = 'blah'; $params['grant_type'] = 'blah';
@ -270,7 +273,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_completeAuthCodeGrant_missingClientId() public function test_completeAuthCodeGrant_missingClientId()
{ {
$reflector = new ReflectionClass($this->oauth); $reflector = new ReflectionClass($this->oauth);
$method = $reflector->getMethod('completeAuthCodeGrant'); $method = $reflector->getMethod('completeAuthCodeGrant');
@ -283,7 +286,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_completeAuthCodeGrant_missingClientSecret() public function test_completeAuthCodeGrant_missingClientSecret()
{ {
$reflector = new ReflectionClass($this->oauth); $reflector = new ReflectionClass($this->oauth);
$method = $reflector->getMethod('completeAuthCodeGrant'); $method = $reflector->getMethod('completeAuthCodeGrant');
@ -298,7 +301,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_completeAuthCodeGrant_missingRedirectUri() public function test_completeAuthCodeGrant_missingRedirectUri()
{ {
$reflector = new ReflectionClass($this->oauth); $reflector = new ReflectionClass($this->oauth);
$method = $reflector->getMethod('completeAuthCodeGrant'); $method = $reflector->getMethod('completeAuthCodeGrant');
@ -314,7 +317,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 8 * @expectedExceptionCode 8
*/ */
function test_completeAuthCodeGrant_invalidClient() public function test_completeAuthCodeGrant_invalidClient()
{ {
$reflector = new ReflectionClass($this->oauth); $reflector = new ReflectionClass($this->oauth);
$method = $reflector->getMethod('completeAuthCodeGrant'); $method = $reflector->getMethod('completeAuthCodeGrant');
@ -331,7 +334,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 0 * @expectedExceptionCode 0
*/ */
function test_completeAuthCodeGrant_missingCode() public function test_completeAuthCodeGrant_missingCode()
{ {
$reflector = new ReflectionClass($this->oauth); $reflector = new ReflectionClass($this->oauth);
$method = $reflector->getMethod('completeAuthCodeGrant'); $method = $reflector->getMethod('completeAuthCodeGrant');
@ -348,7 +351,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ClientException * @expectedException Oauth2\Authentication\ClientException
* @expectedExceptionCode 9 * @expectedExceptionCode 9
*/ */
function test_completeAuthCodeGrant_invalidCode() public function test_completeAuthCodeGrant_invalidCode()
{ {
$reflector = new ReflectionClass($this->oauth); $reflector = new ReflectionClass($this->oauth);
$method = $reflector->getMethod('completeAuthCodeGrant'); $method = $reflector->getMethod('completeAuthCodeGrant');
@ -366,7 +369,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ServerException * @expectedException Oauth2\Authentication\ServerException
* @expectedExceptionMessage No registered database abstractor * @expectedExceptionMessage No registered database abstractor
*/ */
function test_noRegisteredDatabaseAbstractor() public function test_noRegisteredDatabaseAbstractor()
{ {
$reflector = new ReflectionClass($this->oauth); $reflector = new ReflectionClass($this->oauth);
$method = $reflector->getMethod('_dbCall'); $method = $reflector->getMethod('_dbCall');
@ -383,7 +386,7 @@ class Authentication_Server_test extends PHPUnit_Framework_TestCase {
* @expectedException Oauth2\Authentication\ServerException * @expectedException Oauth2\Authentication\ServerException
* @expectedExceptionMessage Registered database abstractor is not an instance of Oauth2\Authentication\Database * @expectedExceptionMessage Registered database abstractor is not an instance of Oauth2\Authentication\Database
*/ */
function test_invalidRegisteredDatabaseAbstractor() public function test_invalidRegisteredDatabaseAbstractor()
{ {
$fake = new stdClass; $fake = new stdClass;
$this->oauth->registerDbAbstractor($fake); $this->oauth->registerDbAbstractor($fake);