diff --git a/README.md b/README.md index 1bf8be42c06..9d6637d85f2 100644 --- a/README.md +++ b/README.md @@ -20,30 +20,29 @@ Uses [GitHub API v3](http://developer.github.com/v3/) & supports [GitHub API v4] ## Requirements * PHP >= 7.1 -* A [HTTP client](https://packagist.org/providers/psr/http-client-implementation) -* A [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation) -* (optional) PHPUnit to run tests. +* A [PSR-17 implementation](https://packagist.org/providers/psr/http-factory-implementation) +* A [PSR-18 implementation](https://packagist.org/providers/psr/http-client-implementation) ## Install Via [Composer](https://getcomposer.org). -### PHP 7.2+: +### PHP 7.1+: ```bash -composer require knplabs/github-api guzzlehttp/guzzle:^7.0.1 +composer require knplabs/github-api:^3.0 php-http/guzzle6-adapter:^2.0.1 http-interop/http-factory-guzzle:^1.0 ``` -### PHP 7.1+: +### PHP 7.2+: ```bash -composer require knplabs/github-api php-http/guzzle6-adapter:^2.0.1 +composer require knplabs/github-api:^3.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 ``` -### Laravel 5.5+: +### Laravel 6+: ```bash -composer require graham-campbell/github guzzlehttp/guzzle:^7.0.1 +composer require graham-campbell/github^10.0 guzzlehttp/guzzle:^7.0.1 http-interop/http-factory-guzzle:^1.0 ``` We are decoupled from any HTTP messaging client with help by [HTTPlug](http://httplug.io). Read about clients in our [docs](doc/customize.md). [graham-campbell/github](https://github.com/GrahamCampbell/Laravel-GitHub) is by [Graham Campbell](https://github.com/GrahamCampbell). diff --git a/composer.json b/composer.json index c7e42f8f372..4fd67392037 100644 --- a/composer.json +++ b/composer.json @@ -18,21 +18,26 @@ ], "require": { "php": "^7.1", - "php-http/client-common": "^2.1", + "php-http/client-common": "^2.2", "php-http/cache-plugin": "^1.7", - "php-http/discovery": "^1.7", + "php-http/discovery": "^1.9", "php-http/httplug": "^2.1", + "php-http/multipart-stream-builder": "^1.1", "psr/cache": "^1.0", "psr/http-client-implementation": "^1.0", + "psr/http-factory-implementation": "^1.0", "psr/http-message": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^7.0 || ^8.0", - "php-http/guzzle6-adapter": "^2.0", - "php-http/mock-client": "^1.2", - "guzzlehttp/psr7": "^1.2", - "cache/array-adapter": "^0.4", - "phpstan/phpstan": "^0.12.23" + "cache/array-adapter": "^1.0.1", + "guzzlehttp/psr7": "^1.5.2", + "http-interop/http-factory-guzzle": "^1.0", + "php-http/guzzle6-adapter": "^2.0.1", + "php-http/mock-client": "^1.4", + "phpstan/phpstan": "^0.12.32", + "phpstan/extension-installer": "^1.0.4", + "phpstan/phpstan-deprecation-rules": "^0.12.4", + "phpunit/phpunit": "^7.5.15 || ^8.4 || ^9.0" }, "autoload": { "psr-4": { "Github\\": "lib/Github/" } @@ -40,8 +45,6 @@ "autoload-dev": { "psr-4": { "Github\\Tests\\": "test/Github/Tests/"} }, - "minimum-stability": "dev", - "prefer-stable": true, "extra": { "branch-alias": { "dev-master": "3.0.x-dev" diff --git a/doc/rate_limits.md b/doc/rate_limits.md index 3239a44b612..454981d0b4f 100644 --- a/doc/rate_limits.md +++ b/doc/rate_limits.md @@ -5,7 +5,6 @@ Get rate limit wrappers from [GitHub Rate Limit API](http://developer.github.com #### Get All Rate Limits -##### new way ```php /** @var \Github\Api\RateLimit\RateLimitResource[] $rateLimits */ $rateLimits = $client->api('rate_limit')->getResources(); @@ -61,14 +60,6 @@ array(4) { } ``` - -##### deprecated way - -```php -/** @var array $rateLimits */ -$rateLimits = $client->api('rate_limit')->getRateLimits(); -``` - #### Get Core Rate Limit ```php diff --git a/doc/security.md b/doc/security.md index 1ced88b97c2..1af022a90d5 100644 --- a/doc/security.md +++ b/doc/security.md @@ -6,47 +6,29 @@ properties on Repositories and some others. Therefore this step is facultative. ### Authenticate -GitHub provides some different ways of authentication. This API implementation implements three of them which are handled by one function: +GitHub provides some different ways of authentication. This API implementation implements three of them which are +handled by one function: ```php $client->authenticate($usernameOrToken, $password, $method); ``` `$usernameOrToken` is, of course, the username (or in some cases token/client ID, more details you can find below), -and guess what should contain `$password`. The `$method` can contain one of the five allowed values: - -#### Deprecated methods -* `Github\Client::AUTH_URL_TOKEN` use `Github\Client::AUTH_ACCESS_TOKEN` instead. -* `Github\Client::AUTH_URL_CLIENT_ID` use `Github\Client::AUTH_CLIENT_ID` instead. -* `Github\Client::AUTH_HTTP_TOKEN` use `Github\Client::AUTH_ACCESS_TOKEN` instead. -* `Github\Client::AUTH_HTTP_PASSWORD` use `Github\Client::AUTH_ACCESS_TOKEN` instead. +and guess what should contain `$password`. The `$method` can contain one of the three allowed values: #### Supported methods * `Github\Client::AUTH_CLIENT_ID` - https://developer.github.com/v3/#oauth2-keysecret * `Github\Client::AUTH_ACCESS_TOKEN` - https://developer.github.com/v3/#oauth2-token-sent-in-a-header * `Github\Client::AUTH_JWT` - https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#authenticating-as-a-github-app -The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_URL_TOKEN`, -`Github\Client::AUTH_HTTP_TOKEN` and `Github\Client::JWT` methods you should provide the API token in -`$usernameOrToken` variable (`$password` is omitted in this particular case). For the -`Github\Client::AUTH_HTTP_PASSWORD`, you should provide the password of the account. When using `Github\Client::AUTH_URL_CLIENT_ID` -`$usernameOrToken` should contain your client ID, and `$password` should contain client secret. - -After executing the `$client->authenticate($usernameOrToken, $secret, $method);` method using correct credentials, -all further requests are done as the given user. +The required value of `$password` depends on the chosen `$method`. For `Github\Client::AUTH_ACCESS_TOKEN` and +`Github\Client::JWT` methods you should provide the API token in `$usernameOrToken` variable (`$password` is omitted in +this particular case). -### About authentication methods - -The `Github\Client::AUTH_URL_TOKEN` authentication method sends the API token in URL parameters. -The `Github\Client::AUTH_URL_CLIENT_ID` authentication method sends the client ID and secret in URL parameters. -The `Github\Client::AUTH_HTTP_*` authentication methods send their values to GitHub using HTTP Basic Authentication. The `Github\Client::AUTH_JWT` authentication method sends the specified JSON Web Token in an Authorization header. -`Github\Client::AUTH_URL_TOKEN` used to be the only available authentication method. To prevent existing applications -from changing their behavior in case of an API upgrade, this method is chosen as the default for this API implementation. - -Note however that GitHub describes this method as deprecated. In most case you should use the -`Github\Client::AUTH_HTTP_TOKEN` instead. +After executing the `$client->authenticate($usernameOrToken, $secret, $method);` method using correct credentials, all +further requests are done as the given user. ### Authenticating as an Integration diff --git a/lib/Github/Api/Authorizations.php b/lib/Github/Api/Authorizations.php index f0122a3fc17..6032c7fadb2 100644 --- a/lib/Github/Api/Authorizations.php +++ b/lib/Github/Api/Authorizations.php @@ -11,100 +11,6 @@ */ class Authorizations extends AbstractApi { - use AcceptHeaderTrait; - - private function configurePreviewHeader() - { - $this->acceptHeaderValue = 'application/vnd.github.doctor-strange-preview+json'; - } - - /** - * List all authorizations. - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. - */ - public function all() - { - return $this->get('/authorizations'); - } - - /** - * Show a single authorization. - * - * @param string $clientId - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. - */ - public function show($clientId) - { - return $this->get('/authorizations/'.rawurlencode($clientId)); - } - - /** - * Create an authorization. - * - * @param array $params - * @param string|null $OTPCode - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. - */ - public function create(array $params, $OTPCode = null) - { - $headers = null === $OTPCode ? [] : ['X-GitHub-OTP' => $OTPCode]; - - return $this->post('/authorizations', $params, $headers); - } - - /** - * Update an authorization. - * - * @param string $clientId - * @param array $params - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. - */ - public function update($clientId, array $params) - { - return $this->patch('/authorizations/'.rawurlencode($clientId), $params); - } - - /** - * Remove an authorization. - * - * @param string $clientId - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 13th November 2020. No replacement will be offered. The "web application flow" should be used instead. - */ - public function remove($clientId) - { - return $this->delete('/authorizations/'.rawurlencode($clientId)); - } - - /** - * Check an authorization. - * - * @param string $clientId - * @param string $token - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::checkToken() instead. - */ - public function check($clientId, $token) - { - return $this->get('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); - } - /** * Check an application token. * @@ -115,26 +21,9 @@ public function check($clientId, $token) */ public function checkToken($clientId, $token = null) { - $this->configurePreviewHeader(); - return $this->post('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []); } - /** - * Reset an authorization. - * - * @param string $clientId - * @param string $token - * - * @return array - * - * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::resetToken() instead. - */ - public function reset($clientId, $token) - { - return $this->post('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); - } - /** * Reset an application token. * @@ -145,36 +34,9 @@ public function reset($clientId, $token) */ public function resetToken($clientId, $token = null) { - $this->configurePreviewHeader(); - return $this->patch('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []); } - /** - * Remove an authorization. - * - * @param string $clientId - * @param string $token - * - * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::deleteToken() instead. - */ - public function revoke($clientId, $token) - { - $this->delete('/applications/'.rawurlencode($clientId).'/tokens/'.rawurlencode($token)); - } - - /** - * Revoke all authorizations. - * - * @param string $clientId - * - * @deprecated GitHub will remove this endpoint on 1st July 2020. Use self::deleteGrant() instead. - */ - public function revokeAll($clientId) - { - $this->delete('/applications/'.rawurlencode($clientId).'/tokens'); - } - /** * Revoke an application token. * @@ -185,8 +47,6 @@ public function revokeAll($clientId) */ public function deleteToken($clientId, $token = null) { - $this->configurePreviewHeader(); - $this->delete('/applications/'.rawurlencode($clientId).'/token', $token ? ['access_token' => $token] : []); } @@ -200,8 +60,6 @@ public function deleteToken($clientId, $token = null) */ public function deleteGrant($clientId, $token = null) { - $this->configurePreviewHeader(); - $this->delete('/applications/'.rawurlencode($clientId).'/grant', $token ? ['access_token' => $token] : []); } } diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index ea6619226b5..18e197f8c77 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -150,16 +150,6 @@ public function watchers() return new Watchers($this->client); } - /** - * @deprecated Use watchers() instead - */ - public function watched($page = 1) - { - return $this->get('/user/watched', [ - 'page' => $page, - ]); - } - /** * @return Starring */ @@ -168,16 +158,6 @@ public function starring() return new Starring($this->client); } - /** - * @deprecated Use starring() instead - */ - public function starred($page = 1) - { - return $this->get('/user/starred', [ - 'page' => $page, - ]); - } - /** * @link https://developer.github.com/v3/activity/watching/#list-repositories-being-watched */ diff --git a/lib/Github/Api/Integrations.php b/lib/Github/Api/Integrations.php deleted file mode 100644 index bd4f78a4f07..00000000000 --- a/lib/Github/Api/Integrations.php +++ /dev/null @@ -1,26 +0,0 @@ - - */ -class Integrations extends Apps -{ - /** - * @deprecated - * Configure the accept header for Early Access to the integrations api (DEPRECATED) - * @see https://developer.github.com/v3/apps/ - * - * @return self - */ - public function configure() - { - return $this; - } -} diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index 73598267a6b..875f305f127 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -58,28 +58,6 @@ public function all($username, $repository, array $params = []) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues', array_merge(['page' => 1], $params)); } - /** - * Search issues by username, repo, state and keyword. - * - * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated - * @link http://developer.github.com/v3/search/#search-issues - * - * @param string $username the username - * @param string $repository the repository - * @param string $state the issue state, can be open or closed - * @param string $keyword the keyword to filter issues by - * - * @return array list of issues found - */ - public function find($username, $repository, $state, $keyword) - { - if (!in_array($state, ['open', 'closed'])) { - $state = 'open'; - } - - return $this->get('/legacy/issues/search/'.rawurlencode($username).'/'.rawurlencode($repository).'/'.rawurlencode($state).'/'.rawurlencode($keyword)); - } - /** * List issues by organization. * diff --git a/lib/Github/Api/Issue/Assignees.php b/lib/Github/Api/Issue/Assignees.php index 1e5e0b727a1..8ae86d1cd99 100644 --- a/lib/Github/Api/Issue/Assignees.php +++ b/lib/Github/Api/Issue/Assignees.php @@ -3,6 +3,7 @@ namespace Github\Api\Issue; use Github\Api\AbstractApi; +use Github\Exception\InvalidArgumentException; use Github\Exception\MissingArgumentException; class Assignees extends AbstractApi @@ -47,6 +48,7 @@ public function check($username, $repository, $assignee) * @param string $issue * @param array $parameters * + * @throws InvalidArgumentException * @throws MissingArgumentException * * @return string @@ -58,9 +60,7 @@ public function add($username, $repository, $issue, array $parameters) } if (!is_array($parameters['assignees'])) { - @trigger_error(sprintf('Passing the "assignees" parameter as a string in "%s" is deprecated and will throw an exception in php-github-api version 3.0. Pass an array of strings instead', __METHOD__), E_USER_DEPRECATED); - - $parameters['assignees'] = [$parameters['assignees']]; + throw new InvalidArgumentException('The assignees parameter should be an array of assignees'); } return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters); diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index 997271c2f0b..396f5060893 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -41,25 +41,16 @@ public function configure($bodyType = null) * * @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue * - * @param string $username - * @param string $repository - * @param int $issue - * @param int|array $page Passing integer is deprecated and will throw an exception in php-github-api version 3.0. Pass an array instead. + * @param string $username + * @param string $repository + * @param int $issue + * @param array $params * * @return array */ - public function all($username, $repository, $issue, $page = 1) + public function all($username, $repository, $issue, array $params = []) { - if (is_array($page)) { - $parameters = $page; - } else { - @trigger_error(sprintf('Passing integer to the "page" argument in "%s" is deprecated and will throw an exception in php-github-api version 3.0. Pass an array instead.', __METHOD__), E_USER_DEPRECATED); - $parameters = [ - 'page' => $page, - ]; - } - - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/comments', $parameters); + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.$issue.'/comments', $params); } /** diff --git a/lib/Github/Api/Organization/Teams.php b/lib/Github/Api/Organization/Teams.php index 8b84028db24..00b57758b05 100644 --- a/lib/Github/Api/Organization/Teams.php +++ b/lib/Github/Api/Organization/Teams.php @@ -35,21 +35,15 @@ public function create($organization, array $params) /** * @link https://developer.github.com/v3/teams/#list-teams */ - public function show($team, $organization = null) + public function show($team, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->get('/teams/'.rawurlencode($team)); - } - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } /** * @link https://developer.github.com/v3/teams/#edit-team */ - public function update($team, array $params, $organization = null) + public function update($team, array $params, $organization) { if (!isset($params['name'])) { throw new MissingArgumentException('name'); @@ -58,82 +52,46 @@ public function update($team, array $params, $organization = null) $params['permission'] = 'pull'; } - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->patch('/teams/'.rawurlencode($team), $params); - } - return $this->patch('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team), $params); } /** * @link https://developer.github.com/v3/teams/#delete-team */ - public function remove($team, $organization = null) + public function remove($team, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->delete('/teams/'.rawurlencode($team)); - } - return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team)); } /** * @link https://developer.github.com/v3/teams/members/#list-team-members */ - public function members($team, $organization = null) + public function members($team, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->get('/teams/'.rawurlencode($team).'/members'); - } - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/members'); } /** * @link https://developer.github.com/v3/teams/members/#get-team-membership */ - public function check($team, $username, $organization = null) + public function check($team, $username, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->get('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); - } - return $this->get('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } /** * @link https://developer.github.com/v3/teams/members/#add-or-update-team-membership */ - public function addMember($team, $username, $organization = null) + public function addMember($team, $username, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->put('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); - } - return $this->put('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } /** * @link https://developer.github.com/v3/teams/members/#remove-team-membership */ - public function removeMember($team, $username, $organization = null) + public function removeMember($team, $username, $organization) { - if (null === $organization) { - @trigger_error('Not passing the $organisation parameter is deprecated in knpLabs/php-github-api v2.14 and will be mandatory in v3.0.', E_USER_DEPRECATED); - - return $this->delete('/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); - } - return $this->delete('/orgs/'.rawurlencode($organization).'/teams/'.rawurlencode($team).'/memberships/'.rawurlencode($username)); } diff --git a/lib/Github/Api/RateLimit.php b/lib/Github/Api/RateLimit.php index 13e84ba16ce..10b8b5b3288 100644 --- a/lib/Github/Api/RateLimit.php +++ b/lib/Github/Api/RateLimit.php @@ -18,18 +18,6 @@ class RateLimit extends AbstractApi */ protected $resources = []; - /** - * Get rate limits data in an array. - * - * @deprecated since 2.11.0 Use `->getResources()` instead - * - * @return array - */ - public function getRateLimits() - { - return $this->fetchLimits(); - } - /** * Gets the rate limit resource objects. * @@ -79,28 +67,4 @@ protected function fetchLimits() return $result; } - - /** - * Get core rate limit. - * - * @deprecated since 2.11.0 Use `->getResource('core')->getLimit()` instead - * - * @return int - */ - public function getCoreLimit() - { - return $this->getResource('core')->getLimit(); - } - - /** - * Get search rate limit. - * - * @deprecated since 2.11.0 Use `->getResource('search')->getLimit()` instead - * - * @return int - */ - public function getSearchLimit() - { - return $this->getResource('search')->getLimit(); - } } diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index ca5cbc90dc0..c7c3555c45e 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -33,22 +33,6 @@ class Repo extends AbstractApi { use AcceptHeaderTrait; - /** - * Search repositories by keyword. - * - * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated - * @link http://developer.github.com/v3/search/#search-repositories - * - * @param string $keyword the search query - * @param array $params - * - * @return array list of found repositories - */ - public function find($keyword, array $params = []) - { - return $this->get('/legacy/repos/search/'.rawurlencode($keyword), array_merge(['start_page' => 1], $params)); - } - /** * List all public repositories. * @@ -530,22 +514,6 @@ public function teams($username, $repository) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/teams'); } - /** - * @deprecated see subscribers method - * - * @param string $username - * @param string $repository - * @param int $page - * - * @return array - */ - public function watchers($username, $repository, $page = 1) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/watchers', [ - 'page' => $page, - ]); - } - /** * @param string $username * @param string $repository diff --git a/lib/Github/Api/Repository/Protection.php b/lib/Github/Api/Repository/Protection.php index 05dc39819b8..b559557a944 100644 --- a/lib/Github/Api/Repository/Protection.php +++ b/lib/Github/Api/Repository/Protection.php @@ -14,13 +14,6 @@ class Protection extends AbstractApi { use AcceptHeaderTrait; - public function configure() - { - $this->acceptHeaderValue = 'application/vnd.github.loki-preview+json'; - - return $this; - } - /** * Retrieves configured protection for the provided branch. * diff --git a/lib/Github/Api/Search.php b/lib/Github/Api/Search.php index 84626ae32db..5a585e77149 100644 --- a/lib/Github/Api/Search.php +++ b/lib/Github/Api/Search.php @@ -90,7 +90,7 @@ public function users($q, $sort = 'updated', $order = 'desc') */ public function commits($q, $sort = null, $order = 'desc') { - //This api is in preview mode, so set the correct accept-header + // This api is in preview mode, so set the correct accept-header $this->acceptHeaderValue = 'application/vnd.github.cloak-preview'; return $this->get('/search/commits', ['q' => $q, 'sort' => $sort, 'order' => $order]); @@ -107,7 +107,7 @@ public function commits($q, $sort = null, $order = 'desc') */ public function topics($q) { - //This api is in preview mode, so set the correct accept-header + // This api is in preview mode, so set the correct accept-header $this->acceptHeaderValue = 'application/vnd.github.mercy-preview+json'; return $this->get('/search/topics', ['q' => $q]); diff --git a/lib/Github/Api/User.php b/lib/Github/Api/User.php index e80cb4c67c5..b36ae47123b 100644 --- a/lib/Github/Api/User.php +++ b/lib/Github/Api/User.php @@ -12,21 +12,6 @@ */ class User extends AbstractApi { - /** - * Search users by username. - * - * @deprecated This method is deprecated use the Search api instead. See https://developer.github.com/v3/search/legacy/#legacy-search-api-is-deprecated - * @link http://developer.github.com/v3/search/#search-users - * - * @param string $keyword the keyword to search - * - * @return array list of users found - */ - public function find($keyword) - { - return $this->get('/legacy/user/search/'.rawurlencode($keyword)); - } - /** * Request all users. * @@ -132,20 +117,6 @@ public function followers($username, array $parameters = [], array $requestHeade return $this->get('/users/'.rawurlencode($username).'/followers', $parameters, $requestHeaders); } - /** - * Request the repository that a specific user is watching. - * - * @deprecated see subscriptions method - * - * @param string $username the username - * - * @return array list of watched repositories - */ - public function watched($username) - { - return $this->get('/users/'.rawurlencode($username).'/watched'); - } - /** * Request starred repositories that a specific user has starred. * diff --git a/lib/Github/Client.php b/lib/Github/Client.php index ad4470c216c..c9adb7c2919 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -10,9 +10,9 @@ use Github\HttpClient\Plugin\GithubExceptionThrower; use Github\HttpClient\Plugin\History; use Github\HttpClient\Plugin\PathPrepend; -use Http\Client\Common\HttpMethodsClient; +use Http\Client\Common\HttpMethodsClientInterface; use Http\Client\Common\Plugin; -use Http\Discovery\UriFactoryDiscovery; +use Http\Discovery\Psr17FactoryDiscovery; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Client\ClientInterface; @@ -31,8 +31,6 @@ * @method Api\Gists gist() * @method Api\Gists gists() * @method Api\Miscellaneous\Gitignore gitignore() - * @method Api\Integrations integration() (deprecated) - * @method Api\Integrations integrations() (deprecated) * @method Api\Apps apps() * @method Api\Issue issue() * @method Api\Issue issues() @@ -69,51 +67,27 @@ */ class Client { - /** - * Constant for authentication method. Indicates the default, but deprecated - * login with username and token in URL. - * - * @deprecated Use `Client::AUTH_ACCESS_TOKEN` instead. See https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters - */ - const AUTH_URL_TOKEN = 'url_token'; - - /** - * Constant for authentication method. Not indicates the new login, but allows - * usage of unauthenticated rate limited requests for given client_id + client_secret. - * - * @deprecated Use `Client::AUTH_CLIENT_ID` instead. See https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters - */ - const AUTH_URL_CLIENT_ID = 'url_client_id'; - - /** - * Constant for authentication method. Indicates the new favored login method - * with username and password via HTTP Authentication. - * - * @deprecated Use `Client::AUTH_ACCESS_TOKEN` instead. See https://developer.github.com/changes/2019-11-05-deprecated-passwords-and-authorizations-api/#authenticating-using-query-parameters - */ - const AUTH_HTTP_PASSWORD = 'http_password'; - - /** - * Constant for authentication method. Indicates the new login method with - * with username and token via HTTP Authentication. - * - * @deprecated Use `Client::AUTH_ACCESS_TOKEN` instead. - */ - const AUTH_HTTP_TOKEN = 'http_token'; - /** * Authenticate using a client_id/client_secret combination. + * + * @var string */ const AUTH_CLIENT_ID = 'client_id_header'; /** * Authenticate using a GitHub access token. + * + * @var string */ const AUTH_ACCESS_TOKEN = 'access_token_header'; /** - * Constant for authentication method. Indicates JSON Web Token - * authentication required for GitHub apps access to the API. + * Constant for authentication method. + * + * Indicates JSON Web Token authentication required for GitHub apps access + * to the API. + * + * @var string */ const AUTH_JWT = 'jwt'; @@ -142,12 +116,12 @@ class Client public function __construct(Builder $httpClientBuilder = null, $apiVersion = null, $enterpriseUrl = null) { $this->responseHistory = new History(); - $this->httpClientBuilder = $builder = $httpClientBuilder ?: new Builder(); + $this->httpClientBuilder = $builder = $httpClientBuilder ?? new Builder(); $builder->addPlugin(new GithubExceptionThrower()); $builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory)); $builder->addPlugin(new Plugin\RedirectPlugin()); - $builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri('https://api.github.com'))); + $builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUrlFactory()->createUri('https://api.github.com'))); $builder->addPlugin(new Plugin\HeaderDefaultsPlugin([ 'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)', ])); @@ -222,11 +196,6 @@ public function api($name) $api = new Api\Miscellaneous\Gitignore($this); break; - case 'integration': - case 'integrations': - $api = new Api\Integrations($this); - break; - case 'apps': $api = new Api\Apps($this); break; @@ -338,17 +307,13 @@ public function api($name) */ public function authenticate($tokenOrLogin, $password = null, $authMethod = null) { - if (null === $password && null === $authMethod) { - throw new InvalidArgumentException('You need to specify authentication method!'); - } - - if (null === $authMethod && in_array($password, [self::AUTH_URL_TOKEN, self::AUTH_URL_CLIENT_ID, self::AUTH_HTTP_PASSWORD, self::AUTH_HTTP_TOKEN, self::AUTH_ACCESS_TOKEN, self::AUTH_JWT], true)) { + if (null === $authMethod && (self::AUTH_JWT === $password || self::AUTH_ACCESS_TOKEN === $password)) { $authMethod = $password; $password = null; } if (null === $authMethod) { - $authMethod = self::AUTH_HTTP_PASSWORD; + throw new InvalidArgumentException('You need to specify authentication method!'); } $this->getHttpClientBuilder()->removePlugin(Authentication::class); @@ -368,7 +333,7 @@ private function setEnterpriseUrl($enterpriseUrl) $builder->removePlugin(Plugin\AddHostPlugin::class); $builder->removePlugin(PathPrepend::class); - $builder->addPlugin(new Plugin\AddHostPlugin(UriFactoryDiscovery::find()->createUri($enterpriseUrl))); + $builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUrlFactory()->createUri($enterpriseUrl))); $builder->addPlugin(new PathPrepend(sprintf('/api/%s', $this->getApiVersion()))); } @@ -427,7 +392,7 @@ public function getLastResponse() } /** - * @return HttpMethodsClient + * @return HttpMethodsClientInterface */ public function getHttpClient() { diff --git a/lib/Github/HttpClient/Builder.php b/lib/Github/HttpClient/Builder.php index d18bbcff332..47d46527928 100644 --- a/lib/Github/HttpClient/Builder.php +++ b/lib/Github/HttpClient/Builder.php @@ -3,16 +3,16 @@ namespace Github\HttpClient; use Http\Client\Common\HttpMethodsClient; +use Http\Client\Common\HttpMethodsClientInterface; use Http\Client\Common\Plugin; use Http\Client\Common\Plugin\Cache\Generator\HeaderCacheKeyGenerator; use Http\Client\Common\PluginClientFactory; -use Http\Discovery\MessageFactoryDiscovery; +use Http\Discovery\Psr17FactoryDiscovery; use Http\Discovery\Psr18ClientDiscovery; -use Http\Discovery\StreamFactoryDiscovery; -use Http\Message\RequestFactory; -use Http\Message\StreamFactory; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; /** * A builder that builds the API client. @@ -32,17 +32,17 @@ class Builder /** * A HTTP client with all our plugins. * - * @var HttpMethodsClient + * @var HttpMethodsClientInterface */ private $pluginClient; /** - * @var RequestFactory + * @var RequestFactoryInterface */ private $requestFactory; /** - * @var StreamFactory + * @var StreamFactoryInterface */ private $streamFactory; @@ -73,22 +73,22 @@ class Builder private $headers = []; /** - * @param ClientInterface $httpClient - * @param RequestFactory $requestFactory - * @param StreamFactory $streamFactory + * @param ClientInterface|null $httpClient + * @param RequestFactoryInterface|null $requestFactory + * @param StreamFactoryInterface|null $streamFactory */ public function __construct( ClientInterface $httpClient = null, - RequestFactory $requestFactory = null, - StreamFactory $streamFactory = null + RequestFactoryInterface $requestFactory = null, + StreamFactoryInterface $streamFactory = null ) { - $this->httpClient = $httpClient ?: Psr18ClientDiscovery::find(); - $this->requestFactory = $requestFactory ?: MessageFactoryDiscovery::find(); - $this->streamFactory = $streamFactory ?: StreamFactoryDiscovery::find(); + $this->httpClient = $httpClient ?? Psr18ClientDiscovery::find(); + $this->requestFactory = $requestFactory ?? Psr17FactoryDiscovery::findRequestFactory(); + $this->streamFactory = $streamFactory ?? Psr17FactoryDiscovery::findStreamFactory(); } /** - * @return HttpMethodsClient + * @return HttpMethodsClientInterface */ public function getHttpClient() { diff --git a/lib/Github/HttpClient/Plugin/Authentication.php b/lib/Github/HttpClient/Plugin/Authentication.php index 48145dba6d8..48131099672 100644 --- a/lib/Github/HttpClient/Plugin/Authentication.php +++ b/lib/Github/HttpClient/Plugin/Authentication.php @@ -46,62 +46,26 @@ public function __construct($tokenOrLogin, $password, $method) * @return Promise */ public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise + { + $request = $request->withHeader( + 'Authorization', + $this->getAuthorizationHeader() + ); + + return $next($request); + } + + private function getAuthorizationHeader(): string { switch ($this->method) { - case Client::AUTH_HTTP_PASSWORD: - @trigger_error('Using the "Client::AUTH_HTTP_PASSWORD" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_ACCESS_TOKEN" instead.', E_USER_DEPRECATED); case Client::AUTH_CLIENT_ID: - $request = $request->withHeader( - 'Authorization', - sprintf('Basic %s', base64_encode($this->tokenOrLogin.':'.$this->password)) - ); - break; - - case Client::AUTH_HTTP_TOKEN: - @trigger_error('Using the "Client::AUTH_HTTP_TOKEN" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_ACCESS_TOKEN" instead.', E_USER_DEPRECATED); + return sprintf('Basic %s', base64_encode($this->tokenOrLogin.':'.$this->password)); case Client::AUTH_ACCESS_TOKEN: - $request = $request->withHeader('Authorization', sprintf('token %s', $this->tokenOrLogin)); - break; - - case Client::AUTH_URL_CLIENT_ID: - @trigger_error('Using the "Client::AUTH_URL_CLIENT_ID" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_CLIENT_ID" instead.', E_USER_DEPRECATED); - - $uri = $request->getUri(); - $query = $uri->getQuery(); - - $parameters = [ - 'client_id' => $this->tokenOrLogin, - 'client_secret' => $this->password, - ]; - - $query .= empty($query) ? '' : '&'; - $query .= utf8_encode(http_build_query($parameters, '', '&')); - - $uri = $uri->withQuery($query); - $request = $request->withUri($uri); - break; - - case Client::AUTH_URL_TOKEN: - @trigger_error('Using the "Client::AUTH_URL_TOKEN" authentication method is deprecated in knp-labs/php-github-api v2.15 and will be removed in knp-labs/php-github-api v3.0. Use "Client::AUTH_ACCESS_TOKEN" instead.', E_USER_DEPRECATED); - - $uri = $request->getUri(); - $query = $uri->getQuery(); - - $parameters = ['access_token' => $this->tokenOrLogin]; - - $query .= empty($query) ? '' : '&'; - $query .= utf8_encode(http_build_query($parameters, '', '&')); - - $uri = $uri->withQuery($query); - $request = $request->withUri($uri); - break; + return sprintf('token %s', $this->tokenOrLogin); case Client::AUTH_JWT: - $request = $request->withHeader('Authorization', sprintf('Bearer %s', $this->tokenOrLogin)); - break; + return sprintf('Bearer %s', $this->tokenOrLogin); default: throw new RuntimeException(sprintf('%s not yet implemented', $this->method)); } - - return $next($request); } } diff --git a/test/Github/Tests/Api/AbstractApiTest.php b/test/Github/Tests/Api/AbstractApiTest.php index ae2fa7cd3b6..428ece12cf3 100644 --- a/test/Github/Tests/Api/AbstractApiTest.php +++ b/test/Github/Tests/Api/AbstractApiTest.php @@ -209,19 +209,12 @@ protected function getClientMock() * * @param array $methods * - * @return \Http\Client\Common\HttpMethodsClient + * @return \Http\Client\Common\HttpMethodsClientInterface */ protected function getHttpMethodsMock(array $methods = []) { - if (interface_exists(HttpMethodsClientInterface::class)) { - $mock = $this->createMock(HttpMethodsClientInterface::class); - } else { - $methods = array_merge(['sendRequest'], $methods); - $mock = $this->getMockBuilder(\Http\Client\Common\HttpMethodsClient::class) - ->disableOriginalConstructor() - ->setMethods($methods) - ->getMock(); - } + $mock = $this->createMock(HttpMethodsClientInterface::class); + $mock ->expects($this->any()) ->method('sendRequest'); diff --git a/test/Github/Tests/Api/AuthorizationsTest.php b/test/Github/Tests/Api/AuthorizationsTest.php deleted file mode 100644 index 87ace7c51f1..00000000000 --- a/test/Github/Tests/Api/AuthorizationsTest.php +++ /dev/null @@ -1,229 +0,0 @@ - '123']]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/authorizations') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->all()); - } - - /** - * @test - */ - public function shouldShowAuthorization() - { - $id = 123; - $expectedArray = ['id' => $id]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/authorizations/'.$id) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->show($id)); - } - - /** - * @test - */ - public function shouldAuthorization() - { - $input = [ - 'note' => '', - ]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('post') - ->with('/authorizations', $input); - - $api->create($input); - } - - /** - * @test - */ - public function shouldUpdateAuthorization() - { - $id = 123; - $input = [ - 'note' => '', - ]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('patch') - ->with('/authorizations/'.$id, $input); - - $api->update($id, $input); - } - - /** - * @test - */ - public function shouldDeleteAuthorization() - { - $id = 123; - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/authorizations/'.$id); - - $api->remove($id); - } - - /** - * @test - */ - public function shouldCheckApplicationToken() - { - $id = 123; - $token = 'abc'; - $expectedArray = ['id' => $id]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('post') - ->with('/applications/'.$id.'/token', ['access_token' => $token]) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->checkToken($id, $token)); - } - - /** - * @test - */ - public function shouldCheckAuthorization() - { - $id = 123; - $token = 'abc'; - $expectedArray = ['id' => $id]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/applications/'.$id.'/tokens/'.$token) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->check($id, $token)); - } - - /** - * @test - */ - public function shouldResetAuthorization() - { - $id = 123; - $token = 'abcde'; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('post') - ->with('/applications/'.$id.'/tokens/'.$token); - - $api->reset($id, $token); - } - - /** - * @test - */ - public function shouldResetApplicationToken() - { - $id = 123; - $token = 'abcde'; - $expectedArray = ['id' => $id]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('patch') - ->with('/applications/'.$id.'/token', ['access_token' => $token]) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->resetToken($id, $token)); - } - - /** - * @test - */ - public function shouldRevokeAuthorization() - { - $id = 123; - $token = 'abcde'; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/applications/'.$id.'/tokens/'.$token); - - $api->revoke($id, $token); - } - - /** - * @test - */ - public function shouldRevokeAllAuthorizations() - { - $id = 123; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/applications/'.$id.'/tokens'); - - $api->revokeAll($id); - } - - /** - * @test - */ - public function shouldDeleteApplicationToken() - { - $id = 123; - $token = 'abcde'; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/applications/'.$id.'/token', ['access_token' => $token]); - - $api->deleteToken($id, $token); - } - - /** - * @test - */ - public function shouldDeleteApplicationAuthorization() - { - $id = 123; - $token = 'abcde'; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/applications/'.$id.'/grant', ['access_token' => $token]); - - $api->deleteGrant($id, $token); - } - - /** - * @return string - */ - protected function getApiClass() - { - return \Github\Api\Authorizations::class; - } -} diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index ace2301b650..5de99f5c911 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -68,22 +68,6 @@ public function shouldGetIssuesAssignedToUser() $this->assertEquals($expectedArray, $api->issues(['some' => 'param'])); } - /** - * @test - */ - public function shouldGetWatchedRepositories() - { - $expectedArray = [['id' => 1, 'name' => 'l3l0repo']]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/user/watched', ['page' => 1]) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->watched(1)); - } - /** * @test */ diff --git a/test/Github/Tests/Api/Issue/CommentsTest.php b/test/Github/Tests/Api/Issue/CommentsTest.php index 08f4ff0ff16..3a8db85a922 100644 --- a/test/Github/Tests/Api/Issue/CommentsTest.php +++ b/test/Github/Tests/Api/Issue/CommentsTest.php @@ -17,7 +17,7 @@ public function shouldGetAllIssueComments() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/issues/123/comments', ['page' => 1]) + ->with('/repos/KnpLabs/php-github-api/issues/123/comments', []) ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index 6ad07439edd..bc8b80fdf5e 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -156,54 +156,6 @@ public function shouldReOpenIssue() $api->update('ornicar', 'php-github-api', 14, $data); } - /** - * @test - */ - public function shouldSearchOpenIssues() - { - $expectedArray = [['id' => '123']]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/issues/search/KnpLabs/php-github-api/open/Invalid%20Commits') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'open', 'Invalid Commits')); - } - - /** - * @test - */ - public function shouldSearchClosedIssues() - { - $expectedArray = [['id' => '123']]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/issues/search/KnpLabs/php-github-api/closed/Invalid%20Commits') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'closed', 'Invalid Commits')); - } - - /** - * @test - */ - public function shouldSearchOpenIssuesWhenStateNotRecognized() - { - $expectedArray = [['id' => '123']]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/issues/search/KnpLabs/php-github-api/open/Invalid%20Commits') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('KnpLabs', 'php-github-api', 'abc', 'Invalid Commits')); - } - /** * @test */ diff --git a/test/Github/Tests/Api/RateLimitTest.php b/test/Github/Tests/Api/RateLimitTest.php index 547b5dc2797..d13d001d890 100644 --- a/test/Github/Tests/Api/RateLimitTest.php +++ b/test/Github/Tests/Api/RateLimitTest.php @@ -37,11 +37,9 @@ class RateLimitTest extends TestCase protected $api; /** - * Used to construct common expectations for the API input data in each unit test. - * - * {@inheritdoc} + * @before */ - protected function setUp(): void + public function initMocks() { $this->api = $this->getApiMock(); $this->api->expects($this->once()) @@ -50,14 +48,6 @@ protected function setUp(): void ->will($this->returnValue($this->expectedArray)); } - /** - * @test - */ - public function shouldReturnRateLimitArray() - { - $this->assertSame($this->expectedArray, $this->api->getRateLimits()); - } - /** * @test */ diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index 88434750883..9bc5363333b 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -36,44 +36,6 @@ public function shouldShowRepositoryById() $this->assertEquals($expectedArray, $api->showById(123456)); } - /** - * @test - */ - public function shouldSearchRepositories() - { - $expectedArray = [ - ['id' => 1, 'name' => 'php'], - ['id' => 2, 'name' => 'php-cs'], - ]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/repos/search/php', ['myparam' => 2, 'start_page' => 1]) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('php', ['myparam' => 2])); - } - - /** - * @test - */ - public function shouldPaginateFoundRepositories() - { - $expectedArray = [ - ['id' => 3, 'name' => 'fork of php'], - ['id' => 4, 'name' => 'fork of php-cs'], - ]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/repos/search/php', ['start_page' => 2]) - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('php', ['start_page' => 2])); - } - /** * @test */ diff --git a/test/Github/Tests/Api/UserTest.php b/test/Github/Tests/Api/UserTest.php index 795c48fa992..491a58f8602 100644 --- a/test/Github/Tests/Api/UserTest.php +++ b/test/Github/Tests/Api/UserTest.php @@ -117,25 +117,6 @@ public function shouldGetAllUsersSince() $this->assertEquals($expectedArray, $api->all(2)); } - /** - * @test - */ - public function shouldSearchUsers() - { - $expectedArray = [ - ['id' => 1, 'username' => 'l3l0'], - ['id' => 2, 'username' => 'l3l0test'], - ]; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/legacy/user/search/l3l0') - ->will($this->returnValue($expectedArray)); - - $this->assertEquals($expectedArray, $api->find('l3l0')); - } - /** * @test */ diff --git a/test/Github/Tests/ClientTest.php b/test/Github/Tests/ClientTest.php index 15a6bf401ac..e92493cffad 100644 --- a/test/Github/Tests/ClientTest.php +++ b/test/Github/Tests/ClientTest.php @@ -68,11 +68,7 @@ public function shouldAuthenticateUsingAllGivenParameters($login, $password, $me public function getAuthenticationFullData() { return [ - ['login', 'password', Client::AUTH_HTTP_PASSWORD], - ['token', null, Client::AUTH_HTTP_TOKEN], - ['token', null, Client::AUTH_URL_TOKEN], ['token', null, Client::AUTH_ACCESS_TOKEN], - ['client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID], ['client_id', 'client_secret', Client::AUTH_CLIENT_ID], ['token', null, Client::AUTH_JWT], ]; @@ -80,16 +76,15 @@ public function getAuthenticationFullData() /** * @test - * @dataProvider getAuthenticationPartialData */ - public function shouldAuthenticateUsingGivenParameters($token, $method) + public function shouldAuthenticateUsingGivenParameters() { $builder = $this->getMockBuilder(Builder::class) ->setMethods(['addPlugin', 'removePlugin']) ->getMock(); $builder->expects($this->once()) ->method('addPlugin') - ->with($this->equalTo(new Authentication($token, null, $method))); + ->with($this->equalTo(new Authentication('token', null, Client::AUTH_ACCESS_TOKEN))); $builder->expects($this->once()) ->method('removePlugin') @@ -103,15 +98,7 @@ public function shouldAuthenticateUsingGivenParameters($token, $method) ->method('getHttpClientBuilder') ->willReturn($builder); - $client->authenticate($token, $method); - } - - public function getAuthenticationPartialData() - { - return [ - ['token', Client::AUTH_HTTP_TOKEN], - ['token', Client::AUTH_URL_TOKEN], - ]; + $client->authenticate('token', Client::AUTH_ACCESS_TOKEN); } /** diff --git a/test/Github/Tests/Functional/CacheTest.php b/test/Github/Tests/Functional/CacheTest.php index a220d355684..625807700ba 100644 --- a/test/Github/Tests/Functional/CacheTest.php +++ b/test/Github/Tests/Functional/CacheTest.php @@ -25,7 +25,7 @@ public function shouldServeCachedResponse() $github = Client::createWithHttpClient($mockClient); $github->addCache(new ArrayCachePool(), ['default_ttl'=>600]); - $github->authenticate('fake_token_aaa', Client::AUTH_HTTP_TOKEN); + $github->authenticate('fake_token_aaa', Client::AUTH_ACCESS_TOKEN); $userA = $github->currentUser()->show(); $this->assertEquals('nyholm', $userA['login']); @@ -45,11 +45,11 @@ public function shouldVaryOnAuthorization() $github = Client::createWithHttpClient($mockClient); $github->addCache(new ArrayCachePool(), ['default_ttl'=>600]); - $github->authenticate('fake_token_aaa', Client::AUTH_HTTP_TOKEN); + $github->authenticate('fake_token_aaa', Client::AUTH_ACCESS_TOKEN); $userA = $github->currentUser()->show(); $this->assertEquals('nyholm', $userA['login']); - $github->authenticate('fake_token_bbb', Client::AUTH_HTTP_TOKEN); + $github->authenticate('fake_token_bbb', Client::AUTH_ACCESS_TOKEN); $userB = $github->currentUser()->show(); $this->assertEquals('octocat', $userB['login'], 'We must vary on the Authorization header.'); } diff --git a/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php b/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php index bcff0d8df88..e8c3d24a6a6 100644 --- a/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php +++ b/test/Github/Tests/HttpClient/Plugin/AuthenticationTest.php @@ -41,11 +41,7 @@ public function testAuthenticationMethods($tokenOrLogin, $password, $method, $ex public function getAuthenticationData() { return [ - ['login', 'password', Client::AUTH_HTTP_PASSWORD, sprintf('Basic %s', base64_encode('login'.':'.'password'))], - ['access_token', null, Client::AUTH_HTTP_TOKEN, 'token access_token'], - ['token', null, Client::AUTH_URL_TOKEN, null, '/?access_token=token'], ['access_token', null, Client::AUTH_ACCESS_TOKEN, 'token access_token'], - ['client_id', 'client_secret', Client::AUTH_URL_CLIENT_ID, null, '/?client_id=client_id&client_secret=client_secret'], ['client_id', 'client_secret', Client::AUTH_CLIENT_ID, sprintf('Basic %s', base64_encode('client_id'.':'.'client_secret'))], ['jwt_token', null, Client::AUTH_JWT, 'Bearer jwt_token'], ]; diff --git a/test/Github/Tests/Integration/TestCase.php b/test/Github/Tests/Integration/TestCase.php index 319070d5014..d101b1b1efe 100644 --- a/test/Github/Tests/Integration/TestCase.php +++ b/test/Github/Tests/Integration/TestCase.php @@ -16,7 +16,10 @@ class TestCase extends \PHPUnit\Framework\TestCase */ protected $client; - public function setUp(): void + /** + * @before + */ + public function initClient() { // You have to specify authentication here to run full suite $client = new Client();