Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f448dd1

Browse files
committedNov 18, 2011
fixed tests
1 parent 0ed7b22 commit f448dd1

8 files changed

+67
-54
lines changed
 

‎.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "vendor/Symfony/Component/ClassLoader"]
2+
path = vendor/Symfony/Component/ClassLoader
3+
url = git://github.com/symfony/ClassLoader.git

‎lib/OAuth2/OAuth2ServerException.php

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace OAuth2;
44

5+
use Exception;
6+
57
/**
68
* OAuth2 errors that require termination of OAuth2 due to
79
* an error.

‎phpunit.xml.dist

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
bootstrap="tests/bootstrap.php"
13+
>
14+
<testsuites>
15+
<testsuite name="oauth2-php Test Suite">
16+
<directory>./tests</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<filter>
21+
<whitelist>
22+
<directory suffix=".php">./lib/</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>

‎tests/All_OAuth2_Tests.php

-29
This file was deleted.

‎tests/OAuth2OutputTest.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
2-
require_once(__DIR__ . '/../lib/OAuth2.php');
3-
require_once(__DIR__ . '/../lib/IOAuth2Storage.php');
4-
require_once(__DIR__ . '/../lib/IOAuth2GrantCode.php');
2+
3+
use OAuth2\OAuth2;
54

65
/**
76
* OAuth2 test cases that invovle capturing output.
@@ -21,7 +20,7 @@ public function testGrantAccessTokenWithGrantAuthCodeSuccess() {
2120
$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');
2221
$storedToken = array('redirect_uri' => 'http://www.example.com', 'client_id' => 'my_little_app', 'expires' => time() + 60);
2322

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

42-
$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
41+
$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
4342
$mockStorage->expects($this->any())
4443
->method('getAuthCode')
4544
->will($this->returnValue($storedToken));

‎tests/OAuth2Test.php

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22

3-
require_once(__DIR__ . '/../lib/OAuth2.php');
4-
require_once(__DIR__ . '/../lib/IOAuth2Storage.php');
5-
require_once(__DIR__ . '/../lib/IOAuth2GrantCode.php');
3+
use OAuth2\OAuth2;
4+
use OAuth2\OAuth2ServerException;
65

76
/**
87
* OAuth2 test case.
@@ -24,11 +23,11 @@ class OAuth2Test extends PHPUnit_Framework_TestCase {
2423
* Tests OAuth2->verifyAccessToken() with a missing token
2524
*/
2625
public function testVerifyAccessTokenWithNoParam() {
27-
$mockStorage = $this->getMock('IOAuth2Storage');
26+
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
2827
$this->fixture = new OAuth2($mockStorage);
2928

3029
$scope = null;
31-
$this->setExpectedException('OAuth2AuthenticateException');
30+
$this->setExpectedException('OAuth2\OAuth2AuthenticateException');
3231
$this->fixture->verifyAccessToken('', $scope);
3332
}
3433

@@ -38,15 +37,15 @@ public function testVerifyAccessTokenWithNoParam() {
3837
public function testVerifyAccessTokenInvalidToken() {
3938

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

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

4847
$scope = null;
49-
$this->setExpectedException('OAuth2AuthenticateException');
48+
$this->setExpectedException('OAuth2\OAuth2AuthenticateException');
5049
$this->fixture->verifyAccessToken($this->tokenId, $scope);
5150
}
5251

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

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

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

6867
$scope = null;
69-
$this->setExpectedException('OAuth2AuthenticateException');
68+
$this->setExpectedException('OAuth2\OAuth2AuthenticateException');
7069
$this->fixture->verifyAccessToken($this->tokenId, $scope);
7170
}
7271

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

8079
// Set up the mock storage to say this token does not exist
81-
$mockStorage = $this->getMock('IOAuth2Storage');
80+
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
8281
$mockStorage->expects($this->once())
8382
->method('getAccessToken')
8483
->will($this->returnValue($token));
@@ -95,7 +94,7 @@ public function testVerifyAccessTokenCheckExpiry($token, $expectedToPass) {
9594
$this->assertInternalType('array', $actual);
9695
}
9796
else {
98-
$this->setExpectedException('OAuth2AuthenticateException');
97+
$this->setExpectedException('OAuth2\OAuth2AuthenticateException');
9998
$this->fixture->verifyAccessToken($this->tokenId, $scope);
10099
}
101100
}
@@ -108,7 +107,7 @@ public function testVerifyAccessTokenCheckExpiry($token, $expectedToPass) {
108107
public function testVerifyAccessTokenCheckScope($scopeRequired, $token, $expectedToPass) {
109108

110109
// Set up the mock storage to say this token does not exist
111-
$mockStorage = $this->getMock('IOAuth2Storage');
110+
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
112111
$mockStorage->expects($this->once())
113112
->method('getAccessToken')
114113
->will($this->returnValue($token));
@@ -122,7 +121,7 @@ public function testVerifyAccessTokenCheckScope($scopeRequired, $token, $expecte
122121
$this->assertInternalType('array', $actual);
123122
}
124123
else {
125-
$this->setExpectedException('OAuth2AuthenticateException');
124+
$this->setExpectedException('OAuth2\OAuth2AuthenticateException');
126125
$this->fixture->verifyAccessToken($this->tokenId, $scopeRequired);
127126
}
128127
}
@@ -133,10 +132,10 @@ public function testVerifyAccessTokenCheckScope($scopeRequired, $token, $expecte
133132
* @dataProvider generateEmptyDataForGrant
134133
*/
135134
public function testGrantAccessTokenMissingData($inputData, $authHeaders) {
136-
$mockStorage = $this->getMock('IOAuth2Storage');
135+
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
137136
$this->fixture = new OAuth2($mockStorage);
138137

139-
$this->setExpectedException('OAuth2ServerException');
138+
$this->setExpectedException('OAuth2\OAuth2ServerException');
140139
$this->fixture->grantAccessToken($inputData, $authHeaders);
141140
}
142141

@@ -146,7 +145,7 @@ public function testGrantAccessTokenMissingData($inputData, $authHeaders) {
146145
* Tests the different ways client credentials can be provided.
147146
*/
148147
public function testGrantAccessTokenCheckClientCredentials() {
149-
$mockStorage = $this->getMock('IOAuth2Storage');
148+
$mockStorage = $this->getMock('OAuth2\IOAuth2Storage');
150149
$mockStorage->expects($this->any())
151150
->method('checkClientCredentials')
152151
->will($this->returnValue(TRUE)); // Always return true for any combination of user/pass
@@ -189,7 +188,7 @@ public function testGrantAccessTokenCheckClientCredentials() {
189188
*
190189
*/
191190
public function testGrantAccessTokenWithGrantAuthCodeMandatoryParams() {
192-
$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
191+
$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
193192
$inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'a', 'client_secret' => 'b');
194193
$fakeAuthCode = array('client_id' => $inputData['client_id'], 'redirect_uri' => '/foo', 'expires' => time() + 60);
195194
$fakeAccessToken = array('access_token' => 'abcde');
@@ -217,7 +216,7 @@ public function testGrantAccessTokenWithGrantAuthCodeMandatoryParams() {
217216
*
218217
*/
219218
public function testGrantAccessTokenWithGrantAuthCodeNoToken() {
220-
$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
219+
$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
221220
$inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'a', 'client_secret' => 'b', 'redirect_uri' => 'foo', 'code'=> 'foo');
222221

223222
// Ensure missing auth code raises an error
@@ -239,7 +238,7 @@ public function testGrantAccessTokenWithGrantAuthCodeRedirectChecked() {
239238
$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');
240239
$storedToken = array('redirect_uri' => 'http://www.example.com', 'client_id' => 'my_little_app', 'expires' => time() + 60);
241240

242-
$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
241+
$mockStorage = $this->createBaseMock('Oauth2\IOAuth2GrantCode');
243242
$mockStorage->expects($this->any())
244243
->method('getAuthCode')
245244
->will($this->returnValue($storedToken));
@@ -264,7 +263,7 @@ public function testGrantAccessTokenWithGrantAuthCodeClientIdChecked() {
264263
$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');
265264
$storedToken = array('client_id' => 'my_little_app', 'redirect_uri' => 'http://www.example.com', 'expires' => time() + 60);
266265

267-
$mockStorage = $this->createBaseMock('IOAuth2GrantCode');
266+
$mockStorage = $this->createBaseMock('OAuth2\IOAuth2GrantCode');
268267
$mockStorage->expects($this->any())
269268
->method('getAuthCode')
270269
->will($this->returnValue($storedToken));

‎tests/bootstrap.php

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Symfony\Component\ClassLoader\UniversalClassLoader;
4+
5+
require_once __DIR__ . '/../vendor/Symfony/Component/ClassLoader/UniversalClassLoader.php';
6+
7+
$loader = new UniversalClassLoader;
8+
$loader->registerNamespaces(array(
9+
'OAuth2' => __DIR__.'/../lib',
10+
));
11+
12+
$loader->register();
13+

‎vendor/Symfony/Component/ClassLoader

Submodule ClassLoader added at 5cd07e4

0 commit comments

Comments
 (0)
Please sign in to comment.