$t->comment('Watch a repository'); $repository = $github->getRepoApi()->watch('ornicar', 'php-git-repo'); $t->is($repository['name'], 'php-git-repo', 'Watching php-git-repo'); // fork method $t->comment('Fork a repository'); $repository = $github->getRepoApi()->fork('ornicar', 'php-git-repo'); $t->is($repository['name'], 'php-git-repo', 'Forked php-git-repo'); $repository = $github->getRepoApi()->delete('php-git-repo', null, true); $t->is($response['status'], 'deleted', 'Fork is deleted'); // unwatch method $t->comment('Unwatch a repository'); $repository = $github->getRepoApi()->unwatch('ornicar', 'php-git-repo'); $t->is($repository['name'], 'php-git-repo', 'Unwatching php-git-repo'); // deauthenticate back to anonymous state $t->comment('Deauthenticating'); $github->deAuthenticate(); // getRepoContributors method $t->comment('Get contributors for a repository'); $contributors = $github->getRepoApi()->getRepoContributors('ornicar', 'php-github-api'); $t->ok(count($contributors) > 2, 'Found ' . count($contributors) . ' contributors'); $t->is($contributors[0]['login'], 'ornicar', 'First contributor is ornicar'); // getRepoTags method $t->comment('Get tags for a repository'); $tags = $github->getRepoApi()->getRepoTags('ornicar', 'php-github-api'); $t->ok(count($tags) > 5, 'Found ' . count($tags) . ' tags'); $tagNames = array_keys($tags); $t->ok($tagNames[0], 'First tag name: ' . $tagNames[0]); // getRepoBranches method $t->comment('Get branches for a repository'); $branches = $github->getRepoApi()->getRepoBranches('ornicar', 'php-github-api'); $t->ok(count($branches) > 0, 'Found ' . count($branches) . ' branch(es)');
require_once dirname(__FILE__) . '/../lib/phpGitHubApi.php'; $t = new lime_test(5); $username = '******'; $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'); }