Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb committed Nov 18, 2011
1 parent 0ed7b22 commit f448dd1
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "vendor/Symfony/Component/ClassLoader"]
path = vendor/Symfony/Component/ClassLoader
url = git://github.com/symfony/ClassLoader.git
2 changes: 2 additions & 0 deletions lib/OAuth2/OAuth2ServerException.php
Expand Up @@ -2,6 +2,8 @@

namespace OAuth2;

use Exception;

/**
* OAuth2 errors that require termination of OAuth2 due to
* an error.
Expand Down
25 changes: 25 additions & 0 deletions phpunit.xml.dist
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="oauth2-php Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">./lib/</directory>
</whitelist>
</filter>
</phpunit>
29 changes: 0 additions & 29 deletions tests/All_OAuth2_Tests.php

This file was deleted.

9 changes: 4 additions & 5 deletions tests/OAuth2OutputTest.php
@@ -1,7 +1,6 @@
<?php
require_once(__DIR__ . '/../lib/OAuth2.php');
require_once(__DIR__ . '/../lib/IOAuth2Storage.php');
require_once(__DIR__ . '/../lib/IOAuth2GrantCode.php');

use OAuth2\OAuth2;

/**
* OAuth2 test cases that invovle capturing output.
Expand All @@ -21,7 +20,7 @@ public function testGrantAccessTokenWithGrantAuthCodeSuccess() {
$inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'redirect_uri' => 'http://www.example.com/my/subdir', 'client_id' => 'my_little_app', 'client_secret' => 'b', 'code'=> 'foo');
$storedToken = array('redirect_uri' => 'http://www.example.com', 'client_id' => 'my_little_app', 'expires' => time() + 60);

$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
$mockStorage->expects($this->any())
->method('getAuthCode')
->will($this->returnValue($storedToken));
Expand All @@ -39,7 +38,7 @@ public function testGrantAccessTokenWithGrantAuthCodeSuccessWithoutRedirect() {
$inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'my_little_app', 'client_secret' => 'b', 'code'=> 'foo');
$storedToken = array('redirect_uri' => 'http://www.example.com', 'client_id' => 'my_little_app', 'expires' => time() + 60);

$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
$mockStorage->expects($this->any())
->method('getAuthCode')
->will($this->returnValue($storedToken));
Expand Down
39 changes: 19 additions & 20 deletions tests/OAuth2Test.php
@@ -1,8 +1,7 @@
<?php

require_once(__DIR__ . '/../lib/OAuth2.php');
require_once(__DIR__ . '/../lib/IOAuth2Storage.php');
require_once(__DIR__ . '/../lib/IOAuth2GrantCode.php');
use OAuth2\OAuth2;
use OAuth2\OAuth2ServerException;

/**
* OAuth2 test case.
Expand All @@ -24,11 +23,11 @@ class OAuth2Test extends PHPUnit_Framework_TestCase {
* Tests OAuth2->verifyAccessToken() with a missing token
*/
public function testVerifyAccessTokenWithNoParam() {
$mockStorage = $this->getMock('IOAuth2Storage');
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
$this->fixture = new OAuth2($mockStorage);

$scope = null;
$this->setExpectedException('OAuth2AuthenticateException');
$this->setExpectedException('OAuth2\OAuth2AuthenticateException');
$this->fixture->verifyAccessToken('', $scope);
}

Expand All @@ -38,15 +37,15 @@ public function testVerifyAccessTokenWithNoParam() {
public function testVerifyAccessTokenInvalidToken() {

// Set up the mock storage to say this token does not exist
$mockStorage = $this->getMock('IOAuth2Storage');
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
$mockStorage->expects($this->once())
->method('getAccessToken')
->will($this->returnValue(false));

$this->fixture = new OAuth2($mockStorage);

$scope = null;
$this->setExpectedException('OAuth2AuthenticateException');
$this->setExpectedException('OAuth2\OAuth2AuthenticateException');
$this->fixture->verifyAccessToken($this->tokenId, $scope);
}

Expand All @@ -58,15 +57,15 @@ public function testVerifyAccessTokenInvalidToken() {
public function testVerifyAccessTokenMalformedToken($token) {

// Set up the mock storage to say this token does not exist
$mockStorage = $this->getMock('IOAuth2Storage');
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
$mockStorage->expects($this->once())
->method('getAccessToken')
->will($this->returnValue($token));

$this->fixture = new OAuth2($mockStorage);

$scope = null;
$this->setExpectedException('OAuth2AuthenticateException');
$this->setExpectedException('OAuth2\OAuth2AuthenticateException');
$this->fixture->verifyAccessToken($this->tokenId, $scope);
}

Expand All @@ -78,7 +77,7 @@ public function testVerifyAccessTokenMalformedToken($token) {
public function testVerifyAccessTokenCheckExpiry($token, $expectedToPass) {

// Set up the mock storage to say this token does not exist
$mockStorage = $this->getMock('IOAuth2Storage');
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
$mockStorage->expects($this->once())
->method('getAccessToken')
->will($this->returnValue($token));
Expand All @@ -95,7 +94,7 @@ public function testVerifyAccessTokenCheckExpiry($token, $expectedToPass) {
$this->assertInternalType('array', $actual);
}
else {
$this->setExpectedException('OAuth2AuthenticateException');
$this->setExpectedException('OAuth2\OAuth2AuthenticateException');
$this->fixture->verifyAccessToken($this->tokenId, $scope);
}
}
Expand All @@ -108,7 +107,7 @@ public function testVerifyAccessTokenCheckExpiry($token, $expectedToPass) {
public function testVerifyAccessTokenCheckScope($scopeRequired, $token, $expectedToPass) {

// Set up the mock storage to say this token does not exist
$mockStorage = $this->getMock('IOAuth2Storage');
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
$mockStorage->expects($this->once())
->method('getAccessToken')
->will($this->returnValue($token));
Expand All @@ -122,7 +121,7 @@ public function testVerifyAccessTokenCheckScope($scopeRequired, $token, $expecte
$this->assertInternalType('array', $actual);
}
else {
$this->setExpectedException('OAuth2AuthenticateException');
$this->setExpectedException('OAuth2\OAuth2AuthenticateException');
$this->fixture->verifyAccessToken($this->tokenId, $scopeRequired);
}
}
Expand All @@ -133,10 +132,10 @@ public function testVerifyAccessTokenCheckScope($scopeRequired, $token, $expecte
* @dataProvider generateEmptyDataForGrant
*/
public function testGrantAccessTokenMissingData($inputData, $authHeaders) {
$mockStorage = $this->getMock('IOAuth2Storage');
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
$this->fixture = new OAuth2($mockStorage);

$this->setExpectedException('OAuth2ServerException');
$this->setExpectedException('OAuth2\OAuth2ServerException');
$this->fixture->grantAccessToken($inputData, $authHeaders);
}

Expand All @@ -146,7 +145,7 @@ public function testGrantAccessTokenMissingData($inputData, $authHeaders) {
* Tests the different ways client credentials can be provided.
*/
public function testGrantAccessTokenCheckClientCredentials() {
$mockStorage = $this->getMock('IOAuth2Storage');
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
$mockStorage->expects($this->any())
->method('checkClientCredentials')
->will($this->returnValue(TRUE)); // Always return true for any combination of user/pass
Expand Down Expand Up @@ -189,7 +188,7 @@ public function testGrantAccessTokenCheckClientCredentials() {
*
*/
public function testGrantAccessTokenWithGrantAuthCodeMandatoryParams() {
$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
$inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'a', 'client_secret' => 'b');
$fakeAuthCode = array('client_id' => $inputData['client_id'], 'redirect_uri' => '/foo', 'expires' => time() + 60);
$fakeAccessToken = array('access_token' => 'abcde');
Expand Down Expand Up @@ -217,7 +216,7 @@ public function testGrantAccessTokenWithGrantAuthCodeMandatoryParams() {
*
*/
public function testGrantAccessTokenWithGrantAuthCodeNoToken() {
$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
$inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'a', 'client_secret' => 'b', 'redirect_uri' => 'foo', 'code'=> 'foo');

// Ensure missing auth code raises an error
Expand All @@ -239,7 +238,7 @@ public function testGrantAccessTokenWithGrantAuthCodeRedirectChecked() {
$inputData = array('redirect_uri' => 'http://www.crossdomain.com/my/subdir', 'grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'my_little_app', 'client_secret' => 'b', 'code'=> 'foo');
$storedToken = array('redirect_uri' => 'http://www.example.com', 'client_id' => 'my_little_app', 'expires' => time() + 60);

$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
$mockStorage = $this->createBaseMock('Oauth2\IOAuth2GrantCode');
$mockStorage->expects($this->any())
->method('getAuthCode')
->will($this->returnValue($storedToken));
Expand All @@ -264,7 +263,7 @@ public function testGrantAccessTokenWithGrantAuthCodeClientIdChecked() {
$inputData = array('client_id' => 'another_app', 'grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'redirect_uri' => 'http://www.example.com/my/subdir', 'client_secret' => 'b', 'code'=> 'foo');
$storedToken = array('client_id' => 'my_little_app', 'redirect_uri' => 'http://www.example.com', 'expires' => time() + 60);

$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
$mockStorage->expects($this->any())
->method('getAuthCode')
->will($this->returnValue($storedToken));
Expand Down
13 changes: 13 additions & 0 deletions tests/bootstrap.php
@@ -0,0 +1,13 @@
<?php

use Symfony\Component\ClassLoader\UniversalClassLoader;

require_once __DIR__ . '/../vendor/Symfony/Component/ClassLoader/UniversalClassLoader.php';

$loader = new UniversalClassLoader;
$loader->registerNamespaces(array(
'OAuth2' => __DIR__.'/../lib',
));

$loader->register();

1 change: 1 addition & 0 deletions vendor/Symfony/Component/ClassLoader
Submodule ClassLoader added at 5cd07e

0 comments on commit f448dd1

Please sign in to comment.