Repository navigation
Expand file tree
/
Copy pathauthenticationTest.php
More file actions
executable file
·59 lines (36 loc) · 1.55 KB
/
Copy pathauthenticationTest.php
File metadata and controls
executable file
·59 lines (36 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
require_once dirname(__FILE__).'/vendor/lime.php';
require_once dirname(__FILE__).'/../lib/phpGitHubApi.php';
$t = new lime_test(5);
$username = 'ornicartest';
$token = 'fd8144e29b4a85e9487d1cacbcd4e26c';
$repo = 'php-github-api';
$api = new phpGitHubApi();
$t->comment('Get user with NO authentication');
$user = $api->getUserApi()->show($username);
$t->ok(!isset($user['plan']), 'User plan is not available');
$t->comment('Authenticate '.$username.' with default authentication method (should be username and token in URL)');
$api->authenticate($username, $token);
$t->comment('Get user with authentication');
$user = $api->getUserApi()->show($username);
$t->ok(isset($user['plan']), 'User plan is available');
$t->comment('Autentication: '.$username . ' using HTTP Basic Authentication with token');
$api->authenticate($username, $token, phpGitHubApi::AUTH_HTTP_TOKEN);
$user = $api->getUserApi()->show($username);
$t->ok(isset($user['plan']), 'User plan is available');
$t->comment('Deauthenticate');
$api->deAuthenticate();
$user = $api->getUserApi()->show($username);
$t->ok(!isset($user['plan']), 'User plan is not available');
$t->comment('Authenticate '.$username.' with bad token');
$api->authenticate($username, 'bad-token');
$t->comment('Get user with bad authentication');
try
{
$user = $api->getUserApi()->show($username);
$t->fail('Call with bad authentication throws a phpGitHubApiRequestException');
}
catch(phpGitHubApiRequestException $e)
{
$t->pass('Call with bad authentication throws a phpGitHubApiRequestException');
}