From a7905201443b712b28ffff1486d5b30943f082d6 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 31 Aug 2014 21:54:50 -0400 Subject: [PATCH 01/79] Update branch for 2.0 development --- README.md | 6 +++--- composer.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c3378798..81cba733 100644 --- a/README.md +++ b/README.md @@ -764,12 +764,12 @@ The following resources contain more information: [Joomla! API Reference](http: ## Installation via Composer -Add `"joomla/github": "~1.0"` to the require block in your composer.json and then run `composer install`. +Add `"joomla/github": "2.0.*@dev"` to the require block in your composer.json and then run `composer install`. ```json { "require": { - "joomla/github": "~1.0" + "joomla/github": "2.0.*@dev" } } ``` @@ -777,5 +777,5 @@ Add `"joomla/github": "~1.0"` to the require block in your composer.json and the Alternatively, you can simply run the following from the command line: ```sh -composer require joomla/github "~1.0" +composer require joomla/github "2.0.*@dev" ``` diff --git a/composer.json b/composer.json index ba8d5118..dcd4c018 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.x-dev" + "dev-2.0-dev": "2.0-dev" } } } From 52f2198d78ecd14216134ed4b1274ec29b145d91 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 31 Aug 2014 21:55:56 -0400 Subject: [PATCH 02/79] Remove deprecated classes --- src/GithubObject.php | 19 ------------------- src/Package.php | 19 ------------------- 2 files changed, 38 deletions(-) delete mode 100644 src/GithubObject.php delete mode 100644 src/Package.php diff --git a/src/GithubObject.php b/src/GithubObject.php deleted file mode 100644 index 602c736b..00000000 --- a/src/GithubObject.php +++ /dev/null @@ -1,19 +0,0 @@ - Date: Wed, 25 Feb 2015 23:02:53 -0500 Subject: [PATCH 03/79] Run tests on PHP 7 --- .travis.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0557f2c3..92fd8a41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,14 @@ php: - 5.4 - 5.5 - 5.6 + - 7.0 + +matrix: + allow_failures: + - php: 7.0 before_script: - - composer update --dev + - composer update script: - ./vendor/bin/phpunit From e125a213589d90df566dae94bdaf57223daf410f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Alleaume Date: Tue, 3 Mar 2015 17:33:45 +0100 Subject: [PATCH 04/79] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index dcd4c018..e0aa390d 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "php": ">=5.3.10", "joomla/date": "~1.0", "joomla/http": "~1.0", - "joomla/registry": "~1.0", + "joomla/registry": "~2.0@dev", "joomla/uri": "~1.0" }, "require-dev": { From 1f946e340f311eab262ad4d5c7ee5ed0e7facdad Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Tue, 3 Mar 2015 21:20:36 -0500 Subject: [PATCH 05/79] Fix 2.0 reference --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e0aa390d..520d7d9d 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "php": ">=5.3.10", "joomla/date": "~1.0", "joomla/http": "~1.0", - "joomla/registry": "~2.0@dev", + "joomla/registry": "2.0.*@dev", "joomla/uri": "~1.0" }, "require-dev": { From cad18df1fe49ab91665c83c10592da9907c3720c Mon Sep 17 00:00:00 2001 From: George Wilson Date: Thu, 19 Mar 2015 03:09:45 +0000 Subject: [PATCH 06/79] Run tests on HHVM --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 92fd8a41..2633a7f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,11 @@ php: - 5.5 - 5.6 - 7.0 + - hhvm matrix: allow_failures: + - php: hhvm - php: 7.0 before_script: From 5bd448b53bde942d9c9b66459b01eac1073e5435 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 22 Aug 2015 15:16:43 -0400 Subject: [PATCH 07/79] Stop allowing failures on PHP 7 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2633a7f5..75969c0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,6 @@ php: matrix: allow_failures: - php: hhvm - - php: 7.0 before_script: - composer update From 6a03471edc827a5382e60f4865df2f658014e3fc Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 23 Jul 2016 16:23:04 -0500 Subject: [PATCH 08/79] Remove deprecations --- src/Package/Repositories.php | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/Package/Repositories.php b/src/Package/Repositories.php index d8747570..5d9715e5 100644 --- a/src/Package/Repositories.php +++ b/src/Package/Repositories.php @@ -388,39 +388,6 @@ public function getListTags($owner, $repo) ); } - /** - * List Branches. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - * @deprecated 2.0 Use Joomla\Github\Package\Repositories\Branches::getList() instead - */ - public function getListBranches($owner, $repo) - { - return $this->branches->getList($owner, $repo); - } - - /** - * Get a Branch. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param string $branch Branch name. - * - * @return object - * - * @since 1.0 - * @deprecated 2.0 Use Joomla\Github\Package\Repositories\Branches::get() instead - */ - public function getBranch($owner, $repo, $branch) - { - return $this->branches->get($owner, $repo, $branch); - } - /** * Delete a Repository. * From ebd785f4cec8250a009f2ae80b3d62e891219221 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 31 Jul 2016 15:02:42 -0500 Subject: [PATCH 09/79] Drop PHP 5.3 --- .travis.yml | 5 ++--- composer.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 974d0aaa..583ed427 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,9 @@ env: matrix: include: - - php: 5.3 - - php: 5.3 - env: COMPOSER_FLAGS="--prefer-lowest" - php: 5.4 + - php: 5.4 + env: COMPOSER_FLAGS="--prefer-lowest" - php: 5.5 - php: 5.6 env: RUN_PHPCS="yes" diff --git a/composer.json b/composer.json index ddbde19f..348fa0ac 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "https://github.com/joomla-framework/github-api", "license": "GPL-2.0+", "require": { - "php": "^5.3.10|~7.0", + "php": "^5.4|~7.0", "joomla/http": "^1.2.2", "joomla/registry": "2.0.*@dev", "joomla/uri": "~1.0" From 8e630b1fad6de32e8fe62088712c0472e101689b Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 17 Sep 2016 11:08:07 -0500 Subject: [PATCH 10/79] Bump PHP minimum to 5.5.9 --- .travis.yml | 5 ++--- composer.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 583ed427..fbfa7bb7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,10 +9,9 @@ env: matrix: include: - - php: 5.4 - - php: 5.4 - env: COMPOSER_FLAGS="--prefer-lowest" - php: 5.5 + - php: 5.5 + env: COMPOSER_FLAGS="--prefer-lowest" - php: 5.6 env: RUN_PHPCS="yes" - php: 7.0 diff --git a/composer.json b/composer.json index 166b9be9..db95ecdd 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "https://github.com/joomla-framework/github-api", "license": "GPL-2.0+", "require": { - "php": "^5.4|~7.0", + "php": "^5.5.9|~7.0", "joomla/http": "^1.2.2", "joomla/registry": "2.0.*@dev", "joomla/uri": "~1.0" From a2f1ad2f064469ea2dcf156d5c9ca34cc3fc3e03 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 17 Sep 2016 11:22:22 -0500 Subject: [PATCH 11/79] Check for interface --- src/Package/Activity/Notifications.php | 48 +++++++++++++------------- src/Package/Issues.php | 18 +++++----- src/Package/Issues/Comments.php | 12 +++---- src/Package/Repositories/Commits.php | 16 ++++----- 4 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/Package/Activity/Notifications.php b/src/Package/Activity/Notifications.php index c05a51a7..4f6e32e2 100644 --- a/src/Package/Activity/Notifications.php +++ b/src/Package/Activity/Notifications.php @@ -24,16 +24,16 @@ class Notifications extends AbstractPackage * * List all notifications for the current user, grouped by repository. * - * @param boolean $all True to show notifications marked as read. - * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. - * @param \DateTime $since Filters out any notifications updated before the given time. The time should be passed in - * as UTC in the ISO 8601 format. + * @param boolean $all True to show notifications marked as read. + * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. + * @param \DateTimeInterface $since Filters out any notifications updated before the given time. The time should be passed in + * as UTC in the ISO 8601 format. * * @return object * * @since 1.0 */ - public function getList($all = true, $participating = true, \DateTime $since = null) + public function getList($all = true, $participating = true, \DateTimeInterface $since = null) { // Build the request path. $path = '/notifications?'; @@ -52,18 +52,18 @@ public function getList($all = true, $participating = true, \DateTime $since = n * * List all notifications for the current user. * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param boolean $all True to show notifications marked as read. - * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. - * @param \DateTime $since Filters out any notifications updated before the given time. The time should be passed in - * as UTC in the ISO 8601 format. + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param boolean $all True to show notifications marked as read. + * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. + * @param \DateTimeInterface $since Filters out any notifications updated before the given time. The time should be passed in + * as UTC in the ISO 8601 format. * * @return object * * @since 1.0 */ - public function getListRepository($owner, $repo, $all = true, $participating = true, \DateTime $since = null) + public function getListRepository($owner, $repo, $all = true, $participating = true, \DateTimeInterface $since = null) { // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/notifications?'; @@ -82,16 +82,16 @@ public function getListRepository($owner, $repo, $all = true, $participating = t * * Marking a notification as “read” removes it from the default view on GitHub.com. * - * @param boolean $unread Changes the unread status of the threads. - * @param boolean $read Inverse of “unread”. - * @param \DateTime $lastReadAt Describes the last point that notifications were checked. - * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. + * @param boolean $unread Changes the unread status of the threads. + * @param boolean $read Inverse of “unread”. + * @param \DateTimeInterface $lastReadAt Describes the last point that notifications were checked. + * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. * * @return object * * @since 1.0 */ - public function markRead($unread = true, $read = true, \DateTime $lastReadAt = null) + public function markRead($unread = true, $read = true, \DateTimeInterface $lastReadAt = null) { // Build the request path. $path = '/notifications'; @@ -117,18 +117,18 @@ public function markRead($unread = true, $read = true, \DateTime $lastReadAt = n * * Marking all notifications in a repository as “read” removes them from the default view on GitHub.com. * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param boolean $unread Changes the unread status of the threads. - * @param boolean $read Inverse of “unread”. - * @param \DateTime $lastReadAt Describes the last point that notifications were checked. - * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param boolean $unread Changes the unread status of the threads. + * @param boolean $read Inverse of “unread”. + * @param \DateTimeInterface $lastReadAt Describes the last point that notifications were checked. + * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. * * @return object * * @since 1.0 */ - public function markReadRepository($owner, $repo, $unread, $read, \DateTime $lastReadAt = null) + public function markReadRepository($owner, $repo, $unread, $read, \DateTimeInterface $lastReadAt = null) { // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/notifications'; diff --git a/src/Package/Issues.php b/src/Package/Issues.php index fada673f..e954558e 100644 --- a/src/Package/Issues.php +++ b/src/Package/Issues.php @@ -169,14 +169,14 @@ public function get($user, $repo, $issueId) /** * List issues. * - * @param string $filter The filter type: assigned, created, mentioned, subscribed. - * @param string $state The optional state to filter requests by. [open, closed] - * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. - * @param string $sort The sort order: created, updated, comments, default: created. - * @param string $direction The list direction: asc or desc, default: desc. - * @param \DateTime $since The date/time since when issues should be returned. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. + * @param string $filter The filter type: assigned, created, mentioned, subscribed. + * @param string $state The optional state to filter requests by. [open, closed] + * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. + * @param string $sort The sort order: created, updated, comments, default: created. + * @param string $direction The list direction: asc or desc, default: desc. + * @param \DateTimeInterface $since The date/time since when issues should be returned. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. * * @return object * @@ -184,7 +184,7 @@ public function get($user, $repo, $issueId) * @throws \DomainException */ public function getList($filter = null, $state = null, $labels = null, $sort = null, - $direction = null, \DateTime $since = null, $page = 0, $limit = 0) + $direction = null, \DateTimeInterface $since = null, $page = 0, $limit = 0) { // Build the request path. $path = '/issues'; diff --git a/src/Package/Issues/Comments.php b/src/Package/Issues/Comments.php index a430e663..0eb5a0de 100644 --- a/src/Package/Issues/Comments.php +++ b/src/Package/Issues/Comments.php @@ -50,11 +50,11 @@ public function getList($owner, $repo, $issueId, $page = 0, $limit = 0) /** * List comments in a repository. * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sort The sort field - created or updated. - * @param string $direction The sort order- asc or desc. Ignored without sort parameter. - * @param \DateTime $since A timestamp in ISO 8601 format. + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sort The sort field - created or updated. + * @param string $direction The sort order- asc or desc. Ignored without sort parameter. + * @param \DateTimeInterface $since A timestamp in ISO 8601 format. * * @return object * @@ -62,7 +62,7 @@ public function getList($owner, $repo, $issueId, $page = 0, $limit = 0) * @throws \UnexpectedValueException * @throws \DomainException */ - public function getRepositoryList($owner, $repo, $sort = 'created', $direction = 'asc', \DateTime $since = null) + public function getRepositoryList($owner, $repo, $sort = 'created', $direction = 'asc', \DateTimeInterface $since = null) { // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/issues/comments'; diff --git a/src/Package/Repositories/Commits.php b/src/Package/Repositories/Commits.php index a23de535..847936de 100644 --- a/src/Package/Repositories/Commits.php +++ b/src/Package/Repositories/Commits.php @@ -28,20 +28,20 @@ class Commits extends AbstractPackage * Please follow the link headers as outlined in the pagination overview instead of constructing * page links yourself. * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha Sha or branch to start listing commits from. - * @param string $path Only commits containing this file path will be returned. - * @param string $author GitHub login, name, or email by which to filter by commit author. - * @param \DateTime $since ISO 8601 Date - Only commits after this date will be returned. - * @param \DateTime $until ISO 8601 Date - Only commits before this date will be returned. + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha Sha or branch to start listing commits from. + * @param string $path Only commits containing this file path will be returned. + * @param string $author GitHub login, name, or email by which to filter by commit author. + * @param \DateTimeInterface $since ISO 8601 Date - Only commits after this date will be returned. + * @param \DateTimeInterface $until ISO 8601 Date - Only commits before this date will be returned. * * @return object * * @since 1.0 * @throws \DomainException */ - public function getList($user, $repo, $sha = '', $path = '', $author = '', \DateTime $since = null, \DateTime $until = null) + public function getList($user, $repo, $sha = '', $path = '', $author = '', \DateTimeInterface $since = null, \DateTimeInterface $until = null) { // Build the request path. $rPath = '/repos/' . $user . '/' . $repo . '/commits?'; From 9ad832db140b59f86f8ce82083e93833ed9fd673 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 17 Sep 2016 11:47:59 -0500 Subject: [PATCH 12/79] Remove test for removed method --- Tests/Package/RepositoriesTest.php | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Tests/Package/RepositoriesTest.php b/Tests/Package/RepositoriesTest.php index d171fc4e..39c044e4 100644 --- a/Tests/Package/RepositoriesTest.php +++ b/Tests/Package/RepositoriesTest.php @@ -422,27 +422,6 @@ public function testGetListTags() ); } - /** - * Tests the GetListBranches method. - * - * @return void - */ - public function testGetListBranches() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/branches', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListBranches('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - /** * Tests the GetBranch method. * From 2adf4d065fc6b9faebc34f9a97007a68a97e7987 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 17 Sep 2016 12:38:37 -0500 Subject: [PATCH 13/79] Method no longer exists --- Tests/Package/RepositoriesTest.php | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Tests/Package/RepositoriesTest.php b/Tests/Package/RepositoriesTest.php index ee27fb7a..8fe63c3f 100644 --- a/Tests/Package/RepositoriesTest.php +++ b/Tests/Package/RepositoriesTest.php @@ -384,27 +384,6 @@ public function testGetListTags() ); } - /** - * Tests the GetBranch method. - * - * @return void - */ - public function testGetBranch() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/branches/master', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getBranch('joomla', 'joomla-cms', 'master'), - $this->equalTo(json_decode($this->response->body)) - ); - } - /** * Tests the Delete method. * From a4ab1a880cc22e43a510cd8b4b3483a1eb20e665 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 16 Oct 2016 12:58:14 -0500 Subject: [PATCH 14/79] Change typehint --- src/Package/Issues/Comments.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Package/Issues/Comments.php b/src/Package/Issues/Comments.php index 334b174a..7c7a51c0 100644 --- a/src/Package/Issues/Comments.php +++ b/src/Package/Issues/Comments.php @@ -25,19 +25,19 @@ class Comments extends AbstractPackage /** * List comments on an issue. * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueId The issue number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * @param \DateTime $since Only comments updated at or after this time are returned. + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueId The issue number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * @param \DateTimeInterface $since Only comments updated at or after this time are returned. * * @return object * * @since 1.0 * @throws \DomainException */ - public function getList($owner, $repo, $issueId, $page = 0, $limit = 0, \DateTime $since = null) + public function getList($owner, $repo, $issueId, $page = 0, $limit = 0, \DateTimeInterface $since = null) { // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; From 0c0c00c6ea1c832b7c35bf0a7c964589161d9712 Mon Sep 17 00:00:00 2001 From: elkuku Date: Mon, 8 May 2017 22:07:58 -0500 Subject: [PATCH 15/79] Update .gitignore Add build files (cherry picked from commit 5ba86e1) --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 871b715c..04cf9643 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ vendor/ composer.phar composer.lock phpunit.xml + +# Build files +/build/coverage +/build/logs \ No newline at end of file From ac3178fb2c29d380016dcfa8ab46d476263df206 Mon Sep 17 00:00:00 2001 From: elkuku Date: Mon, 8 May 2017 22:09:22 -0500 Subject: [PATCH 16/79] Fix Actibity/Starring::getRepositories() Add missing slash. (cherry picked from commit db43548) --- src/Package/Activity/Starring.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package/Activity/Starring.php b/src/Package/Activity/Starring.php index b2a34b16..6eabc13f 100644 --- a/src/Package/Activity/Starring.php +++ b/src/Package/Activity/Starring.php @@ -81,7 +81,7 @@ public function getRepositories($user = '', $sort = 'created', $direction = 'des // Build the request path. $path = ($user) - ? '/users' . $user . '/starred' + ? '/users/' . $user . '/starred' : '/user/starred'; $path .= "?sort=$sort&direction=$direction"; From cbce7ae5713d36e7425f9a603eb86f8189f72670 Mon Sep 17 00:00:00 2001 From: elkuku Date: Mon, 8 May 2017 22:10:02 -0500 Subject: [PATCH 17/79] Update unit tests Start adding @covers tags (cherry picked from commit 2c66ef4) --- Tests/Package/Activity/NotificationsTest.php | 56 ++- Tests/Package/Activity/StarringTest.php | 67 ++- Tests/Package/ActivityTest.php | 10 +- Tests/Package/Data/TagsTest.php | 3 +- Tests/Package/DataTest.php | 10 +- Tests/Package/GitignoreTest.php | 3 +- Tests/Package/Issues/AssigneesTest.php | 4 +- Tests/Package/IssuesTest.php | 491 ++++--------------- Tests/Package/Orgs/HooksTest.php | 62 ++- Tests/Package/Orgs/MembersTest.php | 228 ++++++++- Tests/Package/Orgs/TeamsTest.php | 252 +++++++++- Tests/Package/Pulls/CommentsTest.php | 51 +- Tests/Package/PullsTest.php | 281 ----------- Tests/Package/Repositories/CommitsTest.php | 83 +++- Tests/Package/Repositories/HooksTest.php | 113 ++++- Tests/Package/Repositories/StatusesTest.php | 55 ++- Tests/Package/RepositoriesTest.php | 3 +- Tests/Package/Users/FollowersTest.php | 125 ++++- 18 files changed, 1077 insertions(+), 820 deletions(-) diff --git a/Tests/Package/Activity/NotificationsTest.php b/Tests/Package/Activity/NotificationsTest.php index 792fdc16..2351bc13 100644 --- a/Tests/Package/Activity/NotificationsTest.php +++ b/Tests/Package/Activity/NotificationsTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for the GitHub API package. + * Test class. + * + * @covers \Joomla\Github\Package\Activity\Notifications * * @since 1.0 */ @@ -38,7 +40,9 @@ protected function setUp() } /** - * Tests the getList method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::getList() * * @return void */ @@ -49,17 +53,19 @@ public function testGetList() $this->client->expects($this->once()) ->method('get') - ->with('/notifications?all=1&participating=1', array(), 0) + ->with('/notifications?all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00', array(), 0) ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->getList(), + $this->object->getList(true, true, new \DateTime('2005-8-17'), new \DateTime('2005-8-17')), $this->equalTo(json_decode($this->response->body)) ); } /** - * Tests the getListRepository method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::getListRepository() * * @return void */ @@ -70,17 +76,19 @@ public function testGetListRepository() $this->client->expects($this->once()) ->method('get') - ->with('/repos/joomla/joomla-platform/notifications?all=1&participating=1', array(), 0) + ->with('/repos/{owner}/{repo}/notifications?all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00', array(), 0) ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->getListRepository('joomla', 'joomla-platform'), + $this->object->getListRepository('{owner}', '{repo}', true, true, new \DateTime('2005-8-17'), new \DateTime('2005-8-17')), $this->equalTo(json_decode($this->response->body)) ); } /** - * Tests the markRead method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markRead() * * @return void */ @@ -101,7 +109,9 @@ public function testMarkRead() } /** - * Tests the markReadLastRead method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markRead() * * @return void */ @@ -125,7 +135,9 @@ public function testMarkReadLastRead() } /** - * Tests the markReadRepository method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markReadRepository() * * @return void */ @@ -148,7 +160,9 @@ public function testMarkReadRepository() } /** - * Tests the markReadRepositoryLastRead method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markReadRepository() * * @return void */ @@ -172,7 +186,9 @@ public function testMarkReadRepositoryLastRead() } /** - * Tests the viewThread method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::viewThread() * * @return void */ @@ -193,7 +209,9 @@ public function testViewThread() } /** - * Tests the markReadThread method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markReadThread() * * @return void */ @@ -214,7 +232,9 @@ public function testMarkReadThread() } /** - * Tests the getThreadSubscription method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::getThreadSubscription() * * @return void */ @@ -235,7 +255,9 @@ public function testGetThreadSubscription() } /** - * Tests the setThreadSubscription method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::setThreadSubscription() * * @return void */ @@ -256,7 +278,9 @@ public function testSetThreadSubscription() } /** - * Tests the deleteThreadSubscription method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::deleteThreadSubscription() * * @return void */ diff --git a/Tests/Package/Activity/StarringTest.php b/Tests/Package/Activity/StarringTest.php index 0712792e..795f478e 100644 --- a/Tests/Package/Activity/StarringTest.php +++ b/Tests/Package/Activity/StarringTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for the GitHub API package. + * Test class. + * + * @covers \Joomla\Github\Package\Activity\Starring * * @since 1.0 */ @@ -38,7 +40,9 @@ protected function setUp() } /** - * Tests the getList method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getList() * * @return void */ @@ -59,7 +63,9 @@ public function testGetList() } /** - * Tests the getRepositories method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() * * @return void */ @@ -80,7 +86,34 @@ public function testGetRepositories() } /** - * Tests the getRepositories method - invalid sort option + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * @return void + */ + public function testGetRepositoriesWithName() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/users/{user}/starred?sort=created&direction=desc', array(), 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositories('{user}'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * Invalid sort option * * @return void * @@ -92,7 +125,11 @@ public function testGetRepositoriesInvalidSort() } /** - * Tests the getRepositories method - invalid direction option + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * Invalid direction option * * @return void * @@ -104,7 +141,9 @@ public function testGetRepositoriesInvalidDirection() } /** - * Tests the check method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::check() * * @return void */ @@ -125,7 +164,9 @@ public function testCheck() } /** - * Tests the checkFalse method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::check() * * @return void */ @@ -146,7 +187,9 @@ public function testCheckFalse() } /** - * Tests the checkUnexpected method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::check() * * @expectedException \UnexpectedValueException * @return void @@ -168,7 +211,9 @@ public function testCheckUnexpected() } /** - * Tests the star method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::star() * * @return void */ @@ -189,7 +234,9 @@ public function testStar() } /** - * Tests the unstar method + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::unstar() * * @return void */ diff --git a/Tests/Package/ActivityTest.php b/Tests/Package/ActivityTest.php index 93127c22..22cd6a99 100644 --- a/Tests/Package/ActivityTest.php +++ b/Tests/Package/ActivityTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Activity. + * Test method. + * + * @covers \Joomla\Github\Package\Activity * * @since 1.0 */ @@ -37,7 +39,9 @@ protected function setUp() } /** - * Tests the construct method. + * Test method. + * + * @covers \Joomla\Github\Package\Activity::__construct() * * @return void * @@ -45,5 +49,7 @@ protected function setUp() */ public function testConstruct() { + // Dummy to make PHPUnit "happy" + self::assertEquals(true, true); } } diff --git a/Tests/Package/Data/TagsTest.php b/Tests/Package/Data/TagsTest.php index e2562ba0..a2f15db1 100644 --- a/Tests/Package/Data/TagsTest.php +++ b/Tests/Package/Data/TagsTest.php @@ -68,7 +68,8 @@ public function testCreate() $this->response->code = 201; $this->response->body = $this->sampleString; - $data = '{"tag":"0.1","message":"Message","object":"12345","type":"commit","tagger":{"name":"elkuku","email":"email@example.com","date":"123456789"}}'; + $data = '{"tag":"0.1","message":"Message","object":"12345","type":"commit","tagger":' + . '{"name":"elkuku","email":"email@example.com","date":"123456789"}}'; $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/git/tags', $data, array(), 0) diff --git a/Tests/Package/DataTest.php b/Tests/Package/DataTest.php index 9db48543..439ac93b 100644 --- a/Tests/Package/DataTest.php +++ b/Tests/Package/DataTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Data. + * Test class. + * + * @covers \Joomla\Github\Package\Data * * @since 1.0 */ @@ -37,7 +39,9 @@ protected function setUp() } /** - * Tests the construct method. + * Test method. + * + * @covers \Joomla\Github\Package\Data::__construct() * * @return void * @@ -45,5 +49,7 @@ protected function setUp() */ public function testConstruct() { + // Dummy to make PHPUnit "happy" + self::assertEquals(true, true); } } diff --git a/Tests/Package/GitignoreTest.php b/Tests/Package/GitignoreTest.php index 40969b06..22f2cd3a 100644 --- a/Tests/Package/GitignoreTest.php +++ b/Tests/Package/GitignoreTest.php @@ -79,7 +79,8 @@ public function testGet() $this->response->code = 200; $this->response->body = '{ "name": "C", - "source": "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Windows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n" + "source": "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Windows DLLs)\n' + . '*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n" }'; $this->client->expects($this->once()) diff --git a/Tests/Package/Issues/AssigneesTest.php b/Tests/Package/Issues/AssigneesTest.php index 8ece121b..18e390ad 100644 --- a/Tests/Package/Issues/AssigneesTest.php +++ b/Tests/Package/Issues/AssigneesTest.php @@ -210,7 +210,9 @@ public function testRemove() $this->client->expects($this->once()) ->method('delete') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/issues/123/assignees', array(), null, json_encode(array('assignees' => array('joomla')))) + ->with('/repos/' . $this->owner . '/' . $this->repo + . '/issues/123/assignees', array(), null, json_encode(array('assignees' => array('joomla'))) + ) ->will($this->returnValue($this->response)); $this->assertThat( diff --git a/Tests/Package/IssuesTest.php b/Tests/Package/IssuesTest.php index 9bcda0ed..2bc5a964 100755 --- a/Tests/Package/IssuesTest.php +++ b/Tests/Package/IssuesTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Issues. + * Test class. + * + * @covers \Joomla\Github\Package\Issues * * @since 1.0 */ @@ -38,7 +40,9 @@ protected function setUp() } /** - * Tests the create method + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() * * @return void */ @@ -48,12 +52,12 @@ public function testCreate() $this->response->body = $this->sampleString; $issue = new \stdClass; - $issue->title = 'My issue'; + $issue->title = '{title}'; $issue->assignee = 'JoeUser'; $issue->milestone = '11.5'; - $issue->labels = array('TestLabel'); - $issue->body = 'These are my changes - please review them'; - $issue->assignees = array('joomla'); + $issue->labels = ['TestLabel']; + $issue->body = '{body}'; + $issue->assignees = ['joomla']; $this->client->expects($this->once()) ->method('post') @@ -61,13 +65,17 @@ public function testCreate() ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'My issue', 'These are my changes - please review them', 'JoeUser', '11.5', array('TestLabel'), array('joomla')), + $this->object->create('joomla', 'joomla-platform', '{title}', '{body}', 'JoeUser', '11.5', ['TestLabel'], ['joomla']), $this->equalTo(json_decode($this->sampleString)) ); } /** - * Tests the create method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * Failure * * @expectedException \DomainException * @@ -83,7 +91,7 @@ public function testCreateFailure() $issue->assignee = 'JoeUser'; $issue->milestone = '11.5'; $issue->labels = array(); - $issue->body = 'These are my changes - please review them'; + $issue->body = '{body}'; $issue->assignees = array('joomla'); $this->client->expects($this->once()) @@ -91,11 +99,13 @@ public function testCreateFailure() ->with('/repos/joomla/joomla-platform/issues', json_encode($issue)) ->will($this->returnValue($this->response)); - $this->object->create('joomla', 'joomla-platform', 'My issue', 'These are my changes - please review them', 'JoeUser', '11.5', array(), array('joomla')); + $this->object->create('joomla', 'joomla-platform', 'My issue', '{body}', 'JoeUser', '11.5', array(), array('joomla')); } /** - * Tests the createComment method + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() * * @return void */ @@ -119,7 +129,11 @@ public function testCreateComment() } /** - * Tests the createComment method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * Failure * * @expectedException \DomainException * @@ -142,138 +156,9 @@ public function testCreateCommentFailure() } /** - * Tests the createLabel method - * @todo move - * @return void - * - public function testCreateLabel() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $issue = new \stdClass; - $issue->name = 'My Insightful Label'; - $issue->color = 'My Insightful Color'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/labels', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createLabel('joomla', 'joomla-platform', 'My Insightful Label', 'My Insightful Color'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the createLabel method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testCreateLabelFailure() - { - $this->response->code = 501; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->name = 'My Insightful Label'; - $issue->color = 'My Insightful Color'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/labels', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->createLabel('joomla', 'joomla-platform', 'My Insightful Label', 'My Insightful Color'); - } - */ - - /** - * Tests the deleteComment method - * @todo move - * @return void + * Test method. * - public function testDeleteComment() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/comments/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteComment('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the deleteComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testDeleteCommentFailure() - { - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/comments/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteComment('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the deleteLabel method - * @todo move - * @return void - * - public function testDeleteLabel() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/labels/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteLabel('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the deleteLabel method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testDeleteLabelFailure() - { - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/labels/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteLabel('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the edit method + * @covers \Joomla\Github\Package\Issues::edit() * * @return void */ @@ -304,7 +189,11 @@ public function testEdit() } /** - * Tests the edit method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Issues::edit() + * + * Failure * * @expectedException \DomainException * @@ -329,107 +218,9 @@ public function testEditFailure() } /** - * Tests the editComment method - * @todo move - * @return void - * - public function testEditComment() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $issue = new \stdClass; - $issue->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/issues/comments/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->editComment('joomla', 'joomla-platform', 523, 'This comment is now even more insightful'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the editComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testEditCommentFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/issues/comments/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->editComment('joomla', 'joomla-platform', 523, 'This comment is now even more insightful'); - } - */ - - /** - * Tests the editLabel method - * @todo move - * @return void - * - public function testEditLabel() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $issue = new \stdClass; - $issue->name = 'This label is now even more insightful'; - $issue->color = 'This color is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/labels/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->editLabel('joomla', 'joomla-platform', 523, 'This label is now even more insightful', 'This color is now even more insightful'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the editLabel method - failure - * @todo move - * @expectedException \DomainException + * Test method. * - * @return void - * - public function testEditLabelFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->name = 'This label is now even more insightful'; - $issue->color = 'This color is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/labels/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->editLabel('joomla', 'joomla-platform', 523, 'This label is now even more insightful', 'This color is now even more insightful'); - } - */ - - /** - * Tests the get method + * @covers \Joomla\Github\Package\Issues::get() * * @return void */ @@ -450,7 +241,11 @@ public function testGet() } /** - * Tests the get method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Issues::get() + * + * Failure * * @expectedException \DomainException * @@ -470,200 +265,58 @@ public function testGetFailure() } /** - * Tests the getComment method - * @todo move - * @return void + * Test method. * - public function testGetComment() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/comments/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getComment('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the getComment method - failure - * @todo move - * @expectedException \DomainException + * @covers \Joomla\Github\Package\Issues::getList() * * @return void - * - public function testGetCommentFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/comments/523') - ->will($this->returnValue($this->response)); - - $this->object->getComment('joomla', 'joomla-platform', 523); - } */ - - /** - * Tests the getComments method - * @todo move - * @return void - * - public function testGetComments() + public function testGetList() { $this->response->code = 200; $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') - ->with('/repos/joomla/joomla-platform/issues/523/comments') + ->with('/issues') ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->getComments('joomla', 'joomla-platform', 523), + $this->object->getList(), $this->equalTo(json_decode($this->sampleString)) ); } - */ /** - * Tests the getComments method - failure - * @todo move - * @expectedException \DomainException + * Test method. * - * @return void + * @covers \Joomla\Github\Package\Issues::getList() * - public function testGetCommentsFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/523/comments') - ->will($this->returnValue($this->response)); - - $this->object->getComments('joomla', 'joomla-platform', 523); - } - */ - - /** - * Tests the getLabel method - * @todo move * @return void - * - public function testGetLabel() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels/My Insightful Label') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getLabel('joomla', 'joomla-platform', 'My Insightful Label'), - $this->equalTo(json_decode($this->sampleString)) - ); - } */ - - /** - * Tests the getLabel method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testGetLabelFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels/My Insightful Label') - ->will($this->returnValue($this->response)); - - $this->object->getLabel('joomla', 'joomla-platform', 'My Insightful Label'); - } - */ - - /** - * Tests the getLabels method - * @todo move - * @return void - * - public function testGetLabels() + public function testGetListAll() { $this->response->code = 200; $this->response->body = $this->sampleString; + $since = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); $this->client->expects($this->once()) ->method('get') - ->with('/repos/joomla/joomla-platform/labels') + ->with('/issues?filter={filter}&state={state}&labels={labels}&sort={sort}&direction={direction}&since=2012-01-01T12:12:12+0000') ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->getLabels('joomla', 'joomla-platform'), + $this->object->getList('{filter}', '{state}', '{labels}', '{sort}', '{direction}', $since), $this->equalTo(json_decode($this->sampleString)) ); } - */ /** - * Tests the getLabels method - failure - * @todo move - * @expectedException \DomainException + * Test method. * - * @return void + * @covers \Joomla\Github\Package\Issues::getList() * - public function testGetLabelsFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels') - ->will($this->returnValue($this->response)); - - $this->object->getLabels('joomla', 'joomla-platform'); - } - */ - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/issues') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - failure + * Failure * * @expectedException \DomainException * @@ -683,7 +336,9 @@ public function testGetListFailure() } /** - * Tests the getListByRepository method + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getListByRepository() * * @return void */ @@ -704,7 +359,11 @@ public function testGetListByRepository() } /** - * Tests the getListByRepository method with all parameters + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getListByRepository() + * + * With all parameters * * @return void */ @@ -740,7 +399,11 @@ public function testGetListByRepositoryAll() } /** - * Tests the getListByRepository method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getListByRepository() + * + * Failure * * @expectedException \DomainException * @@ -760,7 +423,9 @@ public function testGetListByRepositoryFailure() } /** - * Tests the lock method + * Test method. + * + * @covers \Joomla\Github\Package\Issues::lock() * * @return void */ @@ -781,7 +446,11 @@ public function testLock() } /** - * Tests the lock method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Issues::lock() + * + * Failure * * @expectedException \DomainException * @@ -801,7 +470,9 @@ public function testLockFailure() } /** - * Tests the unlock method + * Test method. + * + * @covers \Joomla\Github\Package\Issues::unlock() * * @return void */ @@ -822,7 +493,11 @@ public function testUnlock() } /** - * Tests the unlock method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Issues::unlock() + * + * Failure * * @expectedException \DomainException * diff --git a/Tests/Package/Orgs/HooksTest.php b/Tests/Package/Orgs/HooksTest.php index 451a2329..90a15e07 100644 --- a/Tests/Package/Orgs/HooksTest.php +++ b/Tests/Package/Orgs/HooksTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Members. + * Test class. + * + * @covers \Joomla\Github\Package\Orgs\Hooks * * @since 1.0 */ @@ -37,7 +39,9 @@ protected function setUp() } /** - * Tests the getList method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::getList() * * @return void */ @@ -58,7 +62,9 @@ public function testGetList() } /** - * Tests the get method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::get() * * @return void */ @@ -79,7 +85,9 @@ public function testGet() } /** - * Tests the create method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::create() * * @return void */ @@ -100,11 +108,14 @@ public function testCreate() } /** - * Tests the create method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::create() * * @return void * * @expectedException \UnexpectedValueException + * @expectedExceptionMessage Content type must be either "form" or "json". */ public function testCreateFailure() { @@ -112,7 +123,24 @@ public function testCreateFailure() } /** - * Tests the edit method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::create() + * + * @return void + * + * @expectedException \RuntimeException + * @expectedExceptionMessage Your events array contains an unauthorized event. + */ + public function testCreateInvalidEvent() + { + $this->object->create('{org}', '{url}', 'form', null, false, ['{invalid}']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::edit() * * @return void */ @@ -133,7 +161,9 @@ public function testEdit() } /** - * Tests the edit method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::edit() * * @return void * @@ -141,11 +171,13 @@ public function testEdit() */ public function testEditFailure() { - $this->object->edit('joomla', '{url}', '{invalid}'); + $this->object->edit('{org}', '{url}', '{invalid}'); } /** - * Tests the edit method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::edit() * * @return void * @@ -157,7 +189,9 @@ public function testEditFailure2() } /** - * Tests the ping method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::ping() * * @return void */ @@ -168,17 +202,19 @@ public function testPing() $this->client->expects($this->once()) ->method('post') - ->with('/orgs/joomla/hooks/123/pings') + ->with('/orgs/{org}/hooks/123/pings') ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->ping('joomla', 123), + $this->object->ping('{org}', 123), $this->equalTo(json_decode($this->sampleString)) ); } /** - * Tests the delete method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::delete() * * @return void */ diff --git a/Tests/Package/Orgs/MembersTest.php b/Tests/Package/Orgs/MembersTest.php index 304b5ba1..59de492b 100644 --- a/Tests/Package/Orgs/MembersTest.php +++ b/Tests/Package/Orgs/MembersTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Members. + * Test class. + * + * @covers \Joomla\Github\Package\Orgs\Members * * @since 1.0 */ @@ -37,7 +39,9 @@ protected function setUp() } /** - * Tests the getList method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getList() * * @return void */ @@ -58,7 +62,9 @@ public function testGetList() } /** - * Tests the getListNotAMember method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getList() * * @return void */ @@ -79,7 +85,9 @@ public function testGetListNotAMember() } /** - * Tests the getListUnexpected method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getList() * * @return void * @@ -102,7 +110,9 @@ public function testGetListUnexpected() } /** - * Tests the check method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() * * @return void */ @@ -123,7 +133,9 @@ public function testCheck() } /** - * Tests the checkNoMember method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() * * @return void */ @@ -144,7 +156,9 @@ public function testCheckNoMember() } /** - * Tests the checkRequesterNoMember method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() * * @return void */ @@ -165,7 +179,9 @@ public function testCheckRequesterNoMember() } /** - * Tests the checkUnexpectedr method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() * * @return void * @@ -188,7 +204,9 @@ public function testCheckUnexpectedr() } /** - * Tests the remove method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::remove() * * @return void */ @@ -209,7 +227,9 @@ public function testRemove() } /** - * Tests the getListPublic method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getListPublic() * * @return void */ @@ -230,7 +250,9 @@ public function testGetListPublic() } /** - * Tests the checkPublic method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() * * @return void */ @@ -251,7 +273,9 @@ public function testCheckPublic() } /** - * Tests the checkPublicNo method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() * * @return void */ @@ -272,7 +296,9 @@ public function testCheckPublicNo() } /** - * Tests the checkPublicUnexpected method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() * * @return void * @@ -295,7 +321,9 @@ public function testCheckPublicUnexpected() } /** - * Tests the publicize method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::publicize() * * @return void */ @@ -316,7 +344,9 @@ public function testPublicize() } /** - * Tests the conceal method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::conceal() * * @return void */ @@ -335,4 +365,172 @@ public function testConceal() $this->equalTo(json_decode($this->sampleString)) ); } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getMembership() + * + * @return void + */ + public function testGetMembership() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/{org}/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getMembership('{org}', '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() + * + * @return void + */ + public function testUpdateMembership() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('put') + ->with('/orgs/{org}/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->updateMembership('{org}', '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() + * + * @return void + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The user's role must be: member, admin + */ + public function testUpdateMembershipInvalidRole() + { + $this->object->updateMembership('{org}', '{user}', 'INVALID'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::removeMembership() + * + * @return void + */ + public function testRemoveMembership() + { + $this->response->code = 204; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/orgs/{org}/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeMembership('{org}', '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::listMemberships() + * + * @return void + */ + public function testListMemberships() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/memberships/orgs') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->listMemberships(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::listOrganizationMembership() + * + * @return void + */ + public function testListOrganizationMemberships() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/memberships/orgs/{org}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->listOrganizationMembership('{org}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() + * + * @return void + */ + public function testEditOrganizationMemberships() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/user/memberships/orgs/{org}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->editOrganizationMembership('{org}', 'active'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() + * + * @return void + * + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage The state must be "active". + */ + public function testEditOrganizationMembershipsInvalidState() + { + $this->object->editOrganizationMembership('{org}', 'INVALID'); + } } diff --git a/Tests/Package/Orgs/TeamsTest.php b/Tests/Package/Orgs/TeamsTest.php index 32dada03..5da81173 100644 --- a/Tests/Package/Orgs/TeamsTest.php +++ b/Tests/Package/Orgs/TeamsTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Teams. + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams * * @since 1.0 */ @@ -37,7 +39,9 @@ protected function setUp() } /** - * Tests the getList method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getList() * * @return void */ @@ -58,7 +62,9 @@ public function testGetList() } /** - * Tests the get method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::get() * * @return void */ @@ -79,7 +85,9 @@ public function testGet() } /** - * Tests the create method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::create() * * @return void */ @@ -100,7 +108,9 @@ public function testCreate() } /** - * Tests the createWrongPermission method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::create() * * @return void * @@ -115,7 +125,9 @@ public function testCreateWrongPermission() } /** - * Tests the edit method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::edit() * * @return void */ @@ -136,7 +148,9 @@ public function testEdit() } /** - * Tests the editWrongPermission method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::edit() * * @return void * @@ -151,7 +165,9 @@ public function testEditWrongPermission() } /** - * Tests the delete method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::delete() * * @return void */ @@ -172,7 +188,9 @@ public function testDelete() } /** - * Tests the getListMembers method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getListMembers() * * @return void */ @@ -193,7 +211,11 @@ public function testGetListMembers() } /** - * Tests the isMember method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::isMember() + * + * @deprecated * * @return void */ @@ -214,7 +236,11 @@ public function testIsMember() } /** - * Tests the isMemberNo method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::isMember() + * + * @deprecated * * @return void */ @@ -235,7 +261,11 @@ public function testIsMemberNo() } /** - * Tests the isMemberUnexpected method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::isMember() + * + * @deprecated * * @return void * @@ -258,7 +288,11 @@ public function testIsMemberUnexpected() } /** - * Tests the addMember method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addMember() + * + * @deprecated * * @return void */ @@ -279,7 +313,11 @@ public function testAddMember() } /** - * Tests the removeMember method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::removeMember() + * + * @deprecated * * @return void */ @@ -300,7 +338,9 @@ public function testRemoveMember() } /** - * Tests the getListRepos method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getListRepos() * * @return void */ @@ -321,7 +361,9 @@ public function testGetListRepos() } /** - * Tests the checkRepo method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() * * @return void */ @@ -342,7 +384,9 @@ public function testCheckRepo() } /** - * Tests the checkRepoNo method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() * * @return void */ @@ -363,7 +407,9 @@ public function testCheckRepoNo() } /** - * Tests the checkRepoUnexpected method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() * * @return void * @@ -386,7 +432,9 @@ public function testCheckRepoUnexpected() } /** - * Tests the addRepo method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addRepo() * * @return void */ @@ -407,7 +455,9 @@ public function testAddRepo() } /** - * Tests the removeRepo method + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::removeRepo() * * @return void */ @@ -426,4 +476,166 @@ public function testRemoveRepo() $this->equalTo(json_decode($this->sampleString)) ); } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() + * + * @return void + */ + public function testGetTeamMemberships() + { + $this->response->code = 200; + $this->response->body = '{"state":"TEST"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getTeamMembership(123, '{user}'), + $this->equalTo('TEST') + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() + * + * Response if user is not a member + * + * @return void + */ + public function testGetTeamMembershipsFailure1() + { + $this->response->code = 404; + $this->response->body = '{"state":"TEST"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getTeamMembership(123, '{user}'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() + * + * Unexpected Response + * + * @return void + * + * @expectedException \UnexpectedValueException + * @expectedExceptionMessage Unexpected response code: 666 + */ + public function testGetTeamMembershipsFailure2() + { + $this->response->code = 666; + $this->response->body = '{"state":"TEST"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getTeamMembership(123, '{user}'), + $this->equalTo('TEST') + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() + * + * @return void + */ + public function testAddTeamMemberships() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('put') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->addTeamMembership(123, '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() + * + * Invalid role + * + * @return void + * + * @expectedException \UnexpectedValueException + * @expectedExceptionMessage Roles must be either "member" or "maintainer". + */ + public function testAddTeamMembershipsFailure() + { + $this->object->addTeamMembership(123, '{user}', 'INVALID'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::removeTeamMembership() + * + * @return void + */ + public function testRemoveTeamMemberships() + { + $this->response->code = 204; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeTeamMembership(123, '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getUserTeams() + * + * @return void + */ + public function testGetUserTeams() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/teams') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getUserTeams(), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Pulls/CommentsTest.php b/Tests/Package/Pulls/CommentsTest.php index 40375dae..71ffacbb 100644 --- a/Tests/Package/Pulls/CommentsTest.php +++ b/Tests/Package/Pulls/CommentsTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Comments. + * Test class. + * + * @covers \Joomla\Github\Package\Pulls\Comments * * @since 1.0 */ @@ -37,7 +39,9 @@ protected function setUp() } /** - * Tests the create method + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::create() * * @return void */ @@ -58,7 +62,9 @@ public function testCreate() } /** - * Tests the createReply method + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::createReply() * * @return void */ @@ -79,7 +85,9 @@ public function testCreateReply() } /** - * Tests the delete method + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::delete() * * @return void */ @@ -100,7 +108,9 @@ public function testDelete() } /** - * Tests the edit method + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::edit() * * @return void */ @@ -121,7 +131,9 @@ public function testEdit() } /** - * Tests the get method + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::get() * * @return void */ @@ -142,7 +154,9 @@ public function testGet() } /** - * Tests the getList method + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::getList() * * @return void */ @@ -161,4 +175,27 @@ public function testGetList() $this->equalTo(json_decode($this->response->body)) ); } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::getListForRepo() + * + * @return void + */ + public function testGetListForRepo() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/pulls/comments', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListForRepo('{user}', '{repo}'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/PullsTest.php b/Tests/Package/PullsTest.php index 1615c59d..dc0254c8 100755 --- a/Tests/Package/PullsTest.php +++ b/Tests/Package/PullsTest.php @@ -91,112 +91,6 @@ public function testCreateFailure() 'These are my changes - please review them'); } - /** - * Tests the createComment method - * @todo move - * @return void - * - public function testCreateComment() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $pull = new \stdClass; - $pull->body = 'My Insightful Comment'; - $pull->commit_id = 'abcde12345'; - $pull->path = '/path/to/file'; - $pull->position = 254; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/523/comments', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createComment('joomla', 'joomla-platform', 523, 'My Insightful Comment', 'abcde12345', '/path/to/file', 254), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the createComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testCreateCommentFailure() - { - $this->response->code = 501; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->body = 'My Insightful Comment'; - $pull->commit_id = 'abcde12345'; - $pull->path = '/path/to/file'; - $pull->position = 254; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/523/comments', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->createComment('joomla', 'joomla-platform', 523, 'My Insightful Comment', 'abcde12345', '/path/to/file', 254); - } - */ - - /** - * Tests the createCommentReply method - * @todo move - * @return void - * - public function testCreateCommentReply() - { - $this->response->code = 201; - $this->response->body = $this->sampleString; - - $pull = new \stdClass; - $pull->body = 'My Insightful Comment'; - $pull->in_reply_to = 434; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/523/comments', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createCommentReply('joomla', 'joomla-platform', 523, 'My Insightful Comment', 434), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the createCommentReply method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testCreateCommentReplyFailure() - { - $this->response->code = 501; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->body = 'My Insightful Comment'; - $pull->in_reply_to = 434; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/523/comments', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->createCommentReply('joomla', 'joomla-platform', 523, 'My Insightful Comment', 434); - } - */ - /** * Tests the createFromIssue method * @@ -248,46 +142,6 @@ public function testCreateFromIssueFailure() $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'); } - /** - * Tests the deleteComment method - * @todo move - * @return void - * - public function testDeleteComment() - { - $this->response->code = 204; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/pulls/comments/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteComment('joomla', 'joomla-platform', 254); - } - */ - - /** - * Tests the deleteComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testDeleteCommentFailure() - { - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/pulls/comments/254') - ->will($this->returnValue($this->response)); - - $this->object->deleteComment('joomla', 'joomla-platform', 254); - } - */ - /** * Tests the edit method * @@ -339,55 +193,6 @@ public function testEditFailure() $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them'); } - /** - * Tests the editComment method - * @todo move - * @return void - * - public function testEditComment() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $pull = new \stdClass; - $pull->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/pulls/comments/523', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->editComment('joomla', 'joomla-platform', 523, 'This comment is now even more insightful'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the editComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testEditCommentFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/pulls/comments/523', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->editComment('joomla', 'joomla-platform', 523, 'This comment is now even more insightful'); - } - */ - /** * Tests the get method * @@ -429,92 +234,6 @@ public function testGetFailure() $this->object->get('joomla', 'joomla-platform', 523); } - /** - * Tests the getComment method - * @todo move - * @return void - * - public function testGetComment() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/comments/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getComment('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the getComment method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testGetCommentFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/comments/523') - ->will($this->returnValue($this->response)); - - $this->object->getComment('joomla', 'joomla-platform', 523); - } - */ - - /** - * Tests the getComments method - * @todo move - * @return void - * - public function testGetComments() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getComments('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - */ - - /** - * Tests the getComments method - failure - * @todo move - * @expectedException \DomainException - * - * @return void - * - public function testGetCommentsFailure() - { - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/comments') - ->will($this->returnValue($this->response)); - - $this->object->getComments('joomla', 'joomla-platform', 523); - } - */ - /** * Tests the getCommits method * diff --git a/Tests/Package/Repositories/CommitsTest.php b/Tests/Package/Repositories/CommitsTest.php index d3c3e98f..fdb452ff 100644 --- a/Tests/Package/Repositories/CommitsTest.php +++ b/Tests/Package/Repositories/CommitsTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Commits. + * Test class. + * + * @covers \Joomla\Github\Package\Repositories\Commits * * @since 1.0 */ @@ -38,13 +40,15 @@ protected function setUp() } /** - * Tests the getCommit method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::get() * * @return void * * @since 1.0 */ - public function testGetCommit() + public function testGet() { $this->response->code = 200; $this->response->body = $this->sampleString; @@ -61,15 +65,18 @@ public function testGetCommit() } /** - * Tests the getCommit method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::get() * * @return void * * @since 1.0 * * @expectedException \DomainException + * @expectedExceptionMessage Generic Error */ - public function testGetCommitFailure() + public function testGetFailure() { $this->response->code = 500; $this->response->body = $this->errorString; @@ -83,7 +90,9 @@ public function testGetCommitFailure() } /** - * Tests the getList method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getList() * * @return void * @@ -106,13 +115,16 @@ public function testGetList() } /** - * Tests the getList method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getList() * * @return void * * @since 1.0 * * @expectedException \DomainException + * @expectedExceptionMessage Generic Error */ public function testGetListFailure() { @@ -128,7 +140,9 @@ public function testGetListFailure() } /** - * Tests the Compare method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::compare() * * @return void * @@ -149,4 +163,57 @@ public function testCompare() $this->equalTo(json_decode($this->sampleString)) ); } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getSha() + * + * @return void + * + * @since 1.0 + */ + public function testgetSha() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/commits/{ref}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getSha('{user}', '{repo}', '{ref}'), + $this->equalTo($this->sampleString) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getSha() + * + * @return void + * + * @since 1.0 + * + * @expectedException \Joomla\Http\Exception\UnexpectedResponseException + * @expectedExceptionMessage Invalid response received from GitHub. + */ + public function testgetShaFailure() + { + $this->response->code = 666; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/commits/{ref}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getSha('{user}', '{repo}', '{ref}'), + $this->equalTo($this->sampleString) + ); + } } diff --git a/Tests/Package/Repositories/HooksTest.php b/Tests/Package/Repositories/HooksTest.php index a474fb48..48e2d3c1 100644 --- a/Tests/Package/Repositories/HooksTest.php +++ b/Tests/Package/Repositories/HooksTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Hooks. + * Test class. + * + * @covers \Joomla\Github\Package\Repositories\Hooks * * @since 1.0 */ @@ -38,7 +40,9 @@ protected function setUp() } /** - * Tests the create method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::create() * * @return void * @@ -67,7 +71,9 @@ public function testCreate() } /** - * Tests the create method - simulated failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::create() * * @return void * @@ -108,7 +114,11 @@ public function testCreateFailure() } /** - * Tests the create method - unauthorised event + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::create() + * + * Unauthorised event * * @return void * @@ -122,7 +132,9 @@ public function testCreateUnauthorisedEvent() } /** - * Tests the delete method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::delete() * * @return void * @@ -145,7 +157,11 @@ public function testDelete() } /** - * Tests the delete method - simulated failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::delete() + * + * Simulated failure * * @return void * @@ -180,7 +196,9 @@ public function testDeleteFailure() } /** - * Tests the edit method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() * * @return void * @@ -213,7 +231,11 @@ public function testEdit() } /** - * Tests the edit method - simulated failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Simulated failure * * @return void * @@ -258,13 +280,17 @@ public function testEditFailure() } /** - * Tests the edit method - unauthorised event + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Unauthorised event * * @return void * * @since 1.0 * - * @expectedException RuntimeException + * @expectedException \RuntimeException */ public function testEditUnauthorisedEvent() { @@ -272,7 +298,11 @@ public function testEditUnauthorisedEvent() } /** - * Tests the edit method - unauthorised event + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Unauthorised event * * @return void * @@ -286,7 +316,11 @@ public function testEditUnauthorisedAddEvent() } /** - * Tests the edit method - unauthorised event + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Unauthorised event * * @return void * @@ -300,7 +334,9 @@ public function testEditUnauthorisedRemoveEvent() } /** - * Tests the get method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::get() * * @return void * @@ -323,7 +359,11 @@ public function testGet() } /** - * Tests the get method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::get() + * + * Failure * * @return void * @@ -345,7 +385,9 @@ public function testGetFailure() } /** - * Tests the getList method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::getList() * * @return void * @@ -368,7 +410,11 @@ public function testGetList() } /** - * Tests the getList method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::getList() + * + * Failure * * @return void * @@ -390,7 +436,9 @@ public function testGetListFailure() } /** - * Tests the test method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::test() * * @return void * @@ -413,7 +461,11 @@ public function testTest() } /** - * Tests the test method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::test() + * + * Failure * * @return void * @@ -433,4 +485,29 @@ public function testTestFailure() $this->object->test('joomla', 'joomla-platform', 42); } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::ping() + * + * @return void + * + * @since 1.0 + */ + public function testPing() + { + $this->response->code = 204; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{user}/{repo}/hooks/42/pings') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->ping('{user}', '{repo}', 42), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/StatusesTest.php b/Tests/Package/Repositories/StatusesTest.php index 2c1f9f78..c2993942 100755 --- a/Tests/Package/Repositories/StatusesTest.php +++ b/Tests/Package/Repositories/StatusesTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Statuses. + * Test class. + * + * @covers \Joomla\Github\Package\Repositories\Statuses * * @since 1.0 */ @@ -38,7 +40,9 @@ protected function setUp() } /** - * Tests the create method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::create() * * @return void */ @@ -77,7 +81,11 @@ public function testCreate() } /** - * Tests the create method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::create() + * + * Failure * * @expectedException \DomainException * @@ -104,7 +112,11 @@ public function testCreateFailure() } /** - * Tests the create method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::create() + * + * Failure * * @expectedException \InvalidArgumentException * @@ -119,7 +131,9 @@ public function testCreateInvalidState() } /** - * Tests the getList method + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::getList() * * @return void */ @@ -140,7 +154,11 @@ public function testGetList() } /** - * Tests the getList method - failure + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::getList() + * + * Failure * * @expectedException \DomainException * @@ -158,4 +176,29 @@ public function testGetListFailure() $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'); } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::getCombinedStatus() + * + * @return void + * + * @since 1.0 + */ + public function testGetCombinedStatus() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/commits/{sha}/status') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getCombinedStatus('{user}', '{repo}', '{sha}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/RepositoriesTest.php b/Tests/Package/RepositoriesTest.php index 8fe63c3f..3b91054f 100644 --- a/Tests/Package/RepositoriesTest.php +++ b/Tests/Package/RepositoriesTest.php @@ -289,7 +289,8 @@ public function testEdit() ->method('patch') ->with( '/repos/joomla/joomla-test', - '{"name":"joomla-test-1","description":"","homepage":"","private":false,"has_issues":false,"has_wiki":false,"has_downloads":false,"default_branch":""}', + '{"name":"joomla-test-1","description":"","homepage":"","private":' + . 'false,"has_issues":false,"has_wiki":false,"has_downloads":false,"default_branch":""}', array() ) ->will($this->returnValue($this->response)); diff --git a/Tests/Package/Users/FollowersTest.php b/Tests/Package/Users/FollowersTest.php index 3dffc70c..b71586dd 100644 --- a/Tests/Package/Users/FollowersTest.php +++ b/Tests/Package/Users/FollowersTest.php @@ -10,7 +10,9 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; /** - * Test class for Emails. + * Test class. + * + * @covers \Joomla\Github\Package\Users\Followers * * @since 1.0 */ @@ -37,7 +39,9 @@ protected function setUp() } /** - * Tests the getList method + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getList() * * @return void */ @@ -58,7 +62,9 @@ public function testGetList() } /** - * Tests the getListWithUser method + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getList() * * @return void */ @@ -79,7 +85,9 @@ public function testGetListWithUser() } /** - * Tests the getListFollowedBy method + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getListFollowedBy() * * @return void */ @@ -100,7 +108,9 @@ public function testGetListFollowedBy() } /** - * Tests the getListFollowedByWithUser method + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getListFollowedBy() * * @return void */ @@ -121,7 +131,11 @@ public function testGetListFollowedByWithUser() } /** - * Tests the check method + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::check() + * + * You are following this user * * @return void */ @@ -142,7 +156,11 @@ public function testCheck() } /** - * Tests the checkNo method + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::check() + * + * You are not following this user * * @return void */ @@ -163,7 +181,9 @@ public function testCheckNo() } /** - * Tests the checkUnexpected method + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::check() * * @return void * @@ -186,7 +206,9 @@ public function testCheckUnexpected() } /** - * Tests the follow method + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::follow() * * @return void */ @@ -207,7 +229,9 @@ public function testFollow() } /** - * Tests the unfollow method + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::unfollow() * * @return void */ @@ -226,4 +250,85 @@ public function testUnfollow() $this->equalTo($this->response->body) ); } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() + * + * User is following the target + * + * @return void + * + * @since 1.0 + */ + public function testCheckUserFollowing() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/{user}/following/{target}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkUserFollowing('{user}', '{target}'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() + * + * User is not following the target + * + * @return void + * + * @since 1.0 + */ + public function testCheckUserFollowingNot() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/{user}/following/{target}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkUserFollowing('{user}', '{target}'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() + * + * // Unexpected response + * + * @return void + * + * @since 1.0 + * + * @expectedException \UnexpectedValueException + * @expectedExceptionMessage Unexpected response code: 666 + */ + public function testCheckUserFollowingUnexpected() + { + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/{user}/following/{target}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkUserFollowing('{user}', '{target}'), + $this->equalTo(true) + ); + } } From fdf29f3920ce004fab8882f1b140e0a6aeb8c9c5 Mon Sep 17 00:00:00 2001 From: elkuku Date: Tue, 9 May 2017 02:20:45 -0500 Subject: [PATCH 18/79] Fix code style - Based on JCodingStandards 2.0-alpha --- Tests/GithubObjectTest.php | 4 +- Tests/GithubTest.php | 10 +-- Tests/HttpTest.php | 2 +- Tests/Package/Activity/NotificationsTest.php | 3 +- Tests/Package/AuthorizationsTest.php | 72 +++++++++++--------- Tests/Package/GistsTest.php | 20 ++++++ Tests/Package/Issues/MilestonesTest.php | 69 +++++++++---------- Tests/Package/MarkdownTest.php | 6 +- Tests/Package/Pulls/CommentsTest.php | 3 +- Tests/Package/PullsTest.php | 6 +- Tests/Package/Repositories/ContentsTest.php | 27 +++++--- Tests/Package/Repositories/HooksTest.php | 33 +++++---- Tests/Package/Repositories/ReleasesTest.php | 4 +- Tests/PackageTest.php | 4 +- 14 files changed, 152 insertions(+), 111 deletions(-) diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index ba19fd85..e0372c89 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -50,7 +50,9 @@ public function fetchUrlData() 'Standard github - no pagination data' => array('https://api.github.com', '/gists', 0, 0, 'https://api.github.com/gists'), 'Enterprise github - no pagination data' => array('https://mygithub.com', '/gists', 0, 0, 'https://mygithub.com/gists'), 'Standard github - page 3' => array('https://api.github.com', '/gists', 3, 0, 'https://api.github.com/gists?page=3'), - 'Enterprise github - page 3, 50 per page' => array('https://mygithub.com', '/gists', 3, 50, 'https://mygithub.com/gists?page=3&per_page=50'), + 'Enterprise github - page 3, 50 per page' => array( + 'https://mygithub.com', '/gists', 3, 50, 'https://mygithub.com/gists?page=3&per_page=50' + ), ); } diff --git a/Tests/GithubTest.php b/Tests/GithubTest.php index 4f386dde..6fb56fc8 100755 --- a/Tests/GithubTest.php +++ b/Tests/GithubTest.php @@ -44,7 +44,7 @@ protected function setUp() * * @since 1.0 */ - public function test__GetForks() + public function testGetForks() { $this->assertThat( $this->object->repositories->forks, @@ -59,7 +59,7 @@ public function test__GetForks() * * @since 1.0 */ - public function test__GetCommits() + public function testGetCommits() { $this->assertThat( $this->object->repositories->commits, @@ -74,7 +74,7 @@ public function test__GetCommits() * * @since 1.0 */ - public function test__GetStatuses() + public function testGetStatuses() { $this->assertThat( $this->object->repositories->statuses, @@ -89,7 +89,7 @@ public function test__GetStatuses() * * @since 1.0 */ - public function test__GetHooks() + public function testGetHooks() { $this->assertThat( $this->object->repositories->hooks, @@ -105,7 +105,7 @@ public function test__GetHooks() * @since 1.0 * @expectedException \InvalidArgumentException */ - public function test__GetFailure() + public function testGetFailure() { $this->object->other; } diff --git a/Tests/HttpTest.php b/Tests/HttpTest.php index 16bc76c2..0da3ebc4 100755 --- a/Tests/HttpTest.php +++ b/Tests/HttpTest.php @@ -52,7 +52,7 @@ protected function setUp() * * @since 1.0 */ - public function test__Construct() + public function testConstruct() { // Verify the options are set in the object $this->assertThat( diff --git a/Tests/Package/Activity/NotificationsTest.php b/Tests/Package/Activity/NotificationsTest.php index 2351bc13..45ddd078 100644 --- a/Tests/Package/Activity/NotificationsTest.php +++ b/Tests/Package/Activity/NotificationsTest.php @@ -73,10 +73,11 @@ public function testGetListRepository() { $this->response->code = 200; $this->response->body = $this->sampleString; + $args = 'all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00'; $this->client->expects($this->once()) ->method('get') - ->with('/repos/{owner}/{repo}/notifications?all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00', array(), 0) + ->with('/repos/{owner}/{repo}/notifications?' . $args, array(), 0) ->will($this->returnValue($this->response)); $this->assertThat( diff --git a/Tests/Package/AuthorizationsTest.php b/Tests/Package/AuthorizationsTest.php index b1a70cd0..e4c164d0 100644 --- a/Tests/Package/AuthorizationsTest.php +++ b/Tests/Package/AuthorizationsTest.php @@ -48,14 +48,15 @@ public function testCreate() $this->response->code = 201; $this->response->body = $this->sampleString; - $authorisation = new \stdClass; - $authorisation->scopes = array('public_repo'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; + $authorisation = '{' + . '"scopes":["public_repo"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; $this->client->expects($this->once()) ->method('post') - ->with('/authorizations', json_encode($authorisation)) + ->with('/authorizations', $authorisation) ->will($this->returnValue($this->response)); $this->assertThat( @@ -78,14 +79,15 @@ public function testCreateFailure() $this->response->code = 500; $this->response->body = $this->errorString; - $authorisation = new \stdClass; - $authorisation->scopes = array('public_repo'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; + $authorisation = '{' + . '"scopes":["public_repo"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; $this->client->expects($this->once()) ->method('post') - ->with('/authorizations', json_encode($authorisation)) + ->with('/authorizations', $authorisation) ->will($this->returnValue($this->response)); try @@ -101,6 +103,7 @@ public function testCreateFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -159,6 +162,7 @@ public function testDeleteFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -217,6 +221,7 @@ public function testDeleteGrantFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -232,14 +237,15 @@ public function testEditAddScopes() $this->response->code = 200; $this->response->body = $this->sampleString; - $authorisation = new \stdClass; - $authorisation->add_scopes = array('public_repo', 'gist'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; + $authorisation = '{' + . '"add_scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; $this->client->expects($this->once()) ->method('patch') - ->with('/authorizations/42', json_encode($authorisation)) + ->with('/authorizations/42', $authorisation) ->will($this->returnValue($this->response)); $this->assertThat( @@ -260,14 +266,15 @@ public function testEditRemoveScopes() $this->response->code = 200; $this->response->body = $this->sampleString; - $authorisation = new \stdClass; - $authorisation->remove_scopes = array('public_repo', 'gist'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; + $authorisation = '{' + . '"remove_scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; $this->client->expects($this->once()) ->method('patch') - ->with('/authorizations/42', json_encode($authorisation)) + ->with('/authorizations/42', $authorisation) ->will($this->returnValue($this->response)); $this->assertThat( @@ -288,14 +295,15 @@ public function testEditScopes() $this->response->code = 200; $this->response->body = $this->sampleString; - $authorisation = new \stdClass; - $authorisation->scopes = array('public_repo', 'gist'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; + $authorisation = '{' + . '"scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; $this->client->expects($this->once()) ->method('patch') - ->with('/authorizations/42', json_encode($authorisation)) + ->with('/authorizations/42', $authorisation) ->will($this->returnValue($this->response)); $this->assertThat( @@ -318,14 +326,15 @@ public function testEditFailure() $this->response->code = 500; $this->response->body = $this->errorString; - $authorisation = new \stdClass; - $authorisation->add_scopes = array('public_repo', 'gist'); - $authorisation->note = 'My test app'; - $authorisation->note_url = 'http://www.joomla.org'; + $authorisation = '{' + . '"add_scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; $this->client->expects($this->once()) ->method('patch') - ->with('/authorizations/42', json_encode($authorisation)) + ->with('/authorizations/42', $authorisation) ->will($this->returnValue($this->response)); try @@ -341,6 +350,7 @@ public function testEditFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -568,7 +578,7 @@ public function testGetRateLimit() * * @since 1.0 */ - public function testGetRateLimit_unlimited() + public function testGetRateLimitUnlimited() { $this->response->code = 404; $this->response->body = ''; diff --git a/Tests/Package/GistsTest.php b/Tests/Package/GistsTest.php index 9335bae5..bc0ceb41 100755 --- a/Tests/Package/GistsTest.php +++ b/Tests/Package/GistsTest.php @@ -168,6 +168,7 @@ public function testCreateFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -228,6 +229,7 @@ public function testCreateCommentFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -279,6 +281,7 @@ public function testDeleteFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -330,6 +333,7 @@ public function testDeleteCommentFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -424,6 +428,7 @@ public function testEditFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -484,6 +489,7 @@ public function testEditCommentFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -538,6 +544,7 @@ public function testForkFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -592,6 +599,7 @@ public function testGetFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -646,6 +654,7 @@ public function testGetCommentFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -700,6 +709,7 @@ public function testGetCommentsFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -754,6 +764,7 @@ public function testGetCommitListFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -808,6 +819,7 @@ public function testGetForkListFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -862,6 +874,7 @@ public function testGetListFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -916,6 +929,7 @@ public function testGetListByUserFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -970,6 +984,7 @@ public function testGetListPublicFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -1024,6 +1039,7 @@ public function testGetListStarredFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -1078,6 +1094,7 @@ public function testGetRevisionFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -1153,6 +1170,7 @@ public function testIsStarredFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -1204,6 +1222,7 @@ public function testStarFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -1255,6 +1274,7 @@ public function testUnstarFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } } diff --git a/Tests/Package/Issues/MilestonesTest.php b/Tests/Package/Issues/MilestonesTest.php index e496d270..aff94596 100644 --- a/Tests/Package/Issues/MilestonesTest.php +++ b/Tests/Package/Issues/MilestonesTest.php @@ -49,15 +49,13 @@ public function testCreate() $this->response->code = 201; $this->response->body = $this->sampleString; - $milestone = new \stdClass; - $milestone->title = 'My Milestone'; - $milestone->state = 'open'; - $milestone->description = 'This milestone is impossible'; - $milestone->due_on = '2012-12-25T20:09:31Z'; + $milestone = '{' + . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' + . '}'; $this->client->expects($this->once()) ->method('post') - ->with('/repos/joomla/joomla-platform/milestones', json_encode($milestone)) + ->with('/repos/joomla/joomla-platform/milestones', $milestone) ->will($this->returnValue($this->response)); $this->assertThat( @@ -80,15 +78,13 @@ public function testCreateFailure() $this->response->code = 501; $this->response->body = $this->errorString; - $milestone = new \stdClass; - $milestone->title = 'My Milestone'; - $milestone->state = 'open'; - $milestone->description = 'This milestone is impossible'; - $milestone->due_on = '2012-12-25T20:09:31Z'; + $milestone = '{' + . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' + . '}'; $this->client->expects($this->once()) ->method('post') - ->with('/repos/joomla/joomla-platform/milestones', json_encode($milestone)) + ->with('/repos/joomla/joomla-platform/milestones', $milestone) ->will($this->returnValue($this->response)); $this->object->create('joomla', 'joomla-platform', 'My Milestone', 'open', 'This milestone is impossible', '2012-12-25T20:09:31Z'); @@ -132,20 +128,19 @@ public function testEditAllParameters() $this->response->code = 200; $this->response->body = $this->sampleString; - $milestone = new \stdClass; - $milestone->title = 'This is the revised title.'; - $milestone->state = 'closed'; - $milestone->description = 'This describes it perfectly.'; - $milestone->due_on = '2012-12-25T20:09:31Z'; + $milestone = '{' + . '"title":"{title}","state":"closed","description":"{description}","due_on":"2012-12-25T20:09:31Z"' + . '}'; $this->client->expects($this->once()) ->method('patch') - ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) + ->with('/repos/{user}/{repo}/milestones/523', $milestone) ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 523, 'This is the revised title.', 'closed', 'This describes it perfectly.', - '2012-12-25T20:09:31Z'), + $this->object->edit('{user}', '{repo}', 523, '{title}', 'closed', '{description}', + '2012-12-25T20:09:31Z' + ), $this->equalTo(json_decode($this->sampleString)) ); } @@ -168,9 +163,9 @@ public function testEditFailure() $milestone->state = 'closed'; $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) - ->will($this->returnValue($this->response)); + ->method('patch') + ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) + ->will($this->returnValue($this->response)); $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'); } @@ -233,13 +228,13 @@ public function testGetList() $this->response->body = $this->sampleString; $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') - ->will($this->returnValue($this->response)); + ->method('get') + ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') + ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) ); } @@ -258,9 +253,9 @@ public function testGetListFailure() $this->response->body = $this->errorString; $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') - ->will($this->returnValue($this->response)); + ->method('get') + ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') + ->will($this->returnValue($this->response)); $this->object->getList('joomla', 'joomla-platform'); } @@ -278,9 +273,9 @@ public function testDelete() $this->response->body = $this->sampleString; $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/milestones/254') - ->will($this->returnValue($this->response)); + ->method('delete') + ->with('/repos/joomla/joomla-platform/milestones/254') + ->will($this->returnValue($this->response)); $this->object->delete('joomla', 'joomla-platform', 254); } @@ -300,9 +295,9 @@ public function testDeleteFailure() $this->response->body = $this->errorString; $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/milestones/254') - ->will($this->returnValue($this->response)); + ->method('delete') + ->with('/repos/joomla/joomla-platform/milestones/254') + ->will($this->returnValue($this->response)); $this->object->delete('joomla', 'joomla-platform', 254); } diff --git a/Tests/Package/MarkdownTest.php b/Tests/Package/MarkdownTest.php index d290fbad..355661c1 100644 --- a/Tests/Package/MarkdownTest.php +++ b/Tests/Package/MarkdownTest.php @@ -53,7 +53,8 @@ public function testRender() $mode = 'gfm'; $context = 'github/gollum'; - $data = str_replace('\\/', '/', json_encode( + $data = str_replace( + '\\/', '/', json_encode( array( 'text' => $text, 'mode' => $mode, @@ -104,7 +105,8 @@ public function testRenderFailure() $mode = 'gfm'; $context = 'github/gollum'; - $data = str_replace('\\/', '/', json_encode( + $data = str_replace( + '\\/', '/', json_encode( array( 'text' => $text, 'mode' => $mode, diff --git a/Tests/Package/Pulls/CommentsTest.php b/Tests/Package/Pulls/CommentsTest.php index 71ffacbb..007943d3 100644 --- a/Tests/Package/Pulls/CommentsTest.php +++ b/Tests/Package/Pulls/CommentsTest.php @@ -49,10 +49,11 @@ public function testCreate() { $this->response->code = 201; $this->response->body = $this->sampleString; + $data = '{"body":"The Body","commit_id":"123abc","path":"a\/b\/c","position":456}'; $this->client->expects($this->once()) ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/1/comments', '{"body":"The Body","commit_id":"123abc","path":"a\/b\/c","position":456}', array(), 0) + ->with('/repos/joomla/joomla-platform/pulls/1/comments', $data, array(), 0) ->will($this->returnValue($this->response)); $this->assertThat( diff --git a/Tests/Package/PullsTest.php b/Tests/Package/PullsTest.php index dc0254c8..020a9245 100755 --- a/Tests/Package/PullsTest.php +++ b/Tests/Package/PullsTest.php @@ -59,7 +59,8 @@ public function testCreate() $this->assertThat( $this->object->create('joomla', 'joomla-platform', 'My Pull Request', 'staging', 'joomla-jenkins:mychanges', - 'These are my changes - please review them'), + 'These are my changes - please review them' + ), $this->equalTo(json_decode($this->sampleString)) ); } @@ -88,7 +89,8 @@ public function testCreateFailure() ->will($this->returnValue($this->response)); $this->object->create('joomla', 'joomla-platform', 'My Pull Request', 'staging', 'joomla-jenkins:mychanges', - 'These are my changes - please review them'); + 'These are my changes - please review them' + ); } /** diff --git a/Tests/Package/Repositories/ContentsTest.php b/Tests/Package/Repositories/ContentsTest.php index 016d0162..dd1753c7 100644 --- a/Tests/Package/Repositories/ContentsTest.php +++ b/Tests/Package/Repositories/ContentsTest.php @@ -195,7 +195,8 @@ public function testCreate() $this->assertThat( $this->object->create( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com'), + 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com' + ), $this->equalTo(json_decode($this->sampleString)) ); } @@ -211,7 +212,8 @@ public function testCreateFail1() { $this->object->create( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', '', 'elkuku', 'elkuku@example.com'); + 'eddieajau', '', 'elkuku', 'elkuku@example.com' + ); } /** @@ -225,7 +227,8 @@ public function testCreateFail2() { $this->object->create( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', ''); + 'eddieajau', 'eddieajau@example.com', 'elkuku', '' + ); } /** @@ -246,7 +249,8 @@ public function testUpdate() $this->assertThat( $this->object->update( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com'), + 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com' + ), $this->equalTo(json_decode($this->sampleString)) ); } @@ -262,7 +266,8 @@ public function testUpdateFail1() { $this->object->update( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', - 'eddieajau', '', 'elkuku', 'elkuku@example.com'); + 'eddieajau', '', 'elkuku', 'elkuku@example.com' + ); } /** @@ -276,7 +281,8 @@ public function testUpdateFail2() { $this->object->update( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', ''); + 'eddieajau', 'eddieajau@example.com', 'elkuku', '' + ); } /** @@ -297,7 +303,8 @@ public function testDelete() $this->assertThat( $this->object->delete( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com'), + 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com' + ), $this->equalTo(json_decode($this->sampleString)) ); } @@ -313,7 +320,8 @@ public function testDeleteFail1() { $this->object->delete( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', '', 'elkuku', 'elkuku@example.com'); + 'eddieajau', '', 'elkuku', 'elkuku@example.com' + ); } /** @@ -327,6 +335,7 @@ public function testDeleteFail2() { $this->object->delete( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', ''); + 'eddieajau', 'eddieajau@example.com', 'elkuku', '' + ); } } diff --git a/Tests/Package/Repositories/HooksTest.php b/Tests/Package/Repositories/HooksTest.php index 48e2d3c1..6b355a35 100644 --- a/Tests/Package/Repositories/HooksTest.php +++ b/Tests/Package/Repositories/HooksTest.php @@ -110,6 +110,7 @@ public function testCreateFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -192,6 +193,7 @@ public function testDeleteFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -209,17 +211,14 @@ public function testEdit() $this->response->code = 200; $this->response->body = $this->sampleString; - $hook = new \stdClass; - $hook->name = 'acunote'; - $hook->config = array('token' => '123456789'); - $hook->events = array('push', 'public'); - $hook->add_events = array('watch'); - $hook->remove_events = array('watch'); - $hook->active = true; + $hook = '{' + . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' + . '"add_events":["watch"],"remove_events":["watch"],"active":true' + . '}'; $this->client->expects($this->once()) ->method('patch') - ->with('/repos/joomla/joomla-platform/hooks/42', json_encode($hook)) + ->with('/repos/joomla/joomla-platform/hooks/42', $hook) ->will($this->returnValue($this->response)); $this->assertThat( @@ -248,17 +247,14 @@ public function testEditFailure() $this->response->code = 500; $this->response->body = $this->errorString; - $hook = new \stdClass; - $hook->name = 'acunote'; - $hook->config = array('token' => '123456789'); - $hook->events = array('push', 'public'); - $hook->add_events = array('watch'); - $hook->remove_events = array('watch'); - $hook->active = true; + $hook = '{' + . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' + . '"add_events":["watch"],"remove_events":["watch"],"active":true' + . '}'; $this->client->expects($this->once()) ->method('patch') - ->with('/repos/joomla/joomla-platform/hooks/42', json_encode($hook)) + ->with('/repos/joomla/joomla-platform/hooks/42', $hook) ->will($this->returnValue($this->response)); try @@ -276,6 +272,7 @@ public function testEditFailure() $this->equalTo(json_decode($this->errorString)->message) ); } + $this->assertTrue($exception); } @@ -330,7 +327,9 @@ public function testEditUnauthorisedAddEvent() */ public function testEditUnauthorisedRemoveEvent() { - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('push'), array('push'), array('invalid')); + $this->object->edit( + 'joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('push'), array('push'), array('invalid') + ); } /** diff --git a/Tests/Package/Repositories/ReleasesTest.php b/Tests/Package/Repositories/ReleasesTest.php index 86a44649..67533d3f 100644 --- a/Tests/Package/Repositories/ReleasesTest.php +++ b/Tests/Package/Repositories/ReleasesTest.php @@ -139,9 +139,9 @@ public function testGetList() $releases = array(); - foreach (json_decode($this->response->body) as $release) + foreach (json_decode($this->response->body) as $i => $release) { - $releases[$release->tag_name] = $release; + $releases[$i + 1] = $release; } $this->client->expects($this->once()) diff --git a/Tests/PackageTest.php b/Tests/PackageTest.php index 7fc4b9bd..115da02e 100755 --- a/Tests/PackageTest.php +++ b/Tests/PackageTest.php @@ -44,7 +44,7 @@ protected function setUp() * * @since 1.0 */ - public function test__Get() + public function testGet() { $this->assertThat( $this->object->repositories->forks, @@ -61,7 +61,7 @@ public function test__Get() * * @expectedException \InvalidArgumentException */ - public function test__GetInvalid() + public function testGetInvalid() { $this->object->repositories->INVALID; } From 6e9e97592f0eb9eed8c0463401facf1e30bdefdf Mon Sep 17 00:00:00 2001 From: elkuku Date: Tue, 9 May 2017 02:27:24 -0500 Subject: [PATCH 19/79] Add PHPCS check on Travis for Tests folder --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6eb8eeac..b7053884 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,4 +31,4 @@ before_script: script: - vendor/bin/phpunit - - if [ "$RUN_PHPCS" == "yes" ]; then vendor/bin/phpcs -p --report=full --extensions=php --standard=.travis/phpcs/Joomla/ruleset.xml src/; fi; + - if [ "$RUN_PHPCS" == "yes" ]; then vendor/bin/phpcs -p --report=full --extensions=php --standard=.travis/phpcs/Joomla/ruleset.xml src/ Tests/; fi; From ab979f28f002b1ac14f48f7516edbe37c078a5ef Mon Sep 17 00:00:00 2001 From: elkuku Date: Tue, 9 May 2017 02:36:50 -0500 Subject: [PATCH 20/79] Ignore a test case --- Tests/Stub/ObjectMock.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/Stub/ObjectMock.php b/Tests/Stub/ObjectMock.php index 9c4ae5ba..9628962a 100644 --- a/Tests/Stub/ObjectMock.php +++ b/Tests/Stub/ObjectMock.php @@ -15,6 +15,7 @@ */ class ObjectMock extends AbstractGithubObject { + // @codingStandardsIgnoreStart /** * Method to build and return a full request URL for the request. This method will * add appropriate pagination details if necessary and also prepend the API url @@ -32,4 +33,5 @@ public function fetchUrl($path, $page = 0, $limit = 0) { return parent::fetchUrl($path, $page, $limit); } + // @codingStandardsIgnoreEnd } From 5a7810d3954e5c955608312b83b14b6d06ca523c Mon Sep 17 00:00:00 2001 From: elkuku Date: Tue, 9 May 2017 12:55:57 -0500 Subject: [PATCH 21/79] Fix code style - Based on JCodingStandards 2.0-alpha --- src/Package/Issues.php | 5 +++-- src/Package/Markdown.php | 8 +++++--- src/Package/Repositories/Deployments.php | 11 +++++++---- src/Package/Repositories/Downloads.php | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Package/Issues.php b/src/Package/Issues.php index 6cdd6b99..f964a686 100644 --- a/src/Package/Issues.php +++ b/src/Package/Issues.php @@ -43,7 +43,7 @@ class Issues extends AbstractPackage * @since 1.0 * @throws \DomainException */ - public function create($user, $repo, $title, $body = null, $assignee = null, $milestone = null, array $labels = array(), array $assignees = array()) + public function create($user, $repo, $title, $body = null, $assignee = null, $milestone = null, array $labels = [], array $assignees = []) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues'; @@ -88,7 +88,8 @@ public function create($user, $repo, $title, $body = null, $assignee = null, $mi * @since 1.0 * @throws \DomainException */ - public function edit($user, $repo, $issueId, $state = null, $title = null, $body = null, $assignee = null, $milestone = null, array $labels = null) + public function edit($user, $repo, $issueId, $state = null, $title = null, $body = null, $assignee = null, + $milestone = null, array $labels = null) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; diff --git a/src/Package/Markdown.php b/src/Package/Markdown.php index bb6f5ea9..47d7f8f5 100644 --- a/src/Package/Markdown.php +++ b/src/Package/Markdown.php @@ -48,12 +48,14 @@ public function render($text, $mode = 'gfm', $context = null) $path = '/markdown'; // Build the request data. - $data = str_replace('\\/', '/', json_encode( - array( + $data = str_replace( + '\\/', '/', + json_encode( + [ 'text' => $text, 'mode' => $mode, 'context' => $context - ) + ] ) ); diff --git a/src/Package/Repositories/Deployments.php b/src/Package/Repositories/Deployments.php index f922e5d9..7b40a51f 100644 --- a/src/Package/Repositories/Deployments.php +++ b/src/Package/Repositories/Deployments.php @@ -75,10 +75,13 @@ public function getList($owner, $repo, $sha = '', $ref = '', $task = '', $enviro * @param string $repo The name of the GitHub repository. * @param string $ref The ref to deploy. This can be a branch, tag, or SHA. * @param string $task Optional parameter to specify a task to execute. - * @param boolean $autoMerge Optional parameter to merge the default branch into the requested ref if it is behind the default branch. - * @param array|null $requiredContexts Optional array of status contexts verified against commit status checks. If this parameter is omitted - * from the parameters then all unique contexts will be verified before a deployment is created. To bypass - * checking entirely pass an empty array. Defaults to all unique contexts. + * @param boolean $autoMerge Optional parameter to merge the default branch into the requested ref if + * it is behind the default branch. + * @param array|null $requiredContexts Optional array of status contexts verified against commit status checks. + * If this parameter is omitted + * from the parameters then all unique contexts will be verified before a + * deployment is created. To bypass checking entirely pass an empty array. + * Defaults to all unique contexts. * @param string $payload Optional JSON payload with extra information about the deployment. * @param string $environment Optional name for the target deployment environment. * @param string $description Optional short description. diff --git a/src/Package/Repositories/Downloads.php b/src/Package/Repositories/Downloads.php index 85d41d1a..cff32f9e 100644 --- a/src/Package/Repositories/Downloads.php +++ b/src/Package/Repositories/Downloads.php @@ -81,7 +81,7 @@ public function get($owner, $repo, $id) * @param string $description The description. * @param string $content_type The content type. * - * @return boolean + * @return void * * @note This API endpoint no longer exists at GitHub * @since 1.0 @@ -131,7 +131,7 @@ public function create($owner, $repo, $name, $size, $description = '', $content_ * @param string $file Local file. Example assumes the file existing in the directory * where you are running the curl command. Yes, the @ matters. * - * @return boolean + * @return void * * @note This API endpoint no longer exists at GitHub * @since 1.0 From bf8fe6e6a60e6773d8f5f61fcf82a52f71dececa Mon Sep 17 00:00:00 2001 From: elkuku Date: Tue, 9 May 2017 13:06:01 -0500 Subject: [PATCH 22/79] Update .gitignore Add new line --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 04cf9643..340b0780 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ phpunit.xml # Build files /build/coverage -/build/logs \ No newline at end of file +/build/logs From ce8b10316f24cf69594a0b3a11af9b4588712780 Mon Sep 17 00:00:00 2001 From: elkuku Date: Tue, 9 May 2017 13:26:35 -0500 Subject: [PATCH 23/79] Use short array syntax To overcome line length sniff =;) --- Tests/Package/Issues/AssigneesTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tests/Package/Issues/AssigneesTest.php b/Tests/Package/Issues/AssigneesTest.php index 18e390ad..b1cc857a 100644 --- a/Tests/Package/Issues/AssigneesTest.php +++ b/Tests/Package/Issues/AssigneesTest.php @@ -210,9 +210,7 @@ public function testRemove() $this->client->expects($this->once()) ->method('delete') - ->with('/repos/' . $this->owner . '/' . $this->repo - . '/issues/123/assignees', array(), null, json_encode(array('assignees' => array('joomla'))) - ) + ->with('/repos/' . $this->owner . '/' . $this->repo . '/issues/123/assignees', [], null, json_encode(['assignees' => ['joomla']])) ->will($this->returnValue($this->response)); $this->assertThat( From 3aa5826e51c83cbac350b5563280f74cfb76bb3d Mon Sep 17 00:00:00 2001 From: elkuku Date: Tue, 9 May 2017 14:13:33 -0500 Subject: [PATCH 24/79] Add and Use a default response --- Tests/Package/Activity/EventsTest.php | 30 ------------ Tests/Package/Activity/FeedsTest.php | 3 -- Tests/Package/Activity/NotificationsTest.php | 15 ------ Tests/Package/Activity/StarringTest.php | 10 ---- Tests/Package/Activity/WatchingTest.php | 15 ------ Tests/Package/AuthorizationsTest.php | 28 ----------- Tests/Package/Data/BlobsTest.php | 4 -- Tests/Package/Data/CommitsTest.php | 4 -- Tests/Package/Data/RefsTest.php | 13 ----- Tests/Package/Data/TagsTest.php | 4 -- Tests/Package/Data/TreesTest.php | 7 --- Tests/Package/EmojisTest.php | 3 -- Tests/Package/GistsTest.php | 47 ------------------- Tests/Package/Issues/CommentsTest.php | 22 --------- Tests/Package/Issues/EventsTest.php | 9 ---- Tests/Package/Issues/LabelsTest.php | 27 ----------- Tests/Package/Issues/MilestonesTest.php | 14 ------ Tests/Package/IssuesTest.php | 20 -------- Tests/Package/MetaTest.php | 3 -- Tests/Package/Orgs/HooksTest.php | 10 ---- Tests/Package/Orgs/MembersTest.php | 34 -------------- Tests/Package/Orgs/TeamsTest.php | 38 --------------- Tests/Package/OrgsTest.php | 9 ---- Tests/Package/Pulls/CommentsTest.php | 11 ----- Tests/Package/PullsTest.php | 22 --------- .../Repositories/CollaboratorsTest.php | 5 -- Tests/Package/Repositories/CommentsTest.php | 14 ------ Tests/Package/Repositories/CommitsTest.php | 13 ----- Tests/Package/Repositories/ContentsTest.php | 22 --------- .../Package/Repositories/DeploymentsTest.php | 10 ---- Tests/Package/Repositories/DownloadsTest.php | 7 --- Tests/Package/Repositories/ForksTest.php | 4 -- Tests/Package/Repositories/HooksTest.php | 13 ----- Tests/Package/Repositories/KeysTest.php | 10 ---- Tests/Package/Repositories/MergingTest.php | 5 -- Tests/Package/Repositories/PagesTest.php | 9 ---- Tests/Package/Repositories/ReleasesTest.php | 21 --------- Tests/Package/Repositories/StatisticsTest.php | 16 ------- Tests/Package/Repositories/StatusesTest.php | 7 --- Tests/Package/RepositoriesTest.php | 35 -------------- Tests/Package/SearchTest.php | 15 ------ Tests/Package/Users/EmailsTest.php | 5 -- Tests/Package/Users/FollowersTest.php | 12 ----- Tests/Package/Users/KeysTest.php | 14 ------ Tests/Stub/GitHubTestCase.php | 4 ++ 45 files changed, 4 insertions(+), 639 deletions(-) diff --git a/Tests/Package/Activity/EventsTest.php b/Tests/Package/Activity/EventsTest.php index 69d20dbe..68a4474c 100644 --- a/Tests/Package/Activity/EventsTest.php +++ b/Tests/Package/Activity/EventsTest.php @@ -56,9 +56,6 @@ protected function setUp() */ public function testGetPublic() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/events') @@ -77,9 +74,6 @@ public function testGetPublic() */ public function testGetRepository() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $path = '/repos/' . $this->owner . '/' . $this->repo . '/events'; $this->client->expects($this->once()) @@ -100,9 +94,6 @@ public function testGetRepository() */ public function testGetIssue() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $path = '/repos/' . $this->owner . '/' . $this->repo . '/issues/events'; $this->client->expects($this->once()) @@ -123,9 +114,6 @@ public function testGetIssue() */ public function testGetNetwork() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $path = '/networks/' . $this->owner . '/' . $this->repo . '/events'; $this->client->expects($this->once()) @@ -146,9 +134,6 @@ public function testGetNetwork() */ public function testGetOrg() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $path = '/orgs/' . $this->owner . '/events'; $this->client->expects($this->once()) @@ -169,9 +154,6 @@ public function testGetOrg() */ public function testGetUser() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $path = '/users/' . $this->owner . '/received_events'; $this->client->expects($this->once()) @@ -192,9 +174,6 @@ public function testGetUser() */ public function testGetUserPublic() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $path = '/users/' . $this->owner . '/received_events/public'; $this->client->expects($this->once()) @@ -215,9 +194,6 @@ public function testGetUserPublic() */ public function testGetByUser() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $path = '/users/' . $this->owner . '/events'; $this->client->expects($this->once()) @@ -238,9 +214,6 @@ public function testGetByUser() */ public function testGetByUserPublic() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $path = '/users/' . $this->owner . '/events/public'; $this->client->expects($this->once()) @@ -261,9 +234,6 @@ public function testGetByUserPublic() */ public function testGetUserOrg() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $path = '/users/' . $this->owner . '/events/orgs/' . $this->repo; $this->client->expects($this->once()) diff --git a/Tests/Package/Activity/FeedsTest.php b/Tests/Package/Activity/FeedsTest.php index 34b213c7..eaabc5e2 100644 --- a/Tests/Package/Activity/FeedsTest.php +++ b/Tests/Package/Activity/FeedsTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGetFeeds() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/feeds') diff --git a/Tests/Package/Activity/NotificationsTest.php b/Tests/Package/Activity/NotificationsTest.php index 45ddd078..bf2e54f1 100644 --- a/Tests/Package/Activity/NotificationsTest.php +++ b/Tests/Package/Activity/NotificationsTest.php @@ -48,9 +48,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/notifications?all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00', array(), 0) @@ -71,8 +68,6 @@ public function testGetList() */ public function testGetListRepository() { - $this->response->code = 200; - $this->response->body = $this->sampleString; $args = 'all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00'; $this->client->expects($this->once()) @@ -195,9 +190,6 @@ public function testMarkReadRepositoryLastRead() */ public function testViewThread() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/notifications/threads/1', array(), 0) @@ -219,7 +211,6 @@ public function testViewThread() public function testMarkReadThread() { $this->response->code = 205; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('patch') @@ -241,9 +232,6 @@ public function testMarkReadThread() */ public function testGetThreadSubscription() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/notifications/threads/1/subscription', array(), 0) @@ -264,9 +252,6 @@ public function testGetThreadSubscription() */ public function testSetThreadSubscription() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('put') ->with('/notifications/threads/1/subscription', '{"subscribed":true,"ignored":false}', array(), 0) diff --git a/Tests/Package/Activity/StarringTest.php b/Tests/Package/Activity/StarringTest.php index 795f478e..c6e6c1f1 100644 --- a/Tests/Package/Activity/StarringTest.php +++ b/Tests/Package/Activity/StarringTest.php @@ -48,9 +48,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/stargazers', array(), 0) @@ -71,9 +68,6 @@ public function testGetList() */ public function testGetRepositories() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/user/starred?sort=created&direction=desc', array(), 0) @@ -94,9 +88,6 @@ public function testGetRepositories() */ public function testGetRepositoriesWithName() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/users/{user}/starred?sort=created&direction=desc', array(), 0) @@ -220,7 +211,6 @@ public function testCheckUnexpected() public function testStar() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('put') diff --git a/Tests/Package/Activity/WatchingTest.php b/Tests/Package/Activity/WatchingTest.php index 0275cdf0..8f8a80b7 100644 --- a/Tests/Package/Activity/WatchingTest.php +++ b/Tests/Package/Activity/WatchingTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/subscribers', array(), 0) @@ -65,9 +62,6 @@ public function testGetList() */ public function testGetRepositories() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/user/subscriptions', array(), 0) @@ -86,9 +80,6 @@ public function testGetRepositories() */ public function testGetRepositoriesUser() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/subscriptions', array(), 0) @@ -107,9 +98,6 @@ public function testGetRepositoriesUser() */ public function testGetSubscription() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/subscription', array(), 0) @@ -128,9 +116,6 @@ public function testGetSubscription() */ public function testSetSubscription() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/subscription', '{"subscribed":true,"ignored":false}', array(), 0) diff --git a/Tests/Package/AuthorizationsTest.php b/Tests/Package/AuthorizationsTest.php index e4c164d0..b5cd3a88 100644 --- a/Tests/Package/AuthorizationsTest.php +++ b/Tests/Package/AuthorizationsTest.php @@ -46,7 +46,6 @@ protected function setUp() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $authorisation = '{' . '"scopes":["public_repo"],' @@ -117,7 +116,6 @@ public function testCreateFailure() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -176,7 +174,6 @@ public function testDeleteFailure() public function testDeleteGrant() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -234,9 +231,6 @@ public function testDeleteGrantFailure() */ public function testEditAddScopes() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $authorisation = '{' . '"add_scopes":["public_repo","gist"],' . '"note":"My test app",' @@ -263,9 +257,6 @@ public function testEditAddScopes() */ public function testEditRemoveScopes() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $authorisation = '{' . '"remove_scopes":["public_repo","gist"],' . '"note":"My test app",' @@ -292,9 +283,6 @@ public function testEditRemoveScopes() */ public function testEditScopes() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $authorisation = '{' . '"scopes":["public_repo","gist"],' . '"note":"My test app",' @@ -377,9 +365,6 @@ public function testEditTooManyScopes() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/authorizations/42') @@ -422,9 +407,6 @@ public function testGetFailure() */ public function testGetGrant() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/authorizations/grants/42') @@ -467,9 +449,6 @@ public function testGetGrantFailure() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/authorizations') @@ -512,9 +491,6 @@ public function testGetListFailure() */ public function testGetListGrants() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/authorizations/grants') @@ -557,9 +533,6 @@ public function testGetListGrantsFailure() */ public function testGetRateLimit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/rate_limit') @@ -718,7 +691,6 @@ public function testRequestTokenInvalidFormat() public function testRevokeGrantForApplication() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') diff --git a/Tests/Package/Data/BlobsTest.php b/Tests/Package/Data/BlobsTest.php index 538ef3f2..d670a83f 100644 --- a/Tests/Package/Data/BlobsTest.php +++ b/Tests/Package/Data/BlobsTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/blobs/12345', array(), 0) @@ -66,7 +63,6 @@ public function testGet() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') diff --git a/Tests/Package/Data/CommitsTest.php b/Tests/Package/Data/CommitsTest.php index ccc9ea6f..58db8314 100644 --- a/Tests/Package/Data/CommitsTest.php +++ b/Tests/Package/Data/CommitsTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/commits/12345', array(), 0) @@ -66,7 +63,6 @@ public function testGet() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') diff --git a/Tests/Package/Data/RefsTest.php b/Tests/Package/Data/RefsTest.php index 142c505c..43aed572 100755 --- a/Tests/Package/Data/RefsTest.php +++ b/Tests/Package/Data/RefsTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/refs/heads/master') @@ -86,7 +83,6 @@ public function testGetFailure() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; // Build the request data. $data = json_encode( @@ -142,9 +138,6 @@ public function testCreateFailure() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - // Build the request data. $data = json_encode( array( @@ -198,9 +191,6 @@ public function testEditFailure() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/refs') @@ -219,9 +209,6 @@ public function testGetList() */ public function testGetListWithNamespace() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/refs/tags') diff --git a/Tests/Package/Data/TagsTest.php b/Tests/Package/Data/TagsTest.php index a2f15db1..984d96a4 100644 --- a/Tests/Package/Data/TagsTest.php +++ b/Tests/Package/Data/TagsTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/tags/12345', array(), 0) @@ -66,7 +63,6 @@ public function testGet() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $data = '{"tag":"0.1","message":"Message","object":"12345","type":"commit","tagger":' . '{"name":"elkuku","email":"email@example.com","date":"123456789"}}'; diff --git a/Tests/Package/Data/TreesTest.php b/Tests/Package/Data/TreesTest.php index aee96b44..ab3a251a 100644 --- a/Tests/Package/Data/TreesTest.php +++ b/Tests/Package/Data/TreesTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/trees/12345', array(), 0) @@ -65,9 +62,6 @@ public function testGet() */ public function testGetRecursively() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/git/trees/12345?recursive=1', array(), 0) @@ -87,7 +81,6 @@ public function testGetRecursively() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') diff --git a/Tests/Package/EmojisTest.php b/Tests/Package/EmojisTest.php index f0e6ca5a..dc1591ae 100755 --- a/Tests/Package/EmojisTest.php +++ b/Tests/Package/EmojisTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/emojis') diff --git a/Tests/Package/GistsTest.php b/Tests/Package/GistsTest.php index bc0ceb41..d3a6379d 100755 --- a/Tests/Package/GistsTest.php +++ b/Tests/Package/GistsTest.php @@ -44,7 +44,6 @@ protected function setUp() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; // Build the request data. $data = json_encode( @@ -82,7 +81,6 @@ public function testCreate() public function testCreateGistFromFile() { $this->response->code = 201; - $this->response->body = $this->sampleString; // Build the request data. $data = json_encode( @@ -122,7 +120,6 @@ public function testCreateGistFromFile() public function testCreateGistFromFileNotFound() { $this->response->code = 501; - $this->response->body = $this->sampleString; $this->object->create( array( @@ -180,7 +177,6 @@ public function testCreateFailure() public function testCreateComment() { $this->response->code = 201; - $this->response->body = $this->sampleString; $gist = new \stdClass; $gist->body = 'My Insightful Comment'; @@ -241,7 +237,6 @@ public function testCreateCommentFailure() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -293,7 +288,6 @@ public function testDeleteFailure() public function testDeleteComment() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -344,9 +338,6 @@ public function testDeleteCommentFailure() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - // Build the request data. $data = json_encode( array( @@ -439,9 +430,6 @@ public function testEditFailure() */ public function testEditComment() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $gist = new \stdClass; $gist->body = 'This comment is now even more insightful'; @@ -501,7 +489,6 @@ public function testEditCommentFailure() public function testFork() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -555,9 +542,6 @@ public function testForkFailure() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/gists/523') @@ -610,9 +594,6 @@ public function testGetFailure() */ public function testGetComment() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/gists/comments/523') @@ -665,9 +646,6 @@ public function testGetCommentFailure() */ public function testGetComments() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/gists/523/comments') @@ -720,9 +698,6 @@ public function testGetCommentsFailure() */ public function testGetCommitList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/gists/523/commits') @@ -775,9 +750,6 @@ public function testGetCommitListFailure() */ public function testGetForkList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/gists/523/forks') @@ -830,9 +802,6 @@ public function testGetForkListFailure() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/gists') @@ -885,9 +854,6 @@ public function testGetListFailure() */ public function testGetListByUser() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/gists') @@ -940,9 +906,6 @@ public function testGetListByUserFailure() */ public function testGetListPublic() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/gists/public') @@ -995,9 +958,6 @@ public function testGetListPublicFailure() */ public function testGetListStarred() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/gists/starred') @@ -1050,9 +1010,6 @@ public function testGetListStarredFailure() */ public function testGetRevision() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/gists/523/a1b2c3') @@ -1106,7 +1063,6 @@ public function testGetRevisionFailure() public function testIsStarredTrue() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -1127,7 +1083,6 @@ public function testIsStarredTrue() public function testIsStarredFalse() { $this->response->code = 404; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -1182,7 +1137,6 @@ public function testIsStarredFailure() public function testStar() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('put') @@ -1234,7 +1188,6 @@ public function testStarFailure() public function testUnstar() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') diff --git a/Tests/Package/Issues/CommentsTest.php b/Tests/Package/Issues/CommentsTest.php index 9a2bd3ae..d43e47bc 100644 --- a/Tests/Package/Issues/CommentsTest.php +++ b/Tests/Package/Issues/CommentsTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/1/comments', array(), 0) @@ -65,9 +62,6 @@ public function testGetList() */ public function testGetRepositoryList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/comments?sort=created&direction=asc', array(), 0) @@ -87,9 +81,6 @@ public function testGetRepositoryList() */ public function testGetRepositoryListInvalidSort() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->object->getRepositoryList('joomla', 'joomla-platform', 'invalid'); } @@ -101,9 +92,6 @@ public function testGetRepositoryListInvalidSort() */ public function testGetRepositoryListInvalidDirection() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'invalid'); } @@ -114,9 +102,6 @@ public function testGetRepositoryListInvalidDirection() */ public function testGetRepositoryListSince() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $date = new \DateTime('1966-09-15 12:34:56', new \DateTimeZone('UTC')); $this->client->expects($this->once()) @@ -137,9 +122,6 @@ public function testGetRepositoryListSince() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/comments/1', array(), 0) @@ -158,9 +140,6 @@ public function testGet() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/issues/comments/1', '{"body":"Hello"}', array(), 0) @@ -180,7 +159,6 @@ public function testEdit() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') diff --git a/Tests/Package/Issues/EventsTest.php b/Tests/Package/Issues/EventsTest.php index ad2ff202..171a2c55 100644 --- a/Tests/Package/Issues/EventsTest.php +++ b/Tests/Package/Issues/EventsTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/1/events', array(), 0) @@ -65,9 +62,6 @@ public function testGetList() */ public function testGetListRepository() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/1/comments', array(), 0) @@ -86,9 +80,6 @@ public function testGetListRepository() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/events/1', array(), 0) diff --git a/Tests/Package/Issues/LabelsTest.php b/Tests/Package/Issues/LabelsTest.php index 07ae1e3f..60d69f50 100644 --- a/Tests/Package/Issues/LabelsTest.php +++ b/Tests/Package/Issues/LabelsTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/labels', array(), 0) @@ -65,9 +62,6 @@ public function testGetList() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/labels/1', array(), 0) @@ -87,7 +81,6 @@ public function testGet() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -129,9 +122,6 @@ public function testCreateFailure() */ public function testUpdate() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/labels/foobar', '{"name":"boofaz","color":"red"}', array(), 0) @@ -151,7 +141,6 @@ public function testUpdate() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -171,9 +160,6 @@ public function testDelete() */ public function testGetListByIssue() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/1/labels', array(), 0) @@ -192,9 +178,6 @@ public function testGetListByIssue() */ public function testAdd() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('post') ->with('/repos/joomla/joomla-platform/issues/1/labels', '["A","B"]', array(), 0) @@ -213,9 +196,6 @@ public function testAdd() */ public function testRemoveFromIssue() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/issues/1/labels/foobar', array(), 0) @@ -234,9 +214,6 @@ public function testRemoveFromIssue() */ public function testReplace() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/issues/1/labels', '["A","B"]', array(), 0) @@ -256,7 +233,6 @@ public function testReplace() public function testRemoveAllFromIssue() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -276,9 +252,6 @@ public function testRemoveAllFromIssue() */ public function testGetListByMilestone() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/milestones/1/labels', array(), 0) diff --git a/Tests/Package/Issues/MilestonesTest.php b/Tests/Package/Issues/MilestonesTest.php index aff94596..bc0aa8d1 100644 --- a/Tests/Package/Issues/MilestonesTest.php +++ b/Tests/Package/Issues/MilestonesTest.php @@ -47,7 +47,6 @@ protected function setUp() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $milestone = '{' . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' @@ -99,9 +98,6 @@ public function testCreateFailure() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $milestone = new \stdClass; $milestone->state = 'closed'; @@ -125,9 +121,6 @@ public function testEdit() */ public function testEditAllParameters() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $milestone = '{' . '"title":"{title}","state":"closed","description":"{description}","due_on":"2012-12-25T20:09:31Z"' . '}'; @@ -179,9 +172,6 @@ public function testEditFailure() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/milestones/523') @@ -224,9 +214,6 @@ public function testGetFailure() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') @@ -270,7 +257,6 @@ public function testGetListFailure() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') diff --git a/Tests/Package/IssuesTest.php b/Tests/Package/IssuesTest.php index 2bc5a964..0c6fe14a 100755 --- a/Tests/Package/IssuesTest.php +++ b/Tests/Package/IssuesTest.php @@ -49,7 +49,6 @@ protected function setUp() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $issue = new \stdClass; $issue->title = '{title}'; @@ -112,7 +111,6 @@ public function testCreateFailure() public function testCreateComment() { $this->response->code = 201; - $this->response->body = $this->sampleString; $issue = new \stdClass; $issue->body = 'My Insightful Comment'; @@ -164,9 +162,6 @@ public function testCreateCommentFailure() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $issue = new \stdClass; $issue->title = 'My issue'; $issue->body = 'These are my changes - please review them'; @@ -226,9 +221,6 @@ public function testEditFailure() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues/523') @@ -273,9 +265,6 @@ public function testGetFailure() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/issues') @@ -296,8 +285,6 @@ public function testGetList() */ public function testGetListAll() { - $this->response->code = 200; - $this->response->body = $this->sampleString; $since = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); $this->client->expects($this->once()) @@ -344,9 +331,6 @@ public function testGetListFailure() */ public function testGetListByRepository() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/issues') @@ -370,8 +354,6 @@ public function testGetListByRepository() public function testGetListByRepositoryAll() { $date = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); - $this->response->code = 200; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -432,7 +414,6 @@ public function testGetListByRepositoryFailure() public function testLock() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('put') @@ -479,7 +460,6 @@ public function testLockFailure() public function testUnlock() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') diff --git a/Tests/Package/MetaTest.php b/Tests/Package/MetaTest.php index a0da47bd..69d5ef14 100644 --- a/Tests/Package/MetaTest.php +++ b/Tests/Package/MetaTest.php @@ -52,9 +52,6 @@ protected function setUp() */ public function testGetMeta() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $decodedResponse = new \stdClass; $decodedResponse->hooks = array('127.0.0.1/32', '192.168.1.1/32', '10.10.1.1/27'); $decodedResponse->git = array('127.0.0.1/32'); diff --git a/Tests/Package/Orgs/HooksTest.php b/Tests/Package/Orgs/HooksTest.php index 90a15e07..51cfe1f0 100644 --- a/Tests/Package/Orgs/HooksTest.php +++ b/Tests/Package/Orgs/HooksTest.php @@ -47,9 +47,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/hooks') @@ -70,9 +67,6 @@ public function testGetList() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/hooks/123') @@ -94,7 +88,6 @@ public function testGet() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -147,7 +140,6 @@ public function testCreateInvalidEvent() public function testEdit() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -198,7 +190,6 @@ public function testEditFailure2() public function testPing() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -221,7 +212,6 @@ public function testPing() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') diff --git a/Tests/Package/Orgs/MembersTest.php b/Tests/Package/Orgs/MembersTest.php index 59de492b..8b266a08 100644 --- a/Tests/Package/Orgs/MembersTest.php +++ b/Tests/Package/Orgs/MembersTest.php @@ -47,9 +47,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/members') @@ -71,7 +68,6 @@ public function testGetList() public function testGetListNotAMember() { $this->response->code = 302; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -96,7 +92,6 @@ public function testGetListNotAMember() public function testGetListUnexpected() { $this->response->code = 666; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -119,7 +114,6 @@ public function testGetListUnexpected() public function testCheck() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -142,7 +136,6 @@ public function testCheck() public function testCheckNoMember() { $this->response->code = 404; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -165,7 +158,6 @@ public function testCheckNoMember() public function testCheckRequesterNoMember() { $this->response->code = 302; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -190,7 +182,6 @@ public function testCheckRequesterNoMember() public function testCheckUnexpectedr() { $this->response->code = 666; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -213,7 +204,6 @@ public function testCheckUnexpectedr() public function testRemove() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -235,9 +225,6 @@ public function testRemove() */ public function testGetListPublic() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/public_members') @@ -259,7 +246,6 @@ public function testGetListPublic() public function testCheckPublic() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -282,7 +268,6 @@ public function testCheckPublic() public function testCheckPublicNo() { $this->response->code = 404; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -307,7 +292,6 @@ public function testCheckPublicNo() public function testCheckPublicUnexpected() { $this->response->code = 666; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -330,7 +314,6 @@ public function testCheckPublicUnexpected() public function testPublicize() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('put') @@ -353,7 +336,6 @@ public function testPublicize() public function testConceal() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -375,9 +357,6 @@ public function testConceal() */ public function testGetMembership() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/orgs/{org}/memberships/{user}') @@ -398,9 +377,6 @@ public function testGetMembership() */ public function testUpdateMembership() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('put') ->with('/orgs/{org}/memberships/{user}') @@ -437,7 +413,6 @@ public function testUpdateMembershipInvalidRole() public function testRemoveMembership() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -459,9 +434,6 @@ public function testRemoveMembership() */ public function testListMemberships() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/user/memberships/orgs') @@ -482,9 +454,6 @@ public function testListMemberships() */ public function testListOrganizationMemberships() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/user/memberships/orgs/{org}') @@ -505,9 +474,6 @@ public function testListOrganizationMemberships() */ public function testEditOrganizationMemberships() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('patch') ->with('/user/memberships/orgs/{org}') diff --git a/Tests/Package/Orgs/TeamsTest.php b/Tests/Package/Orgs/TeamsTest.php index 5da81173..729a8176 100644 --- a/Tests/Package/Orgs/TeamsTest.php +++ b/Tests/Package/Orgs/TeamsTest.php @@ -47,9 +47,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/teams') @@ -70,9 +67,6 @@ public function testGetList() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/teams/123') @@ -94,7 +88,6 @@ public function testGet() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -119,7 +112,6 @@ public function testCreate() public function testCreateWrongPermission() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->object->create('joomla', 'TheTeam', array('joomla-platform'), 'invalid'); } @@ -133,9 +125,6 @@ public function testCreateWrongPermission() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('patch') ->with('/teams/123') @@ -158,9 +147,6 @@ public function testEdit() */ public function testEditWrongPermission() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->object->edit(123, 'TheTeam', 'invalid'); } @@ -174,7 +160,6 @@ public function testEditWrongPermission() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -196,9 +181,6 @@ public function testDelete() */ public function testGetListMembers() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/teams/123/members') @@ -222,7 +204,6 @@ public function testGetListMembers() public function testIsMember() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -247,7 +228,6 @@ public function testIsMember() public function testIsMemberNo() { $this->response->code = 404; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -274,7 +254,6 @@ public function testIsMemberNo() public function testIsMemberUnexpected() { $this->response->code = 666; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -299,7 +278,6 @@ public function testIsMemberUnexpected() public function testAddMember() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('put') @@ -324,7 +302,6 @@ public function testAddMember() public function testRemoveMember() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -346,9 +323,6 @@ public function testRemoveMember() */ public function testGetListRepos() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/teams/123/repos') @@ -370,7 +344,6 @@ public function testGetListRepos() public function testCheckRepo() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -393,7 +366,6 @@ public function testCheckRepo() public function testCheckRepoNo() { $this->response->code = 404; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -418,7 +390,6 @@ public function testCheckRepoNo() public function testCheckRepoUnexpected() { $this->response->code = 666; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -441,7 +412,6 @@ public function testCheckRepoUnexpected() public function testAddRepo() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('put') @@ -464,7 +434,6 @@ public function testAddRepo() public function testRemoveRepo() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -562,9 +531,6 @@ public function testGetTeamMembershipsFailure2() */ public function testAddTeamMemberships() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('put') ->with('/teams/123/memberships/{user}') @@ -603,7 +569,6 @@ public function testAddTeamMembershipsFailure() public function testRemoveTeamMemberships() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -625,9 +590,6 @@ public function testRemoveTeamMemberships() */ public function testGetUserTeams() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/user/teams') diff --git a/Tests/Package/OrgsTest.php b/Tests/Package/OrgsTest.php index 763502ad..23c47f7b 100644 --- a/Tests/Package/OrgsTest.php +++ b/Tests/Package/OrgsTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/orgs') @@ -64,9 +61,6 @@ public function testGetList() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla') @@ -85,9 +79,6 @@ public function testGet() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('patch') ->with('/orgs/joomla') diff --git a/Tests/Package/Pulls/CommentsTest.php b/Tests/Package/Pulls/CommentsTest.php index 007943d3..63fd77d2 100644 --- a/Tests/Package/Pulls/CommentsTest.php +++ b/Tests/Package/Pulls/CommentsTest.php @@ -48,7 +48,6 @@ protected function setUp() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $data = '{"body":"The Body","commit_id":"123abc","path":"a\/b\/c","position":456}'; $this->client->expects($this->once()) @@ -72,7 +71,6 @@ public function testCreate() public function testCreateReply() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -140,9 +138,6 @@ public function testEdit() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/comments/456', array(), 0) @@ -163,9 +158,6 @@ public function testGet() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/456/comments', array(), 0) @@ -186,9 +178,6 @@ public function testGetList() */ public function testGetListForRepo() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/{user}/{repo}/pulls/comments', [], 0) diff --git a/Tests/Package/PullsTest.php b/Tests/Package/PullsTest.php index 020a9245..a0ac3116 100755 --- a/Tests/Package/PullsTest.php +++ b/Tests/Package/PullsTest.php @@ -44,7 +44,6 @@ protected function setUp() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $pull = new \stdClass; $pull->title = 'My Pull Request'; @@ -101,7 +100,6 @@ public function testCreateFailure() public function testCreateFromIssue() { $this->response->code = 201; - $this->response->body = $this->sampleString; $pull = new \stdClass; $pull->issue = 254; @@ -151,9 +149,6 @@ public function testCreateFromIssueFailure() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $pull = new \stdClass; $pull->title = 'My Pull Request'; $pull->body = 'These are my changes - please review them'; @@ -202,9 +197,6 @@ public function testEditFailure() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523') @@ -243,9 +235,6 @@ public function testGetFailure() */ public function testGetCommits() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523/commits') @@ -284,9 +273,6 @@ public function testGetCommitsFailure() */ public function testGetFiles() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls/523/files') @@ -325,9 +311,6 @@ public function testGetFilesFailure() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/pulls?state=closed') @@ -367,7 +350,6 @@ public function testGetListFailure() public function testIsMergedTrue() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -388,7 +370,6 @@ public function testIsMergedTrue() public function testIsMergedFalse() { $this->response->code = 404; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -428,9 +409,6 @@ public function testIsMergedFailure() */ public function testMerge() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/pulls/523/merge') diff --git a/Tests/Package/Repositories/CollaboratorsTest.php b/Tests/Package/Repositories/CollaboratorsTest.php index 326a0321..6e6e9958 100644 --- a/Tests/Package/Repositories/CollaboratorsTest.php +++ b/Tests/Package/Repositories/CollaboratorsTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/collaborators') @@ -130,7 +127,6 @@ public function testGetUnexpected() public function testAdd() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('put') @@ -151,7 +147,6 @@ public function testAdd() public function testRemove() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') diff --git a/Tests/Package/Repositories/CommentsTest.php b/Tests/Package/Repositories/CommentsTest.php index adf06a6e..87b88190 100644 --- a/Tests/Package/Repositories/CommentsTest.php +++ b/Tests/Package/Repositories/CommentsTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetListRepository() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/comments') @@ -64,9 +61,6 @@ public function testGetListRepository() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/commits/123/comments') @@ -85,9 +79,6 @@ public function testGetList() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/comments/123') @@ -106,9 +97,6 @@ public function testGet() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-framework/comments/123') @@ -128,7 +116,6 @@ public function testEdit() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -149,7 +136,6 @@ public function testDelete() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') diff --git a/Tests/Package/Repositories/CommitsTest.php b/Tests/Package/Repositories/CommitsTest.php index fdb452ff..b805316a 100644 --- a/Tests/Package/Repositories/CommitsTest.php +++ b/Tests/Package/Repositories/CommitsTest.php @@ -50,9 +50,6 @@ protected function setUp() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/commits/abc1234') @@ -100,9 +97,6 @@ public function testGetFailure() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/commits') @@ -150,9 +144,6 @@ public function testGetListFailure() */ public function testCompare() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/compare/123abc...456def') @@ -175,9 +166,6 @@ public function testCompare() */ public function testgetSha() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/{user}/{repo}/commits/{ref}') @@ -204,7 +192,6 @@ public function testgetSha() public function testgetShaFailure() { $this->response->code = 666; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') diff --git a/Tests/Package/Repositories/ContentsTest.php b/Tests/Package/Repositories/ContentsTest.php index dd1753c7..1bdcff21 100644 --- a/Tests/Package/Repositories/ContentsTest.php +++ b/Tests/Package/Repositories/ContentsTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetReadme() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/readme') @@ -64,9 +61,6 @@ public function testGetReadme() */ public function testGetReadmeRef() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/readme?ref=123abc') @@ -85,9 +79,6 @@ public function testGetReadmeRef() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/contents/path/to/file.php') @@ -106,9 +97,6 @@ public function testGet() */ public function testGetRef() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/contents/path/to/file.php?ref=123abc') @@ -128,7 +116,6 @@ public function testGetRef() public function testGetArchiveLink() { $this->response->code = 302; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -149,7 +136,6 @@ public function testGetArchiveLink() public function testGetArchiveLinkRef() { $this->response->code = 302; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') @@ -172,7 +158,6 @@ public function testGetArchiveLinkRef() public function testGetArchiveLinkInvalidFormat() { $this->response->code = 302; - $this->response->body = $this->sampleString; $this->object->getArchiveLink('joomla', 'joomla-platform', 'invalid'); } @@ -185,7 +170,6 @@ public function testGetArchiveLinkInvalidFormat() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('put') @@ -238,9 +222,6 @@ public function testCreateFail2() */ public function testUpdate() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('put') ->with('/repos/joomla/joomla-platform/contents/src/foo') @@ -292,9 +273,6 @@ public function testUpdateFail2() */ public function testDelete() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-platform/contents/src/foo') diff --git a/Tests/Package/Repositories/DeploymentsTest.php b/Tests/Package/Repositories/DeploymentsTest.php index 5e1e2043..281ca18a 100644 --- a/Tests/Package/Repositories/DeploymentsTest.php +++ b/Tests/Package/Repositories/DeploymentsTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/deployments?sha={sha}&ref={ref}&task={task}&environment={environment}') @@ -65,7 +62,6 @@ public function testGetList() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -91,7 +87,6 @@ public function testCreate() public function testCreateMergeConflict() { $this->response->code = 409; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -114,7 +109,6 @@ public function testCreateMergeConflict() public function testCreateFailure() { $this->response->code = 666; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -134,9 +128,6 @@ public function testCreateFailure() */ public function testGetDeploymentStatuses() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/deployments/123/statuses') @@ -156,7 +147,6 @@ public function testGetDeploymentStatuses() public function testCreateStatus() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') diff --git a/Tests/Package/Repositories/DownloadsTest.php b/Tests/Package/Repositories/DownloadsTest.php index 1e509040..bcf89fbc 100644 --- a/Tests/Package/Repositories/DownloadsTest.php +++ b/Tests/Package/Repositories/DownloadsTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/downloads') @@ -64,9 +61,6 @@ public function testGetList() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/downloads/123abc') @@ -114,7 +108,6 @@ public function testUpload() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') diff --git a/Tests/Package/Repositories/ForksTest.php b/Tests/Package/Repositories/ForksTest.php index 3e6a3b69..76433171 100755 --- a/Tests/Package/Repositories/ForksTest.php +++ b/Tests/Package/Repositories/ForksTest.php @@ -45,7 +45,6 @@ protected function setUp() public function testCreate() { $this->response->code = 202; - $this->response->body = $this->sampleString; // Build the request data. $data = json_encode( @@ -97,9 +96,6 @@ public function testCreateFailure() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/forks') diff --git a/Tests/Package/Repositories/HooksTest.php b/Tests/Package/Repositories/HooksTest.php index 6b355a35..08974d72 100644 --- a/Tests/Package/Repositories/HooksTest.php +++ b/Tests/Package/Repositories/HooksTest.php @@ -51,7 +51,6 @@ protected function setUp() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $hook = new \stdClass; $hook->name = 'acunote'; @@ -144,7 +143,6 @@ public function testCreateUnauthorisedEvent() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -208,9 +206,6 @@ public function testDeleteFailure() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $hook = '{' . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' . '"add_events":["watch"],"remove_events":["watch"],"active":true' @@ -343,9 +338,6 @@ public function testEditUnauthorisedRemoveEvent() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/hooks/42') @@ -394,9 +386,6 @@ public function testGetFailure() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/hooks') @@ -446,7 +435,6 @@ public function testGetListFailure() public function testTest() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -497,7 +485,6 @@ public function testTestFailure() public function testPing() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') diff --git a/Tests/Package/Repositories/KeysTest.php b/Tests/Package/Repositories/KeysTest.php index 5b73fdb2..de25ab83 100644 --- a/Tests/Package/Repositories/KeysTest.php +++ b/Tests/Package/Repositories/KeysTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/keys') @@ -64,9 +61,6 @@ public function testGetList() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/keys/1') @@ -86,7 +80,6 @@ public function testGet() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -106,9 +99,6 @@ public function testCreate() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('patch') ->with('/repos/joomla/joomla-platform/keys/1') diff --git a/Tests/Package/Repositories/MergingTest.php b/Tests/Package/Repositories/MergingTest.php index 165f80db..d4c5652a 100644 --- a/Tests/Package/Repositories/MergingTest.php +++ b/Tests/Package/Repositories/MergingTest.php @@ -45,7 +45,6 @@ protected function setUp() public function testPerform() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -68,7 +67,6 @@ public function testPerform() public function testPerformNoOp() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -91,7 +89,6 @@ public function testPerformNoOp() public function testPerformMissing() { $this->response->code = 404; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -114,7 +111,6 @@ public function testPerformMissing() public function testPerformConflict() { $this->response->code = 409; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -137,7 +133,6 @@ public function testPerformConflict() public function testPerformUnexpected() { $this->response->code = 666; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') diff --git a/Tests/Package/Repositories/PagesTest.php b/Tests/Package/Repositories/PagesTest.php index d27f04b9..86af31dd 100644 --- a/Tests/Package/Repositories/PagesTest.php +++ b/Tests/Package/Repositories/PagesTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetInfo() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/pages') @@ -64,9 +61,6 @@ public function testGetInfo() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/pages/builds') @@ -85,9 +79,6 @@ public function testGetList() */ public function testGetLatest() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/{owner}/{repo}/pages/builds/latest') diff --git a/Tests/Package/Repositories/ReleasesTest.php b/Tests/Package/Repositories/ReleasesTest.php index 67533d3f..dc74fe19 100644 --- a/Tests/Package/Repositories/ReleasesTest.php +++ b/Tests/Package/Repositories/ReleasesTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/releases/12345', array(), 0) @@ -66,7 +63,6 @@ public function testGet() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $data = '{"tag_name":"0.1","target_commitish":"targetCommitish","name":"master","body":"New release","draft":false,"prerelease":false}'; $this->client->expects($this->once()) @@ -88,7 +84,6 @@ public function testCreate() public function testCreateFailure() { $this->response->code = 201; - $this->response->body = $this->sampleString; $data = '{"tag_name":"0.1","target_commitish":"targetCommitish","name":"master","body":"New release","draft":false,"prerelease":false}'; $this->client->expects($this->once()) @@ -109,9 +104,6 @@ public function testCreateFailure() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $releaseId = 123; $data = '{"tag_name":"tagName","target_commitish":"targetCommitish","name":"name","body":"body","draft":"draft","prerelease":"preRelease"}'; @@ -163,7 +155,6 @@ public function testGetList() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') @@ -206,9 +197,6 @@ public function testGetLatest() */ public function testGetByTag() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/releases/tags/{tag}', array(), 0) @@ -227,9 +215,6 @@ public function testGetByTag() */ public function testGetListAssets() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/releases/123/assets', array(), 0) @@ -248,9 +233,6 @@ public function testGetListAssets() */ public function testGetAsset() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/releases/assets/123', array(), 0) @@ -269,9 +251,6 @@ public function testGetAsset() */ public function testEditAsset() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $data = '{"name":"{name}","label":"{label}"}'; $this->client->expects($this->once()) diff --git a/Tests/Package/Repositories/StatisticsTest.php b/Tests/Package/Repositories/StatisticsTest.php index 6ede9ffa..70872274 100644 --- a/Tests/Package/Repositories/StatisticsTest.php +++ b/Tests/Package/Repositories/StatisticsTest.php @@ -44,9 +44,6 @@ protected function setUp() */ public function testContributors() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/contributors') @@ -65,9 +62,6 @@ public function testContributors() */ public function testActivity() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/commit_activity') @@ -86,9 +80,6 @@ public function testActivity() */ public function testFrequency() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/code_frequency') @@ -107,9 +98,6 @@ public function testFrequency() */ public function testParticipation() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/participation') @@ -128,9 +116,6 @@ public function testParticipation() */ public function testPunchCard() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-framework/stats/punch_card') @@ -151,7 +136,6 @@ public function testPunchCard() public function testProcessResponse202() { $this->response->code = 202; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('get') diff --git a/Tests/Package/Repositories/StatusesTest.php b/Tests/Package/Repositories/StatusesTest.php index c2993942..eea6a6a5 100755 --- a/Tests/Package/Repositories/StatusesTest.php +++ b/Tests/Package/Repositories/StatusesTest.php @@ -49,7 +49,6 @@ protected function setUp() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; // Build the request data. $data = json_encode( @@ -139,9 +138,6 @@ public function testCreateInvalidState() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') @@ -188,9 +184,6 @@ public function testGetListFailure() */ public function testGetCombinedStatus() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/{user}/{repo}/commits/{sha}/status') diff --git a/Tests/Package/RepositoriesTest.php b/Tests/Package/RepositoriesTest.php index 3b91054f..701bf18b 100644 --- a/Tests/Package/RepositoriesTest.php +++ b/Tests/Package/RepositoriesTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetListOwn() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/user/repos?type=all&sort=full_name&direction=asc', array(), 0) @@ -100,9 +97,6 @@ public function testGetListOwnInvalidSortOrder() */ public function testGetListUser() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/repos?type=all&sort=full_name&direction=asc', array(), 0) @@ -157,9 +151,6 @@ public function testGetListUserInvalidSortOrder() */ public function testGetListOrg() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/orgs/joomla/repos?type=all', array(), 0) @@ -178,9 +169,6 @@ public function testGetListOrg() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repositories', array(), 0) @@ -200,7 +188,6 @@ public function testGetList() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -225,7 +212,6 @@ public function testCreate() public function testCreateWithOrg() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -249,9 +235,6 @@ public function testCreateWithOrg() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-cms', array(), 0) @@ -282,9 +265,6 @@ public function testGetListOrgInvalidType() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('patch') ->with( @@ -308,9 +288,6 @@ public function testEdit() */ public function testGetListContributors() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-cms/contributors', array(), 0) @@ -329,9 +306,6 @@ public function testGetListContributors() */ public function testGetListLanguages() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-cms/languages', array(), 0) @@ -350,9 +324,6 @@ public function testGetListLanguages() */ public function testGetListTeams() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-cms/teams', array(), 0) @@ -371,9 +342,6 @@ public function testGetListTeams() */ public function testGetListTags() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/repos/joomla/joomla-cms/tags', array(), 0) @@ -392,9 +360,6 @@ public function testGetListTags() */ public function testDelete() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('delete') ->with('/repos/joomla/joomla-cms', array(), 0) diff --git a/Tests/Package/SearchTest.php b/Tests/Package/SearchTest.php index 160b5667..56760e42 100644 --- a/Tests/Package/SearchTest.php +++ b/Tests/Package/SearchTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testIssues() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/legacy/issues/search/joomla/joomla-platform/open/github') @@ -66,9 +63,6 @@ public function testIssues() */ public function testIssuesInvalidState() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->object->issues('joomla', 'joomla-platform', 'invalid', 'github'); } @@ -79,9 +73,6 @@ public function testIssuesInvalidState() */ public function testRepositories() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/legacy/repos/search/joomla') @@ -100,9 +91,6 @@ public function testRepositories() */ public function testUsers() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/legacy/user/search/joomla') @@ -121,9 +109,6 @@ public function testUsers() */ public function testEmail() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/legacy/user/email/email@joomla') diff --git a/Tests/Package/Users/EmailsTest.php b/Tests/Package/Users/EmailsTest.php index bb937655..44d05414 100644 --- a/Tests/Package/Users/EmailsTest.php +++ b/Tests/Package/Users/EmailsTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/user/emails') @@ -65,7 +62,6 @@ public function testGetList() public function testAdd() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -86,7 +82,6 @@ public function testAdd() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') diff --git a/Tests/Package/Users/FollowersTest.php b/Tests/Package/Users/FollowersTest.php index b71586dd..a1e65625 100644 --- a/Tests/Package/Users/FollowersTest.php +++ b/Tests/Package/Users/FollowersTest.php @@ -47,9 +47,6 @@ protected function setUp() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/user/followers') @@ -70,9 +67,6 @@ public function testGetList() */ public function testGetListWithUser() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/followers') @@ -93,9 +87,6 @@ public function testGetListWithUser() */ public function testGetListFollowedBy() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/user/following') @@ -116,9 +107,6 @@ public function testGetListFollowedBy() */ public function testGetListFollowedByWithUser() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/following') diff --git a/Tests/Package/Users/KeysTest.php b/Tests/Package/Users/KeysTest.php index 904a6f4b..3aedb1a3 100644 --- a/Tests/Package/Users/KeysTest.php +++ b/Tests/Package/Users/KeysTest.php @@ -43,9 +43,6 @@ protected function setUp() */ public function testGetListUser() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/users/joomla/keys') @@ -64,9 +61,6 @@ public function testGetListUser() */ public function testGetList() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/users/keys') @@ -85,9 +79,6 @@ public function testGetList() */ public function testGet() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('get') ->with('/users/keys/1') @@ -107,7 +98,6 @@ public function testGet() public function testCreate() { $this->response->code = 201; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('post') @@ -127,9 +117,6 @@ public function testCreate() */ public function testEdit() { - $this->response->code = 200; - $this->response->body = $this->sampleString; - $this->client->expects($this->once()) ->method('patch') ->with('/users/keys/1') @@ -149,7 +136,6 @@ public function testEdit() public function testDelete() { $this->response->code = 204; - $this->response->body = $this->sampleString; $this->client->expects($this->once()) ->method('delete') diff --git a/Tests/Stub/GitHubTestCase.php b/Tests/Stub/GitHubTestCase.php index 82fea57b..b7037034 100644 --- a/Tests/Stub/GitHubTestCase.php +++ b/Tests/Stub/GitHubTestCase.php @@ -66,5 +66,9 @@ protected function setUp() $this->response = $this->getMockBuilder('\\Joomla\\Http\\Response') ->getMock(); + + // Set a default response + $this->response->code = 200; + $this->response->body = $this->sampleString; } } From 424df313acfafa4b1580391567b3f1890d86d52f Mon Sep 17 00:00:00 2001 From: elkuku Date: Tue, 9 May 2017 18:07:22 -0500 Subject: [PATCH 25/79] Add missing unit test --- Tests/Package/Repositories/BranchesTest.php | 80 +++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Tests/Package/Repositories/BranchesTest.php diff --git a/Tests/Package/Repositories/BranchesTest.php b/Tests/Package/Repositories/BranchesTest.php new file mode 100644 index 00000000..f3601266 --- /dev/null +++ b/Tests/Package/Repositories/BranchesTest.php @@ -0,0 +1,80 @@ +object = new Branches($this->options, $this->client); + } + + /** + * Tests the GetList method. + * + * @covers \Joomla\Github\Package\Repositories\Branches::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/branches') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('{owner}', '{repo}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @covers \Joomla\Github\Package\Repositories\Branches::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/branches/{branch}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('{owner}', '{repo}', '{branch}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } +} From 41737b619898332cdc74903e7421061f3e94b8a0 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 6 Aug 2017 17:02:59 -0500 Subject: [PATCH 26/79] Test fixes --- Tests/Package/Activity/NotificationsTest.php | 4 ++-- Tests/Package/IssuesTest.php | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Tests/Package/Activity/NotificationsTest.php b/Tests/Package/Activity/NotificationsTest.php index bf2e54f1..5b8b29f1 100644 --- a/Tests/Package/Activity/NotificationsTest.php +++ b/Tests/Package/Activity/NotificationsTest.php @@ -54,7 +54,7 @@ public function testGetList() ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->getList(true, true, new \DateTime('2005-8-17'), new \DateTime('2005-8-17')), + $this->object->getList(true, true, new \DateTime('2005-8-17', new \DateTimeZone('UTC')), new \DateTime('2005-8-17', new \DateTimeZone('UTC'))), $this->equalTo(json_decode($this->response->body)) ); } @@ -76,7 +76,7 @@ public function testGetListRepository() ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->getListRepository('{owner}', '{repo}', true, true, new \DateTime('2005-8-17'), new \DateTime('2005-8-17')), + $this->object->getListRepository('{owner}', '{repo}', true, true, new \DateTime('2005-8-17', new \DateTimeZone('UTC')), new \DateTime('2005-8-17', new \DateTimeZone('UTC'))), $this->equalTo(json_decode($this->response->body)) ); } diff --git a/Tests/Package/IssuesTest.php b/Tests/Package/IssuesTest.php index 20d498e3..49999d12 100755 --- a/Tests/Package/IssuesTest.php +++ b/Tests/Package/IssuesTest.php @@ -52,11 +52,10 @@ public function testCreate() $issue = new \stdClass; $issue->title = '{title}'; - $issue->assignee = 'JoeUser'; - $issue->milestone = '11.5'; - $issue->labels = ['TestLabel']; + $issue->milestone = '{milestone}'; + $issue->labels = ['{label1}']; $issue->body = '{body}'; - $issue->assignees = ['joomla']; + $issue->assignee = '{assignee}'; $this->client->expects($this->once()) ->method('post') @@ -117,16 +116,16 @@ public function testCreateFailure() $issue = new \stdClass; $issue->title = '{title}'; $issue->milestone = '{milestone}'; - $issue->labels = array(); + $issue->labels = array('{label1}'); $issue->body = '{body}'; - $issue->assignees = array('joomla'); + $issue->assignee = '{assignee}'; $this->client->expects($this->once()) ->method('post') ->with('/repos/{user}/{repo}/issues', json_encode($issue)) ->will($this->returnValue($this->response)); - $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee]', '{milestone}', array('{label1}'), array('{assignee1]')); + $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', array('{label1}')); } /** From 8c99081dc9110693e7f9dbed2638f7c797de79d6 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 6 Aug 2017 17:06:53 -0500 Subject: [PATCH 27/79] PHPCS --- Tests/Package/Activity/NotificationsTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Tests/Package/Activity/NotificationsTest.php b/Tests/Package/Activity/NotificationsTest.php index 5b8b29f1..b115a1e4 100644 --- a/Tests/Package/Activity/NotificationsTest.php +++ b/Tests/Package/Activity/NotificationsTest.php @@ -76,7 +76,14 @@ public function testGetListRepository() ->will($this->returnValue($this->response)); $this->assertThat( - $this->object->getListRepository('{owner}', '{repo}', true, true, new \DateTime('2005-8-17', new \DateTimeZone('UTC')), new \DateTime('2005-8-17', new \DateTimeZone('UTC'))), + $this->object->getListRepository( + '{owner}', + '{repo}', + true, + true, + new \DateTime('2005-8-17', new \DateTimeZone('UTC')), + new \DateTime('2005-8-17', new \DateTimeZone('UTC')) + ), $this->equalTo(json_decode($this->response->body)) ); } From dcc2a1afd97e57935db1394357714211fc6e411b Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Mon, 14 Aug 2017 20:21:02 -0500 Subject: [PATCH 28/79] Bump to PHP 7 minimum --- .travis.yml | 11 +++++------ composer.json | 4 ++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index e976abf7..8fa06e3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,16 +10,15 @@ env: matrix: fast_finish: true include: - - php: 5.5 - - php: 5.5 - env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" - - php: 5.6 - env: RUN_PHPCS="yes" - php: 7.0 - php: 7.0 + env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" + - php: 7.0 + env: RUN_PHPCS="yes" + - php: 7.1 + - php: 7.1 # This empty flag removes the prefer-stable switch to cause dev dependencies to be installed env: COMPOSER_FLAGS="" - - php: 7.1 - php: 7.2 - php: nightly allow_failures: diff --git a/composer.json b/composer.json index c0b13a43..f5644879 100644 --- a/composer.json +++ b/composer.json @@ -6,13 +6,13 @@ "homepage": "https://github.com/joomla-framework/github-api", "license": "GPL-2.0+", "require": { - "php": "^5.5.9|~7.0", + "php": "~7.0", "joomla/http": "^1.2.2|~2.0", "joomla/registry": "^1.4.5|~2.0", "joomla/uri": "~1.0|~2.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35|^5.4.3|~6.0", + "phpunit/phpunit": "~6.0", "squizlabs/php_codesniffer": "1.*" }, "autoload": { From b1629bb31cc89cc2afd7b7be25f7dc3759c6e715 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Tue, 15 Aug 2017 19:41:52 -0500 Subject: [PATCH 29/79] Raise PHPUnit minimum to current minor version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f5644879..6857f45a 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "joomla/uri": "~1.0|~2.0" }, "require-dev": { - "phpunit/phpunit": "~6.0", + "phpunit/phpunit": "~6.3", "squizlabs/php_codesniffer": "1.*" }, "autoload": { From 42c9a4b303afd9e6c66a6550bd29bb32a492d09d Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 10 Feb 2018 13:38:03 -0600 Subject: [PATCH 30/79] Revert "Shouldn't allow short array here" This reverts commit 8ff848c627163c0d3b00947eb24035a6cbb9de8b. --- ruleset.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ruleset.xml b/ruleset.xml index c121af93..07be5d2b 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -15,7 +15,14 @@ */vendor/* + + + + + + + From ddc13edb9c84fbd97025d195b656622aabae5225 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Wed, 7 Mar 2018 20:17:03 -0600 Subject: [PATCH 31/79] Check for empty array --- src/Package/Issues.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package/Issues.php b/src/Package/Issues.php index b299c038..bdc5960b 100644 --- a/src/Package/Issues.php +++ b/src/Package/Issues.php @@ -140,7 +140,7 @@ public function edit($user, $repo, $issueId, $state = null, $title = null, $body } // If labels are set add them to the data object. - if (isset($labels)) + if (!empty($labels)) { // Ensure that we have a non-associative array. if (isset($labels)) From fe542c6d20295b1f5452bc002928261b611670e5 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 24 Mar 2018 11:15:09 -0500 Subject: [PATCH 32/79] Return Uri --- src/AbstractGithubObject.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index b5405fa7..ad56d22c 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -100,7 +100,6 @@ public function __construct(Registry $options = null, Http $client = null) * @return string The request URL. * * @since 1.0 - * @note As of 2.0 this method will return a Joomla\Uri\Uri object */ protected function fetchUrl($path, $page = 0, $limit = 0) { @@ -138,7 +137,7 @@ protected function fetchUrl($path, $page = 0, $limit = 0) $uri->setVar('per_page', (int) $limit); } - return (string) $uri; + return $uri; } /** From 58eabda22a495af95e0a3b7a84269e1bfd9570ee Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 24 Mar 2018 11:20:23 -0500 Subject: [PATCH 33/79] Don't need to create a new Uri for Uri returns --- src/AbstractGithubObject.php | 2 +- src/Package/Activity/Notifications.php | 5 ++--- src/Package/Activity/Starring.php | 3 +-- src/Package/Gists.php | 7 +++---- src/Package/Issues.php | 5 ++--- src/Package/Issues/Comments.php | 5 ++--- src/Package/Issues/Milestones.php | 3 +-- src/Package/Repositories.php | 11 +++++------ src/Package/Repositories/Commits.php | 3 +-- src/Package/Repositories/Contents.php | 7 +++---- src/Package/Repositories/Deployments.php | 3 +-- src/Package/Search.php | 5 ++--- src/Package/Users.php | 3 +-- 13 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index ad56d22c..79517a1e 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -97,7 +97,7 @@ public function __construct(Registry $options = null, Http $client = null) * @param integer $page Page to request * @param integer $limit Number of results to return per page * - * @return string The request URL. + * @return Uri * * @since 1.0 */ diff --git a/src/Package/Activity/Notifications.php b/src/Package/Activity/Notifications.php index f87d2a01..39616ef1 100644 --- a/src/Package/Activity/Notifications.php +++ b/src/Package/Activity/Notifications.php @@ -9,7 +9,6 @@ namespace Joomla\Github\Package\Activity; use Joomla\Github\AbstractPackage; -use Joomla\Uri\Uri; /** * GitHub API Activity Events class for the Joomla Framework. @@ -39,7 +38,7 @@ public function getList($all = true, $participating = true, \DateTimeInterface $ // Build the request path. $path = '/notifications'; - $uri = new Uri($this->fetchUrl($path)); + $uri = $this->fetchUrl($path); if ($all) { @@ -87,7 +86,7 @@ public function getListRepository($owner, $repo, $all = true, $participating = t // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/notifications'; - $uri = new Uri($this->fetchUrl($path)); + $uri = $this->fetchUrl($path); if ($all) { diff --git a/src/Package/Activity/Starring.php b/src/Package/Activity/Starring.php index b5697fe3..4f25b8fb 100644 --- a/src/Package/Activity/Starring.php +++ b/src/Package/Activity/Starring.php @@ -9,7 +9,6 @@ namespace Joomla\Github\Package\Activity; use Joomla\Github\AbstractPackage; -use Joomla\Uri\Uri; /** * GitHub API Activity Events class for the Joomla Framework. @@ -84,7 +83,7 @@ public function getRepositories($user = '', $sort = 'created', $direction = 'des ? '/users/' . $user . '/starred' : '/user/starred'; - $uri = new Uri($this->fetchUrl($path)); + $uri = $this->fetchUrl($path); $uri->setVar('sort', $sort); $uri->setVar('direction', $direction); diff --git a/src/Package/Gists.php b/src/Package/Gists.php index 33a15f66..48cf6cea 100644 --- a/src/Package/Gists.php +++ b/src/Package/Gists.php @@ -10,7 +10,6 @@ use Joomla\Github\AbstractPackage; use Joomla\Http\Exception\UnexpectedResponseException; -use Joomla\Uri\Uri; /** * GitHub API Gists class for the Joomla Framework. @@ -237,7 +236,7 @@ public function getList($page = 0, $limit = 0) public function getListByUser($user, $page = 0, $limit = 0, \DateTime $since = null) { // Build the request path. - $uri = new Uri($this->fetchUrl('/users/' . $user . '/gists', $page, $limit)); + $uri = $this->fetchUrl('/users/' . $user . '/gists', $page, $limit); if ($since) { @@ -263,7 +262,7 @@ public function getListByUser($user, $page = 0, $limit = 0, \DateTime $since = n public function getListPublic($page = 0, $limit = 0, \DateTime $since = null) { // Build the request path. - $uri = new Uri($this->fetchUrl('/gists/public', $page, $limit)); + $uri = $this->fetchUrl('/gists/public', $page, $limit); if ($since) { @@ -289,7 +288,7 @@ public function getListPublic($page = 0, $limit = 0, \DateTime $since = null) public function getListStarred($page = 0, $limit = 0, \DateTime $since = null) { // Build the request path. - $uri = new Uri($this->fetchUrl('/gists/starred', $page, $limit)); + $uri = $this->fetchUrl('/gists/starred', $page, $limit); if ($since) { diff --git a/src/Package/Issues.php b/src/Package/Issues.php index c29a9482..01930e21 100644 --- a/src/Package/Issues.php +++ b/src/Package/Issues.php @@ -9,7 +9,6 @@ namespace Joomla\Github\Package; use Joomla\Github\AbstractPackage; -use Joomla\Uri\Uri; /** * GitHub API Issues class for the Joomla Framework. @@ -201,7 +200,7 @@ public function getList($filter = null, $state = null, $labels = null, $sort = n ) { // Build the request path. - $uri = new Uri($this->fetchUrl('/issues', $page, $limit)); + $uri = $this->fetchUrl('/issues', $page, $limit); if ($filter) { @@ -265,7 +264,7 @@ public function getListByRepository($user, $repo, $milestone = null, $state = nu // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/issues'; - $uri = new Uri($this->fetchUrl($path, $page, $limit)); + $uri = $this->fetchUrl($path, $page, $limit); if ($milestone) { diff --git a/src/Package/Issues/Comments.php b/src/Package/Issues/Comments.php index b70350dc..70e0c54b 100644 --- a/src/Package/Issues/Comments.php +++ b/src/Package/Issues/Comments.php @@ -9,7 +9,6 @@ namespace Joomla\Github\Package\Issues; use Joomla\Github\AbstractPackage; -use Joomla\Uri\Uri; /** * GitHub API Comments class for the Joomla Framework. @@ -43,7 +42,7 @@ public function getList($owner, $repo, $issueId, $page = 0, $limit = 0, \DateTim // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; - $uri = new Uri($this->fetchUrl($path, $page, $limit)); + $uri = $this->fetchUrl($path, $page, $limit); if ($since) { @@ -92,7 +91,7 @@ public function getRepositoryList($owner, $repo, $sort = 'created', $direction = ); } - $uri = new Uri($this->fetchUrl($path)); + $uri = $this->fetchUrl($path); $uri->setVar('sort', $sort); $uri->setVar('direction', $direction); diff --git a/src/Package/Issues/Milestones.php b/src/Package/Issues/Milestones.php index 7aac25df..8ac13def 100644 --- a/src/Package/Issues/Milestones.php +++ b/src/Package/Issues/Milestones.php @@ -9,7 +9,6 @@ namespace Joomla\Github\Package\Issues; use Joomla\Github\AbstractPackage; -use Joomla\Uri\Uri; /** * GitHub API Milestones class for the Joomla Framework. @@ -41,7 +40,7 @@ public function getList($user, $repo, $state = 'open', $sort = 'due_date', $dire // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/milestones'; - $uri = new Uri($this->fetchUrl($path, $page, $limit)); + $uri = $this->fetchUrl($path, $page, $limit); $uri->setVar('state', $state); $uri->setVar('sort', $sort); $uri->setVar('direction', $direction); diff --git a/src/Package/Repositories.php b/src/Package/Repositories.php index 6586418c..fd575ffd 100644 --- a/src/Package/Repositories.php +++ b/src/Package/Repositories.php @@ -9,7 +9,6 @@ namespace Joomla\Github\Package; use Joomla\Github\AbstractPackage; -use Joomla\Uri\Uri; /** * GitHub API Activity class for the Joomla Framework. @@ -71,7 +70,7 @@ public function getListOwn($type = 'all', $sort = 'full_name', $direction = '') } // Build the request path. - $uri = new Uri($this->fetchUrl('/user/repos')); + $uri = $this->fetchUrl('/user/repos'); $uri->setVar('type', $type); $uri->setVar('sort', $sort); $uri->setVar('direction', $direction); @@ -116,7 +115,7 @@ public function getListUser($user, $type = 'all', $sort = 'full_name', $directio } // Build the request path. - $uri = new Uri($this->fetchUrl('/users/' . $user . '/repos')); + $uri = $this->fetchUrl('/users/' . $user . '/repos'); $uri->setVar('type', $type); $uri->setVar('sort', $sort); $uri->setVar('direction', $direction); @@ -146,7 +145,7 @@ public function getListOrg($org, $type = 'all') } // Build the request path. - $uri = new Uri($this->fetchUrl('/orgs/' . $org . '/repos')); + $uri = $this->fetchUrl('/orgs/' . $org . '/repos'); $uri->setVar('type', $type); // Send the request. @@ -168,7 +167,7 @@ public function getListOrg($org, $type = 'all') public function getList($id = 0) { // Build the request path. - $uri = new Uri($this->fetchUrl('/repositories')); + $uri = $this->fetchUrl('/repositories'); if ($id) { @@ -311,7 +310,7 @@ public function edit($owner, $repo, $name, $description = '', $homepage = '', $p public function getListContributors($owner, $repo, $anon = false) { // Build the request path. - $uri = new Uri($this->fetchUrl('/repos/' . $owner . '/' . $repo . '/contributors')); + $uri = $this->fetchUrl('/repos/' . $owner . '/' . $repo . '/contributors'); if ($anon) { diff --git a/src/Package/Repositories/Commits.php b/src/Package/Repositories/Commits.php index 65461e37..843cc60e 100644 --- a/src/Package/Repositories/Commits.php +++ b/src/Package/Repositories/Commits.php @@ -10,7 +10,6 @@ use Joomla\Github\AbstractPackage; use Joomla\Http\Exception\UnexpectedResponseException; -use Joomla\Uri\Uri; /** * GitHub API Repositories Commits class for the Joomla Framework. @@ -47,7 +46,7 @@ public function getList($user, $repo, $sha = '', $path = '', $author = '', \Date // Build the request path. $rPath = '/repos/' . $user . '/' . $repo . '/commits'; - $uri = new Uri($this->fetchUrl($rPath)); + $uri = $this->fetchUrl($rPath); if ($sha) { diff --git a/src/Package/Repositories/Contents.php b/src/Package/Repositories/Contents.php index b7e65ce8..7d499be1 100644 --- a/src/Package/Repositories/Contents.php +++ b/src/Package/Repositories/Contents.php @@ -9,7 +9,6 @@ namespace Joomla\Github\Package\Repositories; use Joomla\Github\AbstractPackage; -use Joomla\Uri\Uri; /** * GitHub API Repositories Contents class for the Joomla Framework. @@ -41,7 +40,7 @@ public function getReadme($owner, $repo, $ref = '') // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/readme'; - $uri = new Uri($this->fetchUrl($path)); + $uri = $this->fetchUrl($path); if ($ref) { @@ -71,7 +70,7 @@ public function get($owner, $repo, $path, $ref = '') // Build the request path. $rPath = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; - $uri = new Uri($this->fetchUrl($rPath)); + $uri = $this->fetchUrl($rPath); if ($ref) { @@ -113,7 +112,7 @@ public function getArchiveLink($owner, $repo, $archiveFormat = 'zipball', $ref = // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/' . $archiveFormat; - $uri = new Uri($this->fetchUrl($path)); + $uri = $this->fetchUrl($path); if ($ref) { diff --git a/src/Package/Repositories/Deployments.php b/src/Package/Repositories/Deployments.php index 2b7b7ef7..cd501528 100644 --- a/src/Package/Repositories/Deployments.php +++ b/src/Package/Repositories/Deployments.php @@ -9,7 +9,6 @@ namespace Joomla\Github\Package\Repositories; use Joomla\Github\AbstractPackage; -use Joomla\Uri\Uri; /** * GitHub API Deployments class for the Joomla Framework. @@ -41,7 +40,7 @@ public function getList($owner, $repo, $sha = '', $ref = '', $task = '', $enviro // Build the request path. $path = "/repos/$owner/$repo/deployments"; - $uri = new Uri($this->fetchUrl($path, $page, $limit)); + $uri = $this->fetchUrl($path, $page, $limit); if ($sha) { diff --git a/src/Package/Search.php b/src/Package/Search.php index d54c9d20..7181cc04 100644 --- a/src/Package/Search.php +++ b/src/Package/Search.php @@ -9,7 +9,6 @@ namespace Joomla\Github\Package; use Joomla\Github\AbstractPackage; -use Joomla\Uri\Uri; /** * GitHub API Search class for the Joomla Framework. @@ -70,7 +69,7 @@ public function issues($owner, $repo, $state, $keyword) public function repositories($keyword, $language = '', $startPage = 0) { // Build the request path. - $uri = new Uri($this->fetchUrl('/legacy/repos/search/' . $keyword)); + $uri = $this->fetchUrl('/legacy/repos/search/' . $keyword); if ($language) { @@ -102,7 +101,7 @@ public function repositories($keyword, $language = '', $startPage = 0) public function users($keyword, $startPage = 0) { // Build the request path. - $uri = new Uri($this->fetchUrl('/legacy/user/search/' . $keyword)); + $uri = $this->fetchUrl('/legacy/user/search/' . $keyword); if ($startPage) { diff --git a/src/Package/Users.php b/src/Package/Users.php index 0c72271e..276466de 100644 --- a/src/Package/Users.php +++ b/src/Package/Users.php @@ -9,7 +9,6 @@ namespace Joomla\Github\Package; use Joomla\Github\AbstractPackage; -use Joomla\Uri\Uri; /** * GitHub API References class for the Joomla Framework. @@ -116,7 +115,7 @@ public function edit($name = '', $email = '', $blog = '', $company = '', $locati public function getList($since = 0) { // Build the request path. - $uri = new Uri($this->fetchUrl('/users')); + $uri = $this->fetchUrl('/users'); if ($since) { From 08774e2bd4dbe3a55c7aa7b1b8da9813e628bcce Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 31 Mar 2018 15:03:27 -0500 Subject: [PATCH 34/79] Remove deprecated Http subclass --- Tests/HttpTest.php | 68 ---------------------------------- Tests/Stub/GitHubTestCase.php | 2 +- src/AbstractGithubObject.php | 9 +++-- src/AbstractPackage.php | 6 +-- src/Github.php | 9 +++-- src/Http.php | 69 ----------------------------------- 6 files changed, 14 insertions(+), 149 deletions(-) delete mode 100755 Tests/HttpTest.php delete mode 100644 src/Http.php diff --git a/Tests/HttpTest.php b/Tests/HttpTest.php deleted file mode 100755 index 4095a869..00000000 --- a/Tests/HttpTest.php +++ /dev/null @@ -1,68 +0,0 @@ -transport = $this->getMockBuilder('Joomla\\Http\\TransportInterface') - ->setConstructorArgs(array($this->options)) - ->getMock(); - - $this->object = new Http($this->options, $this->transport); - } - - /** - * Tests the __construct method - * - * @return void - * - * @since 1.0 - */ - public function testConstruct() - { - // Verify the options are set in the object - $this->assertThat( - $this->object->getOption('userAgent'), - $this->equalTo('JGitHub/2.0') - ); - - $this->assertThat( - $this->object->getOption('timeout'), - $this->equalTo(120) - ); - } -} diff --git a/Tests/Stub/GitHubTestCase.php b/Tests/Stub/GitHubTestCase.php index ae86ea57..fdc00ca5 100644 --- a/Tests/Stub/GitHubTestCase.php +++ b/Tests/Stub/GitHubTestCase.php @@ -60,7 +60,7 @@ protected function setUp() $this->options = new Registry; - $this->client = $this->getMockBuilder('\\Joomla\\Github\\Http') + $this->client = $this->getMockBuilder('\\Joomla\\Http\\Http') ->setMethods(array('get', 'post', 'delete', 'patch', 'put')) ->getMock(); diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index ce2da793..18477121 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -9,7 +9,8 @@ namespace Joomla\Github; use Joomla\Http\Exception\UnexpectedResponseException; -use Joomla\Http\Http as BaseHttp; +use Joomla\Http\Http; +use Joomla\Http\HttpFactory; use Joomla\Http\Response; use Joomla\Uri\Uri; use Joomla\Registry\Registry; @@ -76,14 +77,14 @@ abstract class AbstractGithubObject * Constructor. * * @param Registry $options GitHub options object. - * @param BaseHttp $client The HTTP client object. + * @param Http $client The HTTP client object. * * @since 1.0 */ - public function __construct(Registry $options = null, BaseHttp $client = null) + public function __construct(Registry $options = null, Http $client = null) { $this->options = $options ?: new Registry; - $this->client = $client ?: new Http($this->options); + $this->client = $client ?: (new HttpFactory)->getHttp($this->options); $this->package = get_class($this); $this->package = substr($this->package, strrpos($this->package, '\\') + 1); diff --git a/src/AbstractPackage.php b/src/AbstractPackage.php index 816f4e99..2ccc3c1d 100644 --- a/src/AbstractPackage.php +++ b/src/AbstractPackage.php @@ -8,7 +8,7 @@ namespace Joomla\Github; -use Joomla\Http\Http as BaseHttp; +use Joomla\Http\Http; use Joomla\Registry\Registry; /** @@ -22,11 +22,11 @@ abstract class AbstractPackage extends AbstractGithubObject * Constructor. * * @param Registry $options GitHub options object. - * @param BaseHttp $client The HTTP client object. + * @param Http $client The HTTP client object. * * @since 1.0 */ - public function __construct(Registry $options = null, BaseHttp $client = null) + public function __construct(Registry $options = null, Http $client = null) { parent::__construct($options, $client); diff --git a/src/Github.php b/src/Github.php index b3edb6ee..9525b27c 100644 --- a/src/Github.php +++ b/src/Github.php @@ -8,7 +8,8 @@ namespace Joomla\Github; -use Joomla\Http\Http as BaseHttp; +use Joomla\Http\Http; +use Joomla\Http\HttpFactory; use Joomla\Registry\Registry; /** @@ -51,11 +52,11 @@ class Github * Constructor. * * @param Registry $options GitHub options object. - * @param BaseHttp $client The HTTP client object. + * @param Http $client The HTTP client object. * * @since 1.0 */ - public function __construct(Registry $options = null, BaseHttp $client = null) + public function __construct(Registry $options = null, Http $client = null) { $this->options = $options ?: new Registry; @@ -71,7 +72,7 @@ public function __construct(Registry $options = null, BaseHttp $client = null) $this->setOption('api.url', 'https://api.github.com'); } - $this->client = $client ?: new Http($this->options); + $this->client = $client ?: (new HttpFactory)->getHttp($this->options); } /** diff --git a/src/Http.php b/src/Http.php deleted file mode 100644 index 6dddd0ed..00000000 --- a/src/Http.php +++ /dev/null @@ -1,69 +0,0 @@ -options['userAgent'])) - { - $this->options['userAgent'] = 'JGitHub/2.0'; - } - - // Set the default timeout to 120 seconds. - if (!isset($this->options['timeout'])) - { - $this->options['timeout'] = 120; - } - } -} From 096904f494dc44671ae2221cd603bcd68765d28b Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Tue, 2 Oct 2018 20:21:32 -0500 Subject: [PATCH 35/79] PHPCS tweaks via PHP-CS-Fixer --- src/AbstractGithubObject.php | 4 +-- src/Package/Activity/Notifications.php | 16 ++++----- src/Package/Activity/Starring.php | 4 +-- src/Package/Activity/Watching.php | 4 +-- src/Package/Authorization.php | 18 +++++----- src/Package/Data/Blobs.php | 4 +-- src/Package/Data/Commits.php | 4 +-- src/Package/Data/Refs.php | 4 +-- src/Package/Data/Tags.php | 8 ++--- src/Package/Data/Trees.php | 2 +- src/Package/Gists.php | 10 +++--- src/Package/Gists/Comments.php | 8 ++--- src/Package/Gitignore.php | 2 +- src/Package/Graphql.php | 10 +++--- src/Package/Issues.php | 32 ++++++++--------- src/Package/Issues/Assignees.php | 10 +++--- src/Package/Issues/Comments.php | 12 +++---- src/Package/Issues/Labels.php | 8 ++--- src/Package/Issues/Milestones.php | 6 ++-- src/Package/Markdown.php | 2 +- src/Package/Orgs.php | 4 +-- src/Package/Orgs/Hooks.php | 24 ++++++------- src/Package/Orgs/Members.php | 8 ++--- src/Package/Orgs/Teams.php | 20 +++++------ src/Package/Pulls.php | 12 +++---- src/Package/Pulls/Comments.php | 12 +++---- src/Package/Repositories.php | 22 ++++++------ src/Package/Repositories/Comments.php | 8 ++--- src/Package/Repositories/Contents.php | 44 +++++++++++++----------- src/Package/Repositories/Deployments.php | 10 +++--- src/Package/Repositories/Forks.php | 4 +-- src/Package/Repositories/Hooks.php | 12 +++---- src/Package/Repositories/Keys.php | 8 ++--- src/Package/Repositories/Releases.php | 10 +++--- src/Package/Repositories/Statuses.php | 6 ++-- src/Package/Search.php | 2 +- src/Package/Users.php | 4 +-- src/Package/Users/Keys.php | 8 ++--- 38 files changed, 193 insertions(+), 193 deletions(-) diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index 278a0089..6d0a8510 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -48,7 +48,7 @@ abstract class AbstractGithubObject * @link https://developer.github.com/webhooks/#events * @note From 1.4.0 to 1.5.1 this was named $events, it was renamed due to naming conflicts with package subclasses */ - protected $hookEvents = array( + protected $hookEvents = [ '*', 'commit_comment', 'create', @@ -71,7 +71,7 @@ abstract class AbstractGithubObject 'status', 'team_add', 'watch', - ); + ]; /** * Constructor. diff --git a/src/Package/Activity/Notifications.php b/src/Package/Activity/Notifications.php index c2ac6b40..6b8ed0f4 100644 --- a/src/Package/Activity/Notifications.php +++ b/src/Package/Activity/Notifications.php @@ -130,10 +130,10 @@ public function markRead($unread = true, $read = true, \DateTimeInterface $lastR // Build the request path. $path = '/notifications'; - $data = array( + $data = [ 'unread' => $unread, 'read' => $read, - ); + ]; if ($lastReadAt) { @@ -167,10 +167,10 @@ public function markReadRepository($owner, $repo, $unread, $read, \DateTimeInter // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/notifications'; - $data = array( + $data = [ 'unread' => $unread, 'read' => $read, - ); + ]; if ($lastReadAt) { @@ -218,10 +218,10 @@ public function markReadThread($id, $unread = true, $read = true) // Build the request path. $path = '/notifications/threads/' . $id; - $data = array( + $data = [ 'unread' => $unread, 'read' => $read, - ); + ]; return $this->processResponse( $this->client->patch($this->fetchUrl($path), json_encode($data)), @@ -271,10 +271,10 @@ public function setThreadSubscription($id, $subscribed, $ignored) // Build the request path. $path = '/notifications/threads/' . $id . '/subscription'; - $data = array( + $data = [ 'subscribed' => $subscribed, 'ignored' => $ignored, - ); + ]; return $this->processResponse( $this->client->put($this->fetchUrl($path), json_encode($data)) diff --git a/src/Package/Activity/Starring.php b/src/Package/Activity/Starring.php index 926c229a..a0a7743c 100644 --- a/src/Package/Activity/Starring.php +++ b/src/Package/Activity/Starring.php @@ -55,8 +55,8 @@ public function getList($owner, $repo) */ public function getRepositories($user = '', $sort = 'created', $direction = 'desc') { - $allowedSort = array('created', 'updated'); - $allowedDir = array('asc', 'desc'); + $allowedSort = ['created', 'updated']; + $allowedDir = ['asc', 'desc']; if (!\in_array($sort, $allowedSort)) { diff --git a/src/Package/Activity/Watching.php b/src/Package/Activity/Watching.php index aa69fc03..d21e5e3d 100644 --- a/src/Package/Activity/Watching.php +++ b/src/Package/Activity/Watching.php @@ -99,10 +99,10 @@ public function setSubscription($owner, $repo, $subscribed, $ignored) // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/subscription'; - $data = array( + $data = [ 'subscribed' => $subscribed, 'ignored' => $ignored, - ); + ]; return $this->processResponse( $this->client->put($this->fetchUrl($path), json_encode($data)) diff --git a/src/Package/Authorization.php b/src/Package/Authorization.php index 85182151..8742fd26 100644 --- a/src/Package/Authorization.php +++ b/src/Package/Authorization.php @@ -35,13 +35,13 @@ class Authorization extends AbstractPackage * @since 1.0 * @throws \DomainException */ - public function create(array $scopes = array(), $note = '', $url = '') + public function create(array $scopes = [], $note = '', $url = '') { // Build the request path. $path = '/authorizations'; $data = json_encode( - array('scopes' => $scopes, 'note' => $note, 'note_url' => $url) + ['scopes' => $scopes, 'note' => $note, 'note_url' => $url] ); // Send the request. @@ -104,7 +104,7 @@ public function deleteGrant($id) * @throws \DomainException * @throws \RuntimeException */ - public function edit($id, array $scopes = array(), array $addScopes = array(), array $removeScopes = array(), $note = '', $url = '') + public function edit($id, array $scopes = [], array $addScopes = [], array $removeScopes = [], $note = '', $url = '') { // Check if more than one scopes array contains data $scopesCount = 0; @@ -142,11 +142,11 @@ public function edit($id, array $scopes = array(), array $addScopes = array(), a $path = '/authorizations/' . $id; $data = json_encode( - array( + [ $scope => $scopeData, 'note' => $note, 'note_url' => $url, - ) + ] ); // Send the request. @@ -250,7 +250,7 @@ public function getRateLimit() if ($response->code == 404) { // Unlimited rate for Github Enterprise sites and trusted users. - return (object) array('limit' => false, 'remaining' => null); + return (object) ['limit' => false, 'remaining' => null]; } // Decode the error response and throw an exception. @@ -316,18 +316,18 @@ public function requestToken($clientId, $clientSecret, $code, $redirectUri = '', { $uri = 'https://github.com/login/oauth/access_token'; - $data = array( + $data = [ 'client_id' => $clientId, 'client_secret' => $clientSecret, 'code' => $code, - ); + ]; if ($redirectUri) { $data['redirect_uri'] = $redirectUri; } - $headers = array(); + $headers = []; switch ($format) { diff --git a/src/Package/Data/Blobs.php b/src/Package/Data/Blobs.php index fabb712a..ba81fab2 100644 --- a/src/Package/Data/Blobs.php +++ b/src/Package/Data/Blobs.php @@ -61,10 +61,10 @@ public function create($owner, $repo, $content, $encoding = 'utf-8') // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/git/blobs'; - $data = array( + $data = [ 'content' => $content, 'encoding' => $encoding, - ); + ]; return $this->processResponse( $this->client->post($this->fetchUrl($path), json_encode($data)), diff --git a/src/Package/Data/Commits.php b/src/Package/Data/Commits.php index 48b933f8..6f70bd89 100644 --- a/src/Package/Data/Commits.php +++ b/src/Package/Data/Commits.php @@ -54,13 +54,13 @@ public function get($owner, $repo, $sha) * * @return object */ - public function create($owner, $repo, $message, $tree, array $parents = array()) + public function create($owner, $repo, $message, $tree, array $parents = []) { // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/git/commits'; $data = json_encode( - array('message' => $message, 'tree' => $tree, 'parents' => $parents) + ['message' => $message, 'tree' => $tree, 'parents' => $parents] ); // Send the request. diff --git a/src/Package/Data/Refs.php b/src/Package/Data/Refs.php index b7182a78..21e5021f 100644 --- a/src/Package/Data/Refs.php +++ b/src/Package/Data/Refs.php @@ -88,10 +88,10 @@ public function create($user, $repo, $ref, $sha) // Build the request data. $data = json_encode( - array( + [ 'ref' => $ref, 'sha' => $sha, - ) + ] ); // Send the request. diff --git a/src/Package/Data/Tags.php b/src/Package/Data/Tags.php index 4f93c03f..66e2fd7b 100644 --- a/src/Package/Data/Tags.php +++ b/src/Package/Data/Tags.php @@ -69,17 +69,17 @@ public function create($owner, $repo, $tag, $message, $object, $type, $taggerNam // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/git/tags'; - $data = array( + $data = [ 'tag' => $tag, 'message' => $message, 'object' => $object, 'type' => $type, - 'tagger' => array( + 'tagger' => [ 'name' => $taggerName, 'email' => $taggerEmail, 'date' => $taggerDate, - ), - ); + ], + ]; return $this->processResponse( $this->client->post($this->fetchUrl($path), json_encode($data)), diff --git a/src/Package/Data/Trees.php b/src/Package/Data/Trees.php index f740c0b0..3a62abe8 100644 --- a/src/Package/Data/Trees.php +++ b/src/Package/Data/Trees.php @@ -98,7 +98,7 @@ public function create($owner, $repo, $tree, $baseTree = '') // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/git/trees'; - $data = array(); + $data = []; $data['tree'] = $tree; diff --git a/src/Package/Gists.php b/src/Package/Gists.php index 32635435..67109c97 100644 --- a/src/Package/Gists.php +++ b/src/Package/Gists.php @@ -41,11 +41,11 @@ public function create($files, $public = false, $description = null) // Build the request data. $data = json_encode( - array( + [ 'files' => $this->buildFileData((array) $files), 'public' => (bool) $public, 'description' => $description, - ) + ] ); // Send the request. @@ -406,14 +406,14 @@ public function unstar($gistId) */ protected function buildFileData(array $files) { - $data = array(); + $data = []; foreach ($files as $key => $file) { if (!is_numeric($key)) { // If the key isn't numeric, then we are dealing with a file whose content has been supplied - $data[$key] = array('content' => $file); + $data[$key] = ['content' => $file]; } elseif (!file_exists($file)) { @@ -423,7 +423,7 @@ protected function buildFileData(array $files) } else { - $data[basename($file)] = array('content' => file_get_contents($file)); + $data[basename($file)] = ['content' => file_get_contents($file)]; } } diff --git a/src/Package/Gists/Comments.php b/src/Package/Gists/Comments.php index 749f5b6f..14ae01ef 100644 --- a/src/Package/Gists/Comments.php +++ b/src/Package/Gists/Comments.php @@ -37,9 +37,9 @@ public function create($gistId, $body) // Build the request data. $data = json_encode( - array( + [ 'body' => $body, - ) + ] ); // Send the request. @@ -83,9 +83,9 @@ public function edit($commentId, $body) // Build the request data. $data = json_encode( - array( + [ 'body' => $body, - ) + ] ); // Send the request. diff --git a/src/Package/Gitignore.php b/src/Package/Gitignore.php index d5aa38ce..fe7d11df 100644 --- a/src/Package/Gitignore.php +++ b/src/Package/Gitignore.php @@ -58,7 +58,7 @@ public function get($name, $raw = false) // Build the request path. $path = '/gitignore/templates/' . $name; - $headers = array(); + $headers = []; if ($raw) { diff --git a/src/Package/Graphql.php b/src/Package/Graphql.php index 951aa357..9cc14c3b 100644 --- a/src/Package/Graphql.php +++ b/src/Package/Graphql.php @@ -29,19 +29,19 @@ class Graphql extends AbstractPackage * * @since 1.6.0 */ - public function execute($query, array $variables = array()) + public function execute($query, array $variables = []) { // Build the request path. $path = '/graphql'; - $headers = array( + $headers = [ 'Accept' => 'application/vnd.github.v4+json', 'Content-Type' => 'application/json', - ); + ]; - $data = array( + $data = [ 'query' => $query, - ); + ]; if (!empty($variables)) { diff --git a/src/Package/Issues.php b/src/Package/Issues.php index 2810e268..0a7f3699 100644 --- a/src/Package/Issues.php +++ b/src/Package/Issues.php @@ -54,12 +54,12 @@ public function create($user, $repo, $title, $body = null, $assignee = null, $mi } // Build the request data. - $data = array( + $data = [ 'title' => $title, 'milestone' => $milestone, 'labels' => $labels, 'body' => $body, - ); + ]; if (\is_string($assignee) && !empty($assignees)) { @@ -239,18 +239,18 @@ public function getList($filter = null, $state = null, $labels = null, $sort = n /** * List issues for a repository. * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $milestone The milestone number, 'none', or *. - * @param string $state The optional state to filter requests by. [open, closed] - * @param string $assignee The assignee name, 'none', or *. - * @param string $mentioned The GitHub user name. - * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. - * @param string $sort The sort order: created, updated, comments, default: created. - * @param string $direction The list direction: asc or desc, default: desc. - * @param \DateTime $since Only issues updated at or after this time are returned. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $milestone The milestone number, 'none', or *. + * @param string $state The optional state to filter requests by. [open, closed] + * @param string $assignee The assignee name, 'none', or *. + * @param string $mentioned The GitHub user name. + * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. + * @param string $sort The sort order: created, updated, comments, default: created. + * @param string $direction The list direction: asc or desc, default: desc. + * @param \DateTimeInterface $since Only issues updated at or after this time are returned. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. * * @return object * @@ -258,7 +258,7 @@ public function getList($filter = null, $state = null, $labels = null, $sort = n * @throws \DomainException */ public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, - $sort = null, $direction = null, \DateTime $since = null, $page = 0, $limit = 0 + $sort = null, $direction = null, \DateTimeInterface $since = null, $page = 0, $limit = 0 ) { // Build the request path. @@ -327,7 +327,7 @@ public function lock($user, $repo, $issueId) // Build the request path. $path = "/repos/$user/$repo/issues/" . (int) $issueId . '/lock'; - return $this->processResponse($this->client->put($this->fetchUrl($path), array()), 204); + return $this->processResponse($this->client->put($this->fetchUrl($path), []), 204); } /** diff --git a/src/Package/Issues/Assignees.php b/src/Package/Issues/Assignees.php index bd688e02..48cdfa2d 100644 --- a/src/Package/Issues/Assignees.php +++ b/src/Package/Issues/Assignees.php @@ -107,9 +107,9 @@ public function add($owner, $repo, $number, array $assignees) $path = "/repos/$owner/$repo/issues/$number/assignees"; $data = json_encode( - array( + [ 'assignees' => $assignees, - ) + ] ); return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); @@ -136,11 +136,11 @@ public function remove($owner, $repo, $number, array $assignees) $path = "/repos/$owner/$repo/issues/$number/assignees"; $data = json_encode( - array( + [ 'assignees' => $assignees, - ) + ] ); - return $this->processResponse($this->client->delete($this->fetchUrl($path), array(), null, $data)); + return $this->processResponse($this->client->delete($this->fetchUrl($path), [], null, $data)); } } diff --git a/src/Package/Issues/Comments.php b/src/Package/Issues/Comments.php index 8e9f5fa5..61e01e42 100644 --- a/src/Package/Issues/Comments.php +++ b/src/Package/Issues/Comments.php @@ -73,7 +73,7 @@ public function getRepositoryList($owner, $repo, $sort = 'created', $direction = // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/issues/comments'; - if (\in_array($sort, array('created', 'updated')) == false) + if (\in_array($sort, ['created', 'updated']) == false) { throw new \UnexpectedValueException( sprintf( @@ -82,7 +82,7 @@ public function getRepositoryList($owner, $repo, $sort = 'created', $direction = ); } - if (\in_array($direction, array('asc', 'desc')) == false) + if (\in_array($direction, ['asc', 'desc']) == false) { throw new \UnexpectedValueException( sprintf( @@ -147,9 +147,9 @@ public function edit($user, $repo, $commentId, $body) // Build the request data. $data = json_encode( - array( + [ 'body' => $body, - ) + ] ); // Send the request. @@ -178,9 +178,9 @@ public function create($user, $repo, $issueId, $body) // Build the request data. $data = json_encode( - array( + [ 'body' => $body, - ) + ] ); // Send the request. diff --git a/src/Package/Issues/Labels.php b/src/Package/Issues/Labels.php index c34c808c..204257ca 100644 --- a/src/Package/Issues/Labels.php +++ b/src/Package/Issues/Labels.php @@ -82,10 +82,10 @@ public function create($owner, $repo, $name, $color) // Build the request data. $data = json_encode( - array( + [ 'name' => $name, 'color' => $color, - ) + ] ); // Send the request. @@ -135,10 +135,10 @@ public function update($user, $repo, $label, $name, $color) // Build the request data. $data = json_encode( - array( + [ 'name' => $name, 'color' => $color, - ) + ] ); // Send the request. diff --git a/src/Package/Issues/Milestones.php b/src/Package/Issues/Milestones.php index 3903fe6c..f73a2d20 100644 --- a/src/Package/Issues/Milestones.php +++ b/src/Package/Issues/Milestones.php @@ -92,9 +92,9 @@ public function create($user, $repo, $title, $state = null, $description = null, $path = '/repos/' . $user . '/' . $repo . '/milestones'; // Build the request data. - $data = array( + $data = [ 'title' => $title, - ); + ]; if ($state !== null) { @@ -140,7 +140,7 @@ public function edit($user, $repo, $milestoneId, $title = null, $state = null, $ $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId; // Build the request data. - $data = array(); + $data = []; if ($title !== null) { diff --git a/src/Package/Markdown.php b/src/Package/Markdown.php index 56611c05..58d11e71 100644 --- a/src/Package/Markdown.php +++ b/src/Package/Markdown.php @@ -36,7 +36,7 @@ class Markdown extends AbstractPackage public function render($text, $mode = 'gfm', $context = null) { // The valid modes - $validModes = array('gfm', 'markdown'); + $validModes = ['gfm', 'markdown']; // Make sure the scope is valid if (!\in_array($mode, $validModes)) diff --git a/src/Package/Orgs.php b/src/Package/Orgs.php index 497477cf..f0deea6f 100644 --- a/src/Package/Orgs.php +++ b/src/Package/Orgs.php @@ -86,9 +86,9 @@ public function edit($org, $billingEmail = '', $company = '', $email = '', $loca // Build the request path. $path = '/orgs/' . $org; - $args = array('billing_email', 'company', 'email', 'location', 'name'); + $args = ['billing_email', 'company', 'email', 'location', 'name']; - $data = array(); + $data = []; $fArgs = \func_get_args(); diff --git a/src/Package/Orgs/Hooks.php b/src/Package/Orgs/Hooks.php index 5bc32574..d9456892 100644 --- a/src/Package/Orgs/Hooks.php +++ b/src/Package/Orgs/Hooks.php @@ -80,32 +80,32 @@ public function get($org, $id) * @since 1.4.0 * @throws \UnexpectedValueException */ - public function create($org, $url, $contentType = 'form', $secret = null, $insecureSsl = false, array $events = array('push'), $active = true) + public function create($org, $url, $contentType = 'form', $secret = null, $insecureSsl = false, array $events = ['push'], $active = true) { // Build the request path. $path = "/orgs/$org/hooks"; - if (\in_array($contentType, array('form', 'json')) == false) + if (\in_array($contentType, ['form', 'json']) == false) { throw new \UnexpectedValueException('Content type must be either "form" or "json".'); } - $config = array( + $config = [ 'url' => $url, 'content_type' => $contentType, 'insecure_ssl' => (int) $insecureSsl, - ); + ]; if ($secret) { $config['secret'] = $secret; } - $data = array( + $data = [ 'name' => 'web', 'active' => $active, 'config' => (object) $config, - ); + ]; if (!empty($events)) { @@ -146,18 +146,18 @@ public function create($org, $url, $contentType = 'form', $secret = null, $insec * @since 1.4.0 * @throws \UnexpectedValueException */ - public function edit($org, $url, $contentType = null, $secret = null, $insecureSsl = null, array $events = array(), $active = null) + public function edit($org, $url, $contentType = null, $secret = null, $insecureSsl = null, array $events = [], $active = null) { // Build the request path. $path = "/orgs/$org/hooks"; - $config = array( + $config = [ 'url' => $url, - ); + ]; if ($contentType) { - if (\in_array($contentType, array('form', 'json')) == false) + if (\in_array($contentType, ['form', 'json']) == false) { throw new \UnexpectedValueException('Content type must be either "form" or "json".'); } @@ -175,9 +175,9 @@ public function edit($org, $url, $contentType = null, $secret = null, $insecureS $config['secret'] = $secret; } - $data = array( + $data = [ 'config' => (object) $config, - ); + ]; if ($active !== null) { diff --git a/src/Package/Orgs/Members.php b/src/Package/Orgs/Members.php index 11e26e19..eb4f5e31 100644 --- a/src/Package/Orgs/Members.php +++ b/src/Package/Orgs/Members.php @@ -258,7 +258,7 @@ public function getMembership($org, $user) */ public function updateMembership($org, $user, $role = 'member') { - $allowedRoles = array('member', 'admin'); + $allowedRoles = ['member', 'admin']; if (!\in_array($role, $allowedRoles)) { @@ -268,9 +268,9 @@ public function updateMembership($org, $user, $role = 'member') // Build the request path. $path = "/orgs/$org/memberships/$user"; - $data = array( + $data = [ 'role' => $role, - ); + ]; return $this->processResponse($this->client->put($this->fetchUrl($path), json_encode($data))); } @@ -351,6 +351,6 @@ public function editOrganizationMembership($org, $state) // Build the request path. $path = '/user/memberships/orgs/' . $org; - return $this->processResponse($this->client->patch($this->fetchUrl($path), array('state' => $state))); + return $this->processResponse($this->client->patch($this->fetchUrl($path), ['state' => $state])); } } diff --git a/src/Package/Orgs/Teams.php b/src/Package/Orgs/Teams.php index f28719c8..feb631f2 100644 --- a/src/Package/Orgs/Teams.php +++ b/src/Package/Orgs/Teams.php @@ -78,14 +78,14 @@ public function get($id) * @since 1.0 * @throws \UnexpectedValueException */ - public function create($org, $name, array $repoNames = array(), $permission = '') + public function create($org, $name, array $repoNames = [], $permission = '') { // Build the request path. $path = '/orgs/' . $org . '/teams'; - $data = array( + $data = [ 'name' => $name, - ); + ]; if ($repoNames) { @@ -94,7 +94,7 @@ public function create($org, $name, array $repoNames = array(), $permission = '' if ($permission) { - if (\in_array($permission, array('pull', 'push', 'admin')) == false) + if (\in_array($permission, ['pull', 'push', 'admin']) == false) { throw new \UnexpectedValueException('Permissions must be either "pull", "push", or "admin".'); } @@ -130,13 +130,13 @@ public function edit($id, $name, $permission = '') // Build the request path. $path = '/teams/' . (int) $id; - $data = array( + $data = [ 'name' => $name, - ); + ]; if ($permission) { - if (\in_array($permission, array('pull', 'push', 'admin')) == false) + if (\in_array($permission, ['pull', 'push', 'admin']) == false) { throw new \UnexpectedValueException('Permissions must be either "pull", "push", or "admin".'); } @@ -337,14 +337,14 @@ public function addTeamMembership($id, $user, $role = 'member') // Build the request path. $path = "/teams/$id/memberships/$user"; - if (\in_array($role, array('member', 'maintainer')) == false) + if (\in_array($role, ['member', 'maintainer']) == false) { throw new \UnexpectedValueException('Roles must be either "member" or "maintainer".'); } - $data = array( + $data = [ 'role' => $role, - ); + ]; return $this->processResponse($this->client->put($this->fetchUrl($path), $data)); } diff --git a/src/Package/Pulls.php b/src/Package/Pulls.php index d4f89e21..f381f06e 100644 --- a/src/Package/Pulls.php +++ b/src/Package/Pulls.php @@ -47,12 +47,12 @@ public function create($user, $repo, $title, $base, $head, $body = '') // Build the request data. $data = json_encode( - array( + [ 'title' => $title, 'base' => $base, 'head' => $head, 'body' => $body, - ) + ] ); // Send the request. @@ -83,11 +83,11 @@ public function createFromIssue($user, $repo, $issueId, $base, $head) // Build the request data. $data = json_encode( - array( + [ 'issue' => (int) $issueId, 'base' => $base, 'head' => $head, - ) + ] ); // Send the request. @@ -303,9 +303,9 @@ public function merge($user, $repo, $pullId, $message = '') // Build the request data. $data = json_encode( - array( + [ 'commit_message' => $message, - ) + ] ); // Send the request. diff --git a/src/Package/Pulls/Comments.php b/src/Package/Pulls/Comments.php index acb8da43..657f470e 100644 --- a/src/Package/Pulls/Comments.php +++ b/src/Package/Pulls/Comments.php @@ -41,12 +41,12 @@ public function create($user, $repo, $pullId, $body, $commitId, $filePath, $posi // Build the request data. $data = json_encode( - array( + [ 'body' => $body, 'commit_id' => $commitId, 'path' => $filePath, 'position' => $position, - ) + ] ); // Send the request. @@ -76,10 +76,10 @@ public function createReply($user, $repo, $pullId, $body, $inReplyTo) // Build the request data. $data = json_encode( - array( + [ 'body' => $body, 'in_reply_to' => (int) $inReplyTo, - ) + ] ); // Send the request. @@ -131,9 +131,9 @@ public function edit($user, $repo, $commentId, $body) // Build the request data. $data = json_encode( - array( + [ 'body' => $body, - ) + ] ); // Send the request. diff --git a/src/Package/Repositories.php b/src/Package/Repositories.php index e9d1237b..acafb4f8 100644 --- a/src/Package/Repositories.php +++ b/src/Package/Repositories.php @@ -51,12 +51,12 @@ class Repositories extends AbstractPackage */ public function getListOwn($type = 'all', $sort = 'full_name', $direction = '') { - if (\in_array($type, array('all', 'owner', 'public', 'private', 'member')) == false) + if (\in_array($type, ['all', 'owner', 'public', 'private', 'member']) == false) { throw new \RuntimeException('Invalid type'); } - if (\in_array($sort, array('created', 'updated', 'pushed', 'full_name')) == false) + if (\in_array($sort, ['created', 'updated', 'pushed', 'full_name']) == false) { throw new \RuntimeException('Invalid sort field'); } @@ -64,7 +64,7 @@ public function getListOwn($type = 'all', $sort = 'full_name', $direction = '') // Sort direction default: when using full_name: asc, otherwise desc. $direction = ($direction) ? : (($sort == 'full_name') ? 'asc' : 'desc'); - if (\in_array($direction, array('asc', 'desc')) == false) + if (\in_array($direction, ['asc', 'desc']) == false) { throw new \RuntimeException('Invalid sort order'); } @@ -96,12 +96,12 @@ public function getListOwn($type = 'all', $sort = 'full_name', $direction = '') */ public function getListUser($user, $type = 'all', $sort = 'full_name', $direction = '') { - if (\in_array($type, array('all', 'owner', 'member')) == false) + if (\in_array($type, ['all', 'owner', 'member']) == false) { throw new \RuntimeException('Invalid type'); } - if (\in_array($sort, array('created', 'updated', 'pushed', 'full_name')) == false) + if (\in_array($sort, ['created', 'updated', 'pushed', 'full_name']) == false) { throw new \RuntimeException('Invalid sort field'); } @@ -109,7 +109,7 @@ public function getListUser($user, $type = 'all', $sort = 'full_name', $directio // Sort direction default: when using full_name: asc, otherwise desc. $direction = $direction ?: ($sort == 'full_name' ? 'asc' : 'desc'); - if (\in_array($direction, array('asc', 'desc')) == false) + if (\in_array($direction, ['asc', 'desc']) == false) { throw new \RuntimeException('Invalid sort order'); } @@ -139,7 +139,7 @@ public function getListUser($user, $type = 'all', $sort = 'full_name', $directio */ public function getListOrg($org, $type = 'all') { - if (\in_array($type, array('all', 'public', 'private', 'forks', 'sources', 'member')) == false) + if (\in_array($type, ['all', 'public', 'private', 'forks', 'sources', 'member']) == false) { throw new \RuntimeException('Invalid type'); } @@ -212,7 +212,7 @@ public function create($name, $org = '', $description = '', $homepage = '', $pri // Create a repository for a user : '/user/repos'; - $data = array( + $data = [ 'name' => $name, 'description' => $description, 'homepage' => $homepage, @@ -223,7 +223,7 @@ public function create($name, $org = '', $description = '', $homepage = '', $pri 'team_id' => $teamId, 'auto_init' => $autoInit, 'gitignore_template' => $gitignoreTemplate, - ); + ]; // Send the request. return $this->processResponse( @@ -278,7 +278,7 @@ public function edit($owner, $repo, $name, $description = '', $homepage = '', $p { $path = '/repos/' . $owner . '/' . $repo; - $data = array( + $data = [ 'name' => $name, 'description' => $description, 'homepage' => $homepage, @@ -287,7 +287,7 @@ public function edit($owner, $repo, $name, $description = '', $homepage = '', $p 'has_wiki' => $hasWiki, 'has_downloads' => $hasDownloads, 'default_branch' => $defaultBranch, - ); + ]; // Send the request. return $this->processResponse( diff --git a/src/Package/Repositories/Comments.php b/src/Package/Repositories/Comments.php index a75cca1f..2a6887ba 100644 --- a/src/Package/Repositories/Comments.php +++ b/src/Package/Repositories/Comments.php @@ -106,9 +106,9 @@ public function edit($user, $repo, $id, $comment) $path = '/repos/' . $user . '/' . $repo . '/comments/' . $id; $data = json_encode( - array( + [ 'body' => $comment, - ) + ] ); // Send the request. @@ -161,12 +161,12 @@ public function create($user, $repo, $sha, $comment, $line, $filepath, $position $path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/comments'; $data = json_encode( - array( + [ 'body' => $comment, 'path' => $filepath, 'position' => (int) $position, 'line' => (int) $line, - ) + ] ); // Send the request. diff --git a/src/Package/Repositories/Contents.php b/src/Package/Repositories/Contents.php index 90bdec70..fa545ace 100644 --- a/src/Package/Repositories/Contents.php +++ b/src/Package/Repositories/Contents.php @@ -106,14 +106,14 @@ public function get($owner, $repo, $path, $ref = '') */ public function getArchiveLink($owner, $repo, $archiveFormat = 'zipball', $ref = '') { - if (\in_array($archiveFormat, array('tarball', 'zipball')) == false) + if (\in_array($archiveFormat, ['tarball', 'zipball']) == false) { throw new \UnexpectedValueException('Archive format must be either "tarball" or "zipball".'); } // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/' . $archiveFormat; - $uri = $this->fetchUrl($path); + $uri = $this->fetchUrl($path); if ($ref) { @@ -159,11 +159,11 @@ public function create($owner, $repo, $path, $message, $content, $branch = 'mast // Build the request path. $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; - $data = array( + $data = [ 'message' => $message, 'content' => $content, 'branch' => $branch, - ); + ]; if ($authorName) { @@ -172,10 +172,10 @@ public function create($owner, $repo, $path, $message, $content, $branch = 'mast throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); } - $data['author'] = array( + $data['author'] = [ 'name' => $authorName, 'email' => $authorEmail, - ); + ]; } if ($committerName) @@ -185,10 +185,10 @@ public function create($owner, $repo, $path, $message, $content, $branch = 'mast throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); } - $data['committer'] = array( + $data['committer'] = [ 'name' => $committerName, 'email' => $committerEmail, - ); + ]; } return $this->processResponse($this->client->put($this->fetchUrl($route), json_encode($data)), 201); @@ -230,12 +230,12 @@ public function update($owner, $repo, $path, $message, $content, $sha, $branch = // Build the request path. $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; - $data = array( + $data = [ 'message' => $message, 'content' => $content, 'sha' => $sha, 'branch' => $branch, - ); + ]; if ($authorName) { @@ -244,10 +244,10 @@ public function update($owner, $repo, $path, $message, $content, $sha, $branch = throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); } - $data['author'] = array( + $data['author'] = [ 'name' => $authorName, 'email' => $authorEmail, - ); + ]; } if ($committerName) @@ -257,10 +257,10 @@ public function update($owner, $repo, $path, $message, $content, $sha, $branch = throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); } - $data['committer'] = array( + $data['committer'] = [ 'name' => $committerName, 'email' => $committerEmail, - ); + ]; } return $this->processResponse($this->client->put($this->fetchUrl($route), json_encode($data))); @@ -294,11 +294,11 @@ public function delete($owner, $repo, $path, $message, $sha, $branch = 'master', // Build the request path. $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; - $data = array( + $data = [ 'message' => $message, 'sha' => $sha, 'branch' => $branch, - ); + ]; if ($authorName) { @@ -307,10 +307,10 @@ public function delete($owner, $repo, $path, $message, $sha, $branch = 'master', throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); } - $data['author'] = array( + $data['author'] = [ 'name' => $authorName, 'email' => $authorEmail, - ); + ]; } if ($committerName) @@ -320,16 +320,18 @@ public function delete($owner, $repo, $path, $message, $sha, $branch = 'master', throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); } - $data['committer'] = array( + $data['committer'] = [ 'name' => $committerName, 'email' => $committerEmail, - ); + ]; } return $this->processResponse( $this->client->delete( $this->fetchUrl($route), - array(), null, json_encode($data) + [], + null, + json_encode($data) ) ); } diff --git a/src/Package/Repositories/Deployments.php b/src/Package/Repositories/Deployments.php index 7feb848d..ce60af1f 100644 --- a/src/Package/Repositories/Deployments.php +++ b/src/Package/Repositories/Deployments.php @@ -95,10 +95,10 @@ public function create($owner, $repo, $ref, $task = '', $autoMerge = true, $requ // Build the request path. $path = "/repos/$owner/$repo/deployments"; - $data = array( + $data = [ 'ref' => $ref, 'auto_merge' => $autoMerge, - ); + ]; if ($task) { @@ -186,7 +186,7 @@ public function getDeploymentStatuses($owner, $repo, $id, $page = 0, $limit = 0) */ public function createStatus($owner, $repo, $id, $state, $targetUrl = '', $description = '') { - $allowedStates = array('pending', 'success', 'error', 'failure'); + $allowedStates = ['pending', 'success', 'error', 'failure']; // Build the request path. $path = "/repos/$owner/$repo/deployments/" . (int) $id . '/statuses'; @@ -196,9 +196,9 @@ public function createStatus($owner, $repo, $id, $state, $targetUrl = '', $descr throw new \InvalidArgumentException(sprintf('The deployment state must be: %s', implode(', ', $allowedStates))); } - $data = array( + $data = [ 'state' => $state, - ); + ]; if ($targetUrl) { diff --git a/src/Package/Repositories/Forks.php b/src/Package/Repositories/Forks.php index 39e366af..5639fd89 100644 --- a/src/Package/Repositories/Forks.php +++ b/src/Package/Repositories/Forks.php @@ -39,12 +39,12 @@ public function create($owner, $repo, $org = '') if (\strlen($org) > 0) { $data = json_encode( - array('org' => $org) + ['org' => $org] ); } else { - $data = json_encode(array()); + $data = json_encode([]); } // Send the request. diff --git a/src/Package/Repositories/Hooks.php b/src/Package/Repositories/Hooks.php index 03b6c23d..1e9678a2 100644 --- a/src/Package/Repositories/Hooks.php +++ b/src/Package/Repositories/Hooks.php @@ -35,7 +35,7 @@ class Hooks extends AbstractPackage * @throws \DomainException * @throws \RuntimeException */ - public function create($user, $repo, $name, $config, array $events = array('push'), $active = true) + public function create($user, $repo, $name, $config, array $events = ['push'], $active = true) { // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/hooks'; @@ -50,7 +50,7 @@ public function create($user, $repo, $name, $config, array $events = array('push } $data = json_encode( - array('name' => $name, 'config' => $config, 'events' => $events, 'active' => $active) + ['name' => $name, 'config' => $config, 'events' => $events, 'active' => $active] ); return $this->processResponse( @@ -101,9 +101,7 @@ public function delete($user, $repo, $id) * @throws \DomainException * @throws \RuntimeException */ - public function edit($user, $repo, $id, $name, $config, array $events = array('push'), array $addEvents = array(), - array $removeEvents = array(), $active = true - ) + public function edit($user, $repo, $id, $name, $config, array $events = ['push'], array $addEvents = [], array $removeEvents = [], $active = true) { // Check to ensure all events are in the allowed list foreach ($events as $event) @@ -134,14 +132,14 @@ public function edit($user, $repo, $id, $name, $config, array $events = array('p $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id; $data = json_encode( - array( + [ 'name' => $name, 'config' => $config, 'events' => $events, 'add_events' => $addEvents, 'remove_events' => $removeEvents, 'active' => $active, - ) + ] ); return $this->processResponse( diff --git a/src/Package/Repositories/Keys.php b/src/Package/Repositories/Keys.php index e97335c7..6a82285a 100644 --- a/src/Package/Repositories/Keys.php +++ b/src/Package/Repositories/Keys.php @@ -77,10 +77,10 @@ public function create($owner, $repo, $title, $key) // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/keys'; - $data = array( + $data = [ 'title' => $title, 'key' => $key, - ); + ]; return $this->processResponse( $this->client->post($this->fetchUrl($path), json_encode($data)), @@ -106,10 +106,10 @@ public function edit($owner, $repo, $id, $title, $key) // Build the request path. $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id; - $data = array( + $data = [ 'title' => $title, 'key' => $key, - ); + ]; return $this->processResponse( $this->client->patch($this->fetchUrl($path), json_encode($data)) diff --git a/src/Package/Repositories/Releases.php b/src/Package/Repositories/Releases.php index 70e239ef..eee7f308 100644 --- a/src/Package/Repositories/Releases.php +++ b/src/Package/Repositories/Releases.php @@ -43,14 +43,14 @@ public function create($user, $repo, $tagName, $targetCommitish = '', $name = '' // Build the request data. $data = json_encode( - array( + [ 'tag_name' => $tagName, 'target_commitish' => $targetCommitish, 'name' => $name, 'body' => $body, 'draft' => (boolean) $draft, 'prerelease' => (boolean) $preRelease, - ) + ] ); // Send the request. @@ -225,7 +225,7 @@ public function getList($user, $repo, $page = 0, $limit = 0) // Send the request. $response = $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - $releases = array(); + $releases = []; if (\is_array($response)) { @@ -298,9 +298,9 @@ public function editAsset($user, $repo, $assetId, $name, $label = '') // Build the request path. $path = '/repos/' . $user . '/' . $repo . '/releases/assets/' . (int) $assetId; - $data = array( + $data = [ 'name' => $name, - ); + ]; if ($label) { diff --git a/src/Package/Repositories/Statuses.php b/src/Package/Repositories/Statuses.php index eb0666e5..35fa2387 100644 --- a/src/Package/Repositories/Statuses.php +++ b/src/Package/Repositories/Statuses.php @@ -43,15 +43,15 @@ public function create($user, $repo, $sha, $state, $targetUrl = null, $descripti // Build the request path. $path = "/repos/$user/$repo/statuses/$sha"; - if (!\in_array($state, array('pending', 'success', 'error', 'failure'))) + if (!\in_array($state, ['pending', 'success', 'error', 'failure'])) { throw new \InvalidArgumentException('State must be one of pending, success, error or failure.'); } // Build the request data. - $data = array( + $data = [ 'state' => $state, - ); + ]; if ($targetUrl !== null) { diff --git a/src/Package/Search.php b/src/Package/Search.php index fdd922d5..9961f1d9 100644 --- a/src/Package/Search.php +++ b/src/Package/Search.php @@ -35,7 +35,7 @@ class Search extends AbstractPackage */ public function issues($owner, $repo, $state, $keyword) { - if (\in_array($state, array('open', 'close')) == false) + if (\in_array($state, ['open', 'close']) == false) { throw new \UnexpectedValueException('State must be either "open" or "closed"'); } diff --git a/src/Package/Users.php b/src/Package/Users.php index dfb48c18..433dd1a3 100644 --- a/src/Package/Users.php +++ b/src/Package/Users.php @@ -81,7 +81,7 @@ public function getAuthenticatedUser() */ public function edit($name = '', $email = '', $blog = '', $company = '', $location = '', $hireable = '', $bio = '') { - $data = array( + $data = [ 'name' => $name, 'email' => $email, 'blog' => $blog, @@ -89,7 +89,7 @@ public function edit($name = '', $email = '', $blog = '', $company = '', $locati 'location' => $location, 'hireable' => $hireable, 'bio' => $bio, - ); + ]; // Build the request path. $path = '/user'; diff --git a/src/Package/Users/Keys.php b/src/Package/Users/Keys.php index 225ec75f..8feca721 100644 --- a/src/Package/Users/Keys.php +++ b/src/Package/Users/Keys.php @@ -95,10 +95,10 @@ public function create($title, $key) // Build the request path. $path = '/users/keys'; - $data = array( + $data = [ 'title' => $title, 'key' => $key, - ); + ]; return $this->processResponse( $this->client->post($this->fetchUrl($path), json_encode($data)), @@ -122,10 +122,10 @@ public function edit($id, $title, $key) // Build the request path. $path = '/users/keys/' . $id; - $data = array( + $data = [ 'title' => $title, 'key' => $key, - ); + ]; return $this->processResponse( $this->client->patch($this->fetchUrl($path), json_encode($data)) From f557725c0e00ee967e2bb4c65f492c7817e2ec4d Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 9 Feb 2019 15:10:25 -0600 Subject: [PATCH 36/79] Use a multi-line signature that's actually legible --- src/Package/Issues.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Package/Issues.php b/src/Package/Issues.php index 0a7f3699..f6b36caa 100644 --- a/src/Package/Issues.php +++ b/src/Package/Issues.php @@ -195,8 +195,15 @@ public function get($user, $repo, $issueId) * @since 1.0 * @throws \DomainException */ - public function getList($filter = null, $state = null, $labels = null, $sort = null, $direction = null, \DateTimeInterface $since = null, - $page = 0, $limit = 0 + public function getList( + $filter = null, + $state = null, + $labels = null, + $sort = null, + $direction = null, + \DateTimeInterface $since = null, + $page = 0, + $limit = 0 ) { // Build the request path. @@ -257,8 +264,19 @@ public function getList($filter = null, $state = null, $labels = null, $sort = n * @since 1.0 * @throws \DomainException */ - public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, - $sort = null, $direction = null, \DateTimeInterface $since = null, $page = 0, $limit = 0 + public function getListByRepository( + $user, + $repo, + $milestone = null, + $state = null, + $assignee = null, + $mentioned = null, + $labels = null, + $sort = null, + $direction = null, + \DateTimeInterface $since = null, + $page = 0, + $limit = 0 ) { // Build the request path. From db7d4fd5b1c7dd91fc5b2c84e94193fc7822ef01 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Mon, 17 Jun 2019 17:36:29 -0500 Subject: [PATCH 37/79] Raise PHP minimum to 7.2 --- .travis.yml | 13 +++++++------ composer.json | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index d269ecff..a632a19f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,18 +10,19 @@ env: matrix: fast_finish: true include: - - php: 7.0 - - php: 7.0 + - php: 7.2 + - php: 7.2 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" - - php: 7.0 + - php: 7.2 env: RUN_PHPCS="yes" - - php: 7.1 - - php: 7.1 + - php: 7.3 + - php: 7.3 # This empty flag removes the prefer-stable switch to cause dev dependencies to be installed env: COMPOSER_FLAGS="" - - php: 7.2 + - php: 7.4snapshot - php: nightly allow_failures: + - php: 7.4snapshot - php: nightly before_script: diff --git a/composer.json b/composer.json index 809d7ba5..4788dd3d 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "https://github.com/joomla-framework/github-api", "license": "GPL-2.0-or-later", "require": { - "php": "~7.0", + "php": "~7.2", "joomla/http": "~1.3|~2.0", "joomla/registry": "^1.4.5|~2.0", "joomla/uri": "~1.0|~2.0" From 2e2139d3ec4594676470077a162fbf37e205ee72 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 14 Jul 2019 13:49:38 -0500 Subject: [PATCH 38/79] Upgrade to PHPUnit 8 --- .gitignore | 1 + Tests/GithubObjectTest.php | 2 +- Tests/GithubTest.php | 7 ++-- Tests/Package/Activity/EventsTest.php | 2 +- Tests/Package/Activity/FeedsTest.php | 2 +- Tests/Package/Activity/NotificationsTest.php | 2 +- Tests/Package/Activity/StarringTest.php | 13 ++++--- Tests/Package/Activity/WatchingTest.php | 5 ++- Tests/Package/ActivityTest.php | 2 +- Tests/Package/AuthorizationsTest.php | 34 ++++++++--------- Tests/Package/Data/BlobsTest.php | 2 +- Tests/Package/Data/CommitsTest.php | 2 +- Tests/Package/Data/RefsTest.php | 22 +++++------ Tests/Package/Data/TagsTest.php | 2 +- Tests/Package/Data/TreesTest.php | 2 +- Tests/Package/DataTest.php | 2 +- Tests/Package/EmojisTest.php | 2 +- Tests/Package/GistsTest.php | 6 +-- Tests/Package/GitignoreTest.php | 6 +-- Tests/Package/GraphqlTest.php | 2 +- Tests/Package/Issues/AssigneesTest.php | 6 +-- Tests/Package/Issues/CommentsTest.php | 8 ++-- Tests/Package/Issues/EventsTest.php | 2 +- Tests/Package/Issues/LabelsTest.php | 5 ++- Tests/Package/Issues/MilestonesTest.php | 22 +++++------ Tests/Package/IssuesTest.php | 34 ++++++++--------- Tests/Package/MarkdownTest.php | 10 ++--- Tests/Package/MetaTest.php | 6 +-- Tests/Package/Orgs/HooksTest.php | 22 +++++------ Tests/Package/Orgs/MembersTest.php | 28 +++++++------- Tests/Package/Orgs/TeamsTest.php | 30 +++++++-------- Tests/Package/OrgsTest.php | 2 +- Tests/Package/Pulls/CommentsTest.php | 2 +- Tests/Package/PullsTest.php | 38 +++++++++---------- Tests/Package/Repositories/BranchesTest.php | 2 +- .../Repositories/CollaboratorsTest.php | 6 +-- Tests/Package/Repositories/CommentsTest.php | 2 +- Tests/Package/Repositories/CommitsTest.php | 21 +++++----- Tests/Package/Repositories/ContentsTest.php | 30 +++++++-------- .../Package/Repositories/DeploymentsTest.php | 14 +++---- Tests/Package/Repositories/DownloadsTest.php | 14 +++---- Tests/Package/Repositories/ForksTest.php | 10 ++--- Tests/Package/Repositories/HooksTest.php | 30 +++++++-------- Tests/Package/Repositories/KeysTest.php | 2 +- Tests/Package/Repositories/MergingTest.php | 18 ++++----- Tests/Package/Repositories/PagesTest.php | 2 +- Tests/Package/Repositories/ReleasesTest.php | 2 +- Tests/Package/Repositories/StatisticsTest.php | 5 ++- Tests/Package/Repositories/StatusesTest.php | 14 +++---- Tests/Package/RepositoriesTest.php | 30 +++++++-------- Tests/Package/SearchTest.php | 6 +-- Tests/Package/Users/EmailsTest.php | 2 +- Tests/Package/Users/FollowersTest.php | 12 +++--- Tests/Package/Users/KeysTest.php | 2 +- Tests/Package/UsersTest.php | 13 ++++--- Tests/Package/ZenTest.php | 6 +-- Tests/PackageTest.php | 6 +-- Tests/Stub/GitHubTestCase.php | 2 +- composer.json | 2 +- 59 files changed, 298 insertions(+), 288 deletions(-) diff --git a/.gitignore b/.gitignore index 340b0780..c016313d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ vendor/ composer.phar composer.lock phpunit.xml +.phpunit.result.cache # Build files /build/coverage diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index 38692739..38fb8d85 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -30,7 +30,7 @@ class GithubObjectTest extends GitHubTestCase * * @since 1.0 */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/GithubTest.php b/Tests/GithubTest.php index bed096b1..e2b7285a 100755 --- a/Tests/GithubTest.php +++ b/Tests/GithubTest.php @@ -30,7 +30,7 @@ class GithubTest extends GitHubTestCase * * @since 1.0 */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -102,11 +102,12 @@ public function testGetHooks() * * @return void * - * @since 1.0 - * @expectedException \InvalidArgumentException + * @since 1.0 */ public function testGetFailure() { + $this->expectException(\InvalidArgumentException::class); + $this->object->other; } diff --git a/Tests/Package/Activity/EventsTest.php b/Tests/Package/Activity/EventsTest.php index 3d9eb178..8c093761 100644 --- a/Tests/Package/Activity/EventsTest.php +++ b/Tests/Package/Activity/EventsTest.php @@ -42,7 +42,7 @@ class EventsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Activity/FeedsTest.php b/Tests/Package/Activity/FeedsTest.php index be1f82c2..6f63a0e8 100644 --- a/Tests/Package/Activity/FeedsTest.php +++ b/Tests/Package/Activity/FeedsTest.php @@ -30,7 +30,7 @@ class FeedsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Activity/NotificationsTest.php b/Tests/Package/Activity/NotificationsTest.php index abfda4c7..b5fc72f1 100644 --- a/Tests/Package/Activity/NotificationsTest.php +++ b/Tests/Package/Activity/NotificationsTest.php @@ -32,7 +32,7 @@ class NotificationsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Activity/StarringTest.php b/Tests/Package/Activity/StarringTest.php index 1306033c..9ff57008 100644 --- a/Tests/Package/Activity/StarringTest.php +++ b/Tests/Package/Activity/StarringTest.php @@ -32,7 +32,7 @@ class StarringTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -107,11 +107,11 @@ public function testGetRepositoriesWithName() * Invalid sort option * * @return void - * - * @expectedException \InvalidArgumentException */ public function testGetRepositoriesInvalidSort() { + $this->expectException(\InvalidArgumentException::class); + $this->object->getRepositories('', 'invalid'); } @@ -123,11 +123,11 @@ public function testGetRepositoriesInvalidSort() * Invalid direction option * * @return void - * - * @expectedException \InvalidArgumentException */ public function testGetRepositoriesInvalidDirection() { + $this->expectException(\InvalidArgumentException::class); + $this->object->getRepositories('', 'created', 'invalid'); } @@ -182,11 +182,12 @@ public function testCheckFalse() * * @covers \Joomla\Github\Package\Activity\Starring::check() * - * @expectedException \UnexpectedValueException * @return void */ public function testCheckUnexpected() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->response->body = false; diff --git a/Tests/Package/Activity/WatchingTest.php b/Tests/Package/Activity/WatchingTest.php index 75d19bad..1685cd03 100644 --- a/Tests/Package/Activity/WatchingTest.php +++ b/Tests/Package/Activity/WatchingTest.php @@ -30,7 +30,7 @@ class WatchingTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -193,11 +193,12 @@ public function testCheckFalse() /** * Tests the checkUnexpected method * - * @expectedException \UnexpectedValueException * @return void */ public function testCheckUnexpected() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->response->body = ''; diff --git a/Tests/Package/ActivityTest.php b/Tests/Package/ActivityTest.php index fe58b699..781a8af1 100644 --- a/Tests/Package/ActivityTest.php +++ b/Tests/Package/ActivityTest.php @@ -31,7 +31,7 @@ class ActivityTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/AuthorizationsTest.php b/Tests/Package/AuthorizationsTest.php index 7d419e44..41eb8a75 100644 --- a/Tests/Package/AuthorizationsTest.php +++ b/Tests/Package/AuthorizationsTest.php @@ -29,7 +29,7 @@ class AuthorizationsTest extends GitHubTestCase * * @since 1.0 */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -348,11 +348,11 @@ public function testEditFailure() * @return void * * @since 1.0 - * - * @expectedException \RuntimeException */ public function testEditTooManyScopes() { + $this->expectException(\RuntimeException::class); + $this->object->edit(42, array(), array('public_repo', 'gist'), array('public_repo', 'gist'), 'My test app', 'http://www.joomla.org'); } @@ -382,11 +382,11 @@ public function testGet() * @return void * * @since 1.0 - * - * @expectedException \DomainException */ public function testGetFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -424,11 +424,11 @@ public function testGetGrant() * @return void * * @since 1.0 - * - * @expectedException \DomainException */ public function testGetGrantFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -466,11 +466,11 @@ public function testGetList() * @return void * * @since 1.0 - * - * @expectedException \DomainException */ public function testGetListFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -508,11 +508,11 @@ public function testGetListGrants() * @return void * * @since 1.0 - * - * @expectedException \DomainException */ public function testGetListGrantsFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -570,11 +570,11 @@ public function testGetRateLimitUnlimited() * @return void * * @since 1.0 - * - * @expectedException \DomainException */ public function testGetRateLimitFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -670,11 +670,11 @@ public function testRequestTokenXml() * Tests the requestTokenInvalidFormat method * * @return void - * - * @expectedException \UnexpectedValueException */ public function testRequestTokenInvalidFormat() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 200; $this->response->body = ''; @@ -709,11 +709,11 @@ public function testRevokeGrantForApplication() * @return void * * @since 1.0 - * - * @expectedException \DomainException */ public function testRevokeGrantForApplicationFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; diff --git a/Tests/Package/Data/BlobsTest.php b/Tests/Package/Data/BlobsTest.php index 77db8794..eb3efa25 100644 --- a/Tests/Package/Data/BlobsTest.php +++ b/Tests/Package/Data/BlobsTest.php @@ -30,7 +30,7 @@ class BlobsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Data/CommitsTest.php b/Tests/Package/Data/CommitsTest.php index 9dbecd6b..42e0aca6 100644 --- a/Tests/Package/Data/CommitsTest.php +++ b/Tests/Package/Data/CommitsTest.php @@ -30,7 +30,7 @@ class CommitsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Data/RefsTest.php b/Tests/Package/Data/RefsTest.php index d2f84dab..c7dc066b 100755 --- a/Tests/Package/Data/RefsTest.php +++ b/Tests/Package/Data/RefsTest.php @@ -30,7 +30,7 @@ class RefsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -58,12 +58,12 @@ public function testGet() /** * Tests the get method * - * @expectedException \DomainException - * * @return void */ public function testGetFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -106,12 +106,12 @@ public function testCreate() /** * Tests the create method - failure * - * @expectedException \DomainException - * * @return void */ public function testCreateFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 501; $this->response->body = $this->errorString; @@ -160,12 +160,12 @@ public function testEdit() /** * Tests the edit method - failure * - * @expectedException \DomainException - * * @return void */ public function testEditFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -223,12 +223,12 @@ public function testGetListWithNamespace() /** * Tests the getList method - failure * - * @expectedException \DomainException - * * @return void */ public function testGetListFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -266,12 +266,12 @@ public function testDelete() /** * Tests the delete method - failure * - * @expectedException \DomainException - * * @return void */ public function testDeleteFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; diff --git a/Tests/Package/Data/TagsTest.php b/Tests/Package/Data/TagsTest.php index 0cba7844..52025471 100644 --- a/Tests/Package/Data/TagsTest.php +++ b/Tests/Package/Data/TagsTest.php @@ -30,7 +30,7 @@ class TagsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Data/TreesTest.php b/Tests/Package/Data/TreesTest.php index 62a299b1..f87a9b30 100644 --- a/Tests/Package/Data/TreesTest.php +++ b/Tests/Package/Data/TreesTest.php @@ -30,7 +30,7 @@ class TreesTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/DataTest.php b/Tests/Package/DataTest.php index 82f11eb6..38428257 100644 --- a/Tests/Package/DataTest.php +++ b/Tests/Package/DataTest.php @@ -31,7 +31,7 @@ class DataTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/EmojisTest.php b/Tests/Package/EmojisTest.php index 47809dcb..34ef39d0 100755 --- a/Tests/Package/EmojisTest.php +++ b/Tests/Package/EmojisTest.php @@ -29,7 +29,7 @@ class EmojisTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/GistsTest.php b/Tests/Package/GistsTest.php index 7c48a6ef..9c209168 100755 --- a/Tests/Package/GistsTest.php +++ b/Tests/Package/GistsTest.php @@ -29,7 +29,7 @@ class GistsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -113,12 +113,12 @@ public function testCreateGistFromFile() /** * Tests the create method loading file content from a file - file does not exist * - * @expectedException \InvalidArgumentException - * * @return void */ public function testCreateGistFromFileNotFound() { + $this->expectException(\InvalidArgumentException::class); + $this->response->code = 501; $this->object->create( diff --git a/Tests/Package/GitignoreTest.php b/Tests/Package/GitignoreTest.php index 6bda3021..37cd83e4 100644 --- a/Tests/Package/GitignoreTest.php +++ b/Tests/Package/GitignoreTest.php @@ -29,7 +29,7 @@ class GitignoreTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -137,13 +137,13 @@ public function testGetRaw() /** * Tests the get method with failure. * - * @expectedException \DomainException - * * @since 1.0 * @return void */ public function testGetFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 404; $this->response->body = '{"message":"Not found"}'; diff --git a/Tests/Package/GraphqlTest.php b/Tests/Package/GraphqlTest.php index e1c874e1..a174ddaf 100644 --- a/Tests/Package/GraphqlTest.php +++ b/Tests/Package/GraphqlTest.php @@ -29,7 +29,7 @@ class GraphqlTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Issues/AssigneesTest.php b/Tests/Package/Issues/AssigneesTest.php index 54991da1..5740f3d0 100644 --- a/Tests/Package/Issues/AssigneesTest.php +++ b/Tests/Package/Issues/AssigneesTest.php @@ -42,7 +42,7 @@ class AssigneesTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -139,12 +139,12 @@ public function testCheckNo() * a 204 header with no content is returned. * Otherwise a 404 status code is returned. * - * @expectedException \DomainException - * * @return void */ public function testCheckException() { + $this->expectException(\DomainException::class); + $this->response->code = 666; $this->response->body = ''; diff --git a/Tests/Package/Issues/CommentsTest.php b/Tests/Package/Issues/CommentsTest.php index 5525540e..40bb83ca 100644 --- a/Tests/Package/Issues/CommentsTest.php +++ b/Tests/Package/Issues/CommentsTest.php @@ -30,7 +30,7 @@ class CommentsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -76,22 +76,24 @@ public function testGetRepositoryList() /** * Tests the getRepositoryListInvalidSort method * - * @expectedException \UnexpectedValueException * @return void */ public function testGetRepositoryListInvalidSort() { + $this->expectException(\UnexpectedValueException::class); + $this->object->getRepositoryList('joomla', 'joomla-platform', 'invalid'); } /** * Tests the getRepositoryListInvalidDirection method * - * @expectedException \UnexpectedValueException * @return void */ public function testGetRepositoryListInvalidDirection() { + $this->expectException(\UnexpectedValueException::class); + $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'invalid'); } diff --git a/Tests/Package/Issues/EventsTest.php b/Tests/Package/Issues/EventsTest.php index e9cc20a2..b41f6ed6 100644 --- a/Tests/Package/Issues/EventsTest.php +++ b/Tests/Package/Issues/EventsTest.php @@ -30,7 +30,7 @@ class EventsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Issues/LabelsTest.php b/Tests/Package/Issues/LabelsTest.php index 0fb54c51..cf7170b1 100644 --- a/Tests/Package/Issues/LabelsTest.php +++ b/Tests/Package/Issues/LabelsTest.php @@ -30,7 +30,7 @@ class LabelsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -96,11 +96,12 @@ public function testCreate() /** * Tests the createFailure method * - * @expectedException \DomainException * @return void */ public function testCreateFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 404; $this->response->body = $this->errorString; diff --git a/Tests/Package/Issues/MilestonesTest.php b/Tests/Package/Issues/MilestonesTest.php index d3e7f89f..54b8f212 100644 --- a/Tests/Package/Issues/MilestonesTest.php +++ b/Tests/Package/Issues/MilestonesTest.php @@ -30,7 +30,7 @@ class MilestonesTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -66,14 +66,14 @@ public function testCreate() /** * Tests the create method - failure * - * @expectedException \DomainException - * * @return void * * @since 12.3 */ public function testCreateFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 501; $this->response->body = $this->errorString; @@ -141,14 +141,14 @@ public function testEditAllParameters() /** * Tests the edit method - failure * - * @expectedException \DomainException - * * @return void * * @since 12.3 */ public function testEditFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -186,14 +186,14 @@ public function testGet() /** * Tests the get method - failure * - * @expectedException \DomainException - * * @return void * * @since 12.3 */ public function testGetFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -228,14 +228,14 @@ public function testGetList() /** * Tests the getList method - failure * - * @expectedException \DomainException - * * @return void * * @since 12.3 */ public function testGetListFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -269,14 +269,14 @@ public function testDelete() /** * Tests the delete method - failure * - * @expectedException \DomainException - * * @return void * * @since 12.3 */ public function testDeleteFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 504; $this->response->body = $this->errorString; diff --git a/Tests/Package/IssuesTest.php b/Tests/Package/IssuesTest.php index 094a8869..5aae9e4e 100755 --- a/Tests/Package/IssuesTest.php +++ b/Tests/Package/IssuesTest.php @@ -32,7 +32,7 @@ class IssuesTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -104,12 +104,12 @@ public function testCreate2() * * Failure * - * @expectedException \DomainException - * * @return void */ public function testCreateFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 501; $this->response->body = $this->errorString; @@ -160,12 +160,12 @@ public function testCreateComment() * * Failure * - * @expectedException \DomainException - * * @return void */ public function testCreateCommentFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 501; $this->response->body = $this->errorString; @@ -217,12 +217,12 @@ public function testEdit() * * Failure * - * @expectedException \DomainException - * * @return void */ public function testEditFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -266,12 +266,12 @@ public function testGet() * * Failure * - * @expectedException \DomainException - * * @return void */ public function testGetFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -332,12 +332,12 @@ public function testGetListAll() * * Failure * - * @expectedException \DomainException - * * @return void */ public function testGetListFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -414,12 +414,12 @@ public function testGetListByRepositoryAll() * * Failure * - * @expectedException \DomainException - * * @return void */ public function testGetListByRepositoryFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -460,12 +460,12 @@ public function testLock() * * Failure * - * @expectedException \DomainException - * * @return void */ public function testLockFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -506,12 +506,12 @@ public function testUnlock() * * Failure * - * @expectedException \DomainException - * * @return void */ public function testUnlockFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; diff --git a/Tests/Package/MarkdownTest.php b/Tests/Package/MarkdownTest.php index b95aa4e0..258b28e7 100644 --- a/Tests/Package/MarkdownTest.php +++ b/Tests/Package/MarkdownTest.php @@ -29,7 +29,7 @@ class MarkdownTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -78,11 +78,11 @@ public function testRender() * Tests the renderInvalidMode method * * @return void - * - * @expectedException \InvalidArgumentException */ public function testRenderInvalidMode() { + $this->expectException(\InvalidArgumentException::class); + $this->assertThat( $this->object->render('', 'xxx', 'github/gollum'), $this->equalTo('') @@ -93,11 +93,11 @@ public function testRenderInvalidMode() * Tests the renderFailure method * * @return void - * - * @expectedException \DomainException */ public function testRenderFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 404; $this->response->body = ''; diff --git a/Tests/Package/MetaTest.php b/Tests/Package/MetaTest.php index 85819281..0cfe7c90 100644 --- a/Tests/Package/MetaTest.php +++ b/Tests/Package/MetaTest.php @@ -36,7 +36,7 @@ class MetaTest extends GitHubTestCase * * @since 1.0 */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -73,11 +73,11 @@ public function testGetMeta() * @return void * * @since 1.0 - * - * @expectedException \DomainException */ public function testGetMetaFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; diff --git a/Tests/Package/Orgs/HooksTest.php b/Tests/Package/Orgs/HooksTest.php index fe387c3f..2b678be5 100644 --- a/Tests/Package/Orgs/HooksTest.php +++ b/Tests/Package/Orgs/HooksTest.php @@ -31,7 +31,7 @@ class HooksTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -106,12 +106,12 @@ public function testCreate() * @covers \Joomla\Github\Package\Orgs\Hooks::create() * * @return void - * - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage Content type must be either "form" or "json". */ public function testCreateFailure() { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Content type must be either "form" or "json"'); + $this->object->create('joomla', '{url}', '{invalid}'); } @@ -121,12 +121,12 @@ public function testCreateFailure() * @covers \Joomla\Github\Package\Orgs\Hooks::create() * * @return void - * - * @expectedException \RuntimeException - * @expectedExceptionMessage Your events array contains an unauthorized event. */ public function testCreateInvalidEvent() { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Your events array contains an unauthorized event.'); + $this->object->create('{org}', '{url}', 'form', null, false, ['{invalid}']); } @@ -158,11 +158,11 @@ public function testEdit() * @covers \Joomla\Github\Package\Orgs\Hooks::edit() * * @return void - * - * @expectedException \UnexpectedValueException */ public function testEditFailure() { + $this->expectException(\UnexpectedValueException::class); + $this->object->edit('{org}', '{url}', '{invalid}'); } @@ -172,11 +172,11 @@ public function testEditFailure() * @covers \Joomla\Github\Package\Orgs\Hooks::edit() * * @return void - * - * @expectedException \RuntimeException */ public function testEditFailure2() { + $this->expectException(\RuntimeException::class); + $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, array('{invalid}')); } diff --git a/Tests/Package/Orgs/MembersTest.php b/Tests/Package/Orgs/MembersTest.php index a2b99700..8db4eb04 100644 --- a/Tests/Package/Orgs/MembersTest.php +++ b/Tests/Package/Orgs/MembersTest.php @@ -4,7 +4,7 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -namespace Joomla\Github\Tests; +namespace Joomla\Github\Tests\Package\Orgs; use Joomla\Github\Package\Orgs\Members; use Joomla\Github\Tests\Stub\GitHubTestCase; @@ -31,7 +31,7 @@ class MembersTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -86,11 +86,11 @@ public function testGetListNotAMember() * @covers \Joomla\Github\Package\Orgs\Members::getList() * * @return void - * - * @expectedException \UnexpectedValueException */ public function testGetListUnexpected() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->client->expects($this->once()) @@ -176,11 +176,11 @@ public function testCheckRequesterNoMember() * @covers \Joomla\Github\Package\Orgs\Members::check() * * @return void - * - * @expectedException \UnexpectedValueException */ public function testCheckUnexpectedr() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->client->expects($this->once()) @@ -286,11 +286,11 @@ public function testCheckPublicNo() * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() * * @return void - * - * @expectedException \UnexpectedValueException */ public function testCheckPublicUnexpected() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->client->expects($this->once()) @@ -394,12 +394,12 @@ public function testUpdateMembership() * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() * * @return void - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The user's role must be: member, admin */ public function testUpdateMembershipInvalidRole() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The user's role must be: member, admin"); + $this->object->updateMembership('{org}', '{user}', 'INVALID'); } @@ -491,12 +491,12 @@ public function testEditOrganizationMemberships() * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() * * @return void - * - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The state must be "active". */ public function testEditOrganizationMembershipsInvalidState() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The state must be "active".'); + $this->object->editOrganizationMembership('{org}', 'INVALID'); } } diff --git a/Tests/Package/Orgs/TeamsTest.php b/Tests/Package/Orgs/TeamsTest.php index 09a5d853..cf7bae6c 100644 --- a/Tests/Package/Orgs/TeamsTest.php +++ b/Tests/Package/Orgs/TeamsTest.php @@ -31,7 +31,7 @@ class TeamsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -106,11 +106,11 @@ public function testCreate() * @covers \Joomla\Github\Package\Orgs\Teams::create() * * @return void - * - * @expectedException \UnexpectedValueException */ public function testCreateWrongPermission() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 201; $this->object->create('joomla', 'TheTeam', array('joomla-platform'), 'invalid'); @@ -142,11 +142,11 @@ public function testEdit() * @covers \Joomla\Github\Package\Orgs\Teams::edit() * * @return void - * - * @expectedException \UnexpectedValueException */ public function testEditWrongPermission() { + $this->expectException(\UnexpectedValueException::class); + $this->object->edit(123, 'TheTeam', 'invalid'); } @@ -248,11 +248,11 @@ public function testIsMemberNo() * @deprecated * * @return void - * - * @expectedException \UnexpectedValueException */ public function testIsMemberUnexpected() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->client->expects($this->once()) @@ -384,11 +384,11 @@ public function testCheckRepoNo() * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() * * @return void - * - * @expectedException \UnexpectedValueException */ public function testCheckRepoUnexpected() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->client->expects($this->once()) @@ -502,12 +502,12 @@ public function testGetTeamMembershipsFailure1() * Unexpected Response * * @return void - * - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage Unexpected response code: 666 */ public function testGetTeamMembershipsFailure2() { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Unexpected response code: 666'); + $this->response->code = 666; $this->response->body = '{"state":"TEST"}'; @@ -550,12 +550,12 @@ public function testAddTeamMemberships() * Invalid role * * @return void - * - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage Roles must be either "member" or "maintainer". */ public function testAddTeamMembershipsFailure() { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Roles must be either "member" or "maintainer".'); + $this->object->addTeamMembership(123, '{user}', 'INVALID'); } diff --git a/Tests/Package/OrgsTest.php b/Tests/Package/OrgsTest.php index c6c5bc21..62df4605 100644 --- a/Tests/Package/OrgsTest.php +++ b/Tests/Package/OrgsTest.php @@ -29,7 +29,7 @@ class OrgsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Pulls/CommentsTest.php b/Tests/Package/Pulls/CommentsTest.php index 20e58855..fb7bcde5 100644 --- a/Tests/Package/Pulls/CommentsTest.php +++ b/Tests/Package/Pulls/CommentsTest.php @@ -31,7 +31,7 @@ class CommentsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/PullsTest.php b/Tests/Package/PullsTest.php index 9603edcd..9fb6a694 100755 --- a/Tests/Package/PullsTest.php +++ b/Tests/Package/PullsTest.php @@ -29,7 +29,7 @@ class JGithubPackagePullsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -67,12 +67,12 @@ public function testCreate() /** * Tests the create method - failure * - * @expectedException \DomainException - * * @return void */ public function testCreateFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 501; $this->response->body = $this->errorString; @@ -120,12 +120,12 @@ public function testCreateFromIssue() /** * Tests the createFromIssue method - failure * - * @expectedException \DomainException - * * @return void */ public function testCreateFromIssueFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 501; $this->response->body = $this->errorString; @@ -169,12 +169,12 @@ public function testEdit() /** * Tests the edit method - failure * - * @expectedException \DomainException - * * @return void */ public function testEditFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -211,12 +211,12 @@ public function testGet() /** * Tests the get method - failure * - * @expectedException \DomainException - * * @return void */ public function testGetFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -249,12 +249,12 @@ public function testGetCommits() /** * Tests the getCommits method - failure * - * @expectedException \DomainException - * * @return void */ public function testGetCommitsFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -287,12 +287,12 @@ public function testGetFiles() /** * Tests the getFiles method - failure * - * @expectedException \DomainException - * * @return void */ public function testGetFilesFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -325,12 +325,12 @@ public function testGetList() /** * Tests the getList method - failure * - * @expectedException \DomainException - * * @return void */ public function testGetListFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -385,12 +385,12 @@ public function testIsMergedFalse() /** * Tests the isMerged method when the request fails * - * @expectedException \DomainException - * * @return void */ public function testIsMergedFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 504; $this->response->body = $this->errorString; @@ -423,12 +423,12 @@ public function testMerge() /** * Tests the merge method - failure * - * @expectedException \DomainException - * * @return void */ public function testMergeFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; diff --git a/Tests/Package/Repositories/BranchesTest.php b/Tests/Package/Repositories/BranchesTest.php index f3601266..51ca67e5 100644 --- a/Tests/Package/Repositories/BranchesTest.php +++ b/Tests/Package/Repositories/BranchesTest.php @@ -31,7 +31,7 @@ class BranchesTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Repositories/CollaboratorsTest.php b/Tests/Package/Repositories/CollaboratorsTest.php index 458d7f17..852b23b3 100644 --- a/Tests/Package/Repositories/CollaboratorsTest.php +++ b/Tests/Package/Repositories/CollaboratorsTest.php @@ -29,7 +29,7 @@ class CollaboratorsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -100,11 +100,11 @@ public function testGetNegative() * Tests the GetUnexpected method. * * @return void - * - * @expectedException \UnexpectedValueException */ public function testGetUnexpected() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->response->body = null; diff --git a/Tests/Package/Repositories/CommentsTest.php b/Tests/Package/Repositories/CommentsTest.php index e9633fa3..1619d3cd 100644 --- a/Tests/Package/Repositories/CommentsTest.php +++ b/Tests/Package/Repositories/CommentsTest.php @@ -29,7 +29,7 @@ class CommentsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Repositories/CommitsTest.php b/Tests/Package/Repositories/CommitsTest.php index b4c7da1d..28421dcc 100644 --- a/Tests/Package/Repositories/CommitsTest.php +++ b/Tests/Package/Repositories/CommitsTest.php @@ -8,6 +8,7 @@ use Joomla\Github\Package\Repositories\Commits; use Joomla\Github\Tests\Stub\GitHubTestCase; +use Joomla\Http\Exception\UnexpectedResponseException; /** * Test class. @@ -32,7 +33,7 @@ class CommitsTest extends GitHubTestCase * * @since 1.0 */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -69,12 +70,12 @@ public function testGet() * @return void * * @since 1.0 - * - * @expectedException \DomainException - * @expectedExceptionMessage Generic Error */ public function testGetFailure() { + $this->expectException(\DomainException::class); + $this->expectExceptionMessage('Generic Error'); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -116,12 +117,12 @@ public function testGetList() * @return void * * @since 1.0 - * - * @expectedException \DomainException - * @expectedExceptionMessage Generic Error */ public function testGetListFailure() { + $this->expectException(\DomainException::class); + $this->expectExceptionMessage('Generic Error'); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -185,12 +186,12 @@ public function testgetSha() * @return void * * @since 1.0 - * - * @expectedException \Joomla\Http\Exception\UnexpectedResponseException - * @expectedExceptionMessage Invalid response received from GitHub. */ public function testgetShaFailure() { + $this->expectException(UnexpectedResponseException::class); + $this->expectExceptionMessage('Invalid response received from GitHub.'); + $this->response->code = 666; $this->client->expects($this->once()) diff --git a/Tests/Package/Repositories/ContentsTest.php b/Tests/Package/Repositories/ContentsTest.php index f8b88c61..7caa70c8 100644 --- a/Tests/Package/Repositories/ContentsTest.php +++ b/Tests/Package/Repositories/ContentsTest.php @@ -29,7 +29,7 @@ class ContentsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -152,11 +152,11 @@ public function testGetArchiveLinkRef() * Tests the GetArchiveLinkInvalidFormat method. * * @return void - * - * @expectedException \UnexpectedValueException */ public function testGetArchiveLinkInvalidFormat() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 302; $this->object->getArchiveLink('joomla', 'joomla-platform', 'invalid'); @@ -188,12 +188,12 @@ public function testCreate() /** * Tests the create method with missing author e-mail. * - * @expectedException \UnexpectedValueException - * * @return void */ public function testCreateFail1() { + $this->expectException(\UnexpectedValueException::class); + $this->object->create( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', 'eddieajau', '', 'elkuku', 'elkuku@example.com' @@ -203,12 +203,12 @@ public function testCreateFail1() /** * Tests the create method with missing committer e-mail. * - * @expectedException \UnexpectedValueException - * * @return void */ public function testCreateFail2() { + $this->expectException(\UnexpectedValueException::class); + $this->object->create( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', 'eddieajau', 'eddieajau@example.com', 'elkuku', '' @@ -239,12 +239,12 @@ public function testUpdate() /** * Tests the update method with missing author e-mail. * - * @expectedException \UnexpectedValueException - * * @return void */ public function testUpdateFail1() { + $this->expectException(\UnexpectedValueException::class); + $this->object->update( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', 'eddieajau', '', 'elkuku', 'elkuku@example.com' @@ -254,12 +254,12 @@ public function testUpdateFail1() /** * Tests the update method with missing committer e-mail. * - * @expectedException \UnexpectedValueException - * * @return void */ public function testUpdateFail2() { + $this->expectException(\UnexpectedValueException::class); + $this->object->update( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', 'eddieajau', 'eddieajau@example.com', 'elkuku', '' @@ -290,12 +290,12 @@ public function testDelete() /** * Tests the delete method with missing author e-mail. * - * @expectedException \UnexpectedValueException - * * @return void */ public function testDeleteFail1() { + $this->expectException(\UnexpectedValueException::class); + $this->object->delete( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', 'eddieajau', '', 'elkuku', 'elkuku@example.com' @@ -305,12 +305,12 @@ public function testDeleteFail1() /** * Tests the update method with missing committer e-mail. * - * @expectedException \UnexpectedValueException - * * @return void */ public function testDeleteFail2() { + $this->expectException(\UnexpectedValueException::class); + $this->object->delete( 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', 'eddieajau', 'eddieajau@example.com', 'elkuku', '' diff --git a/Tests/Package/Repositories/DeploymentsTest.php b/Tests/Package/Repositories/DeploymentsTest.php index 8bab8332..b7b4d601 100644 --- a/Tests/Package/Repositories/DeploymentsTest.php +++ b/Tests/Package/Repositories/DeploymentsTest.php @@ -29,7 +29,7 @@ class DeploymentsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -80,12 +80,12 @@ public function testCreate() /** * Tests the Create method. * - * @expectedException \RuntimeException - * * @return void */ public function testCreateMergeConflict() { + $this->expectException(\RuntimeException::class); + $this->response->code = 409; $this->client->expects($this->once()) @@ -102,12 +102,12 @@ public function testCreateMergeConflict() /** * Tests the Create method. * - * @expectedException \UnexpectedValueException - * * @return void */ public function testCreateFailure() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->client->expects($this->once()) @@ -162,12 +162,12 @@ public function testCreateStatus() /** * Tests the CreateStatus method. * - * @expectedException \InvalidArgumentException - * * @return void */ public function testCreateStatusFailure() { + $this->expectException(\InvalidArgumentException::class); + $this->object->createStatus('{owner}', '{repo}', 123, '{invalid}'); } } diff --git a/Tests/Package/Repositories/DownloadsTest.php b/Tests/Package/Repositories/DownloadsTest.php index 3d5f5ea8..f9f19225 100644 --- a/Tests/Package/Repositories/DownloadsTest.php +++ b/Tests/Package/Repositories/DownloadsTest.php @@ -29,7 +29,7 @@ class DownloadsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -76,12 +76,12 @@ public function testGet() * Tests the Create method. * * @return void - * - * @expectedException \RuntimeException - * @expectedExceptionMessage The GitHub API no longer supports creating downloads. The Releases API should be used instead. */ public function testCreate() { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); + $this->object->create('joomla', 'joomla-platform', 'aaa.zip', 1234, 'Description', 'content_type'); } @@ -89,12 +89,12 @@ public function testCreate() * Tests the Upload method. * * @return void - * - * @expectedException \RuntimeException - * @expectedExceptionMessage The GitHub API no longer supports creating downloads. The Releases API should be used instead. */ public function testUpload() { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); + $this->object->upload( 'joomla', 'joomla-platform', 123, 'a/b/aaa.zip', 'acl', 201, 'aaa.zip', '123abc', '123abc', '123abc', 'content_type', '@aaa.zip' ); diff --git a/Tests/Package/Repositories/ForksTest.php b/Tests/Package/Repositories/ForksTest.php index c56f0199..30eb2580 100755 --- a/Tests/Package/Repositories/ForksTest.php +++ b/Tests/Package/Repositories/ForksTest.php @@ -30,7 +30,7 @@ class ForksTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -67,12 +67,12 @@ public function testCreate() /** * Tests the create method - failure * - * @expectedException \DomainException - * * @return void */ public function testCreateFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -110,12 +110,12 @@ public function testGetList() /** * Tests the getList method - failure * - * @expectedException \DomainException - * * @return void */ public function testGetListFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; diff --git a/Tests/Package/Repositories/HooksTest.php b/Tests/Package/Repositories/HooksTest.php index d63df66f..900e1a24 100644 --- a/Tests/Package/Repositories/HooksTest.php +++ b/Tests/Package/Repositories/HooksTest.php @@ -32,7 +32,7 @@ class HooksTest extends GitHubTestCase * * @since 1.0 */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -123,11 +123,11 @@ public function testCreateFailure() * @return void * * @since 1.0 - * - * @expectedException \RuntimeException */ public function testCreateUnauthorisedEvent() { + $this->expectException(\RuntimeException::class); + $this->object->create('joomla', 'joomla-platform', 'acunote', array('token' => '123456789'), array('push', 'faker')); } @@ -281,11 +281,11 @@ public function testEditFailure() * @return void * * @since 1.0 - * - * @expectedException \RuntimeException */ public function testEditUnauthorisedEvent() { + $this->expectException(\RuntimeException::class); + $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('invalid')); } @@ -299,11 +299,11 @@ public function testEditUnauthorisedEvent() * @return void * * @since 1.0 - * - * @expectedException \RuntimeException */ public function testEditUnauthorisedAddEvent() { + $this->expectException(\RuntimeException::class); + $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('push'), array('invalid')); } @@ -317,11 +317,11 @@ public function testEditUnauthorisedAddEvent() * @return void * * @since 1.0 - * - * @expectedException \RuntimeException */ public function testEditUnauthorisedRemoveEvent() { + $this->expectException(\RuntimeException::class); + $this->object->edit( 'joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('push'), array('push'), array('invalid') ); @@ -359,11 +359,11 @@ public function testGet() * @return void * * @since 1.0 - * - * @expectedException \DomainException */ public function testGetFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -407,11 +407,11 @@ public function testGetList() * @return void * * @since 1.0 - * - * @expectedException \DomainException */ public function testGetListFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; @@ -457,11 +457,11 @@ public function testTest() * @return void * * @since 1.0 - * - * @expectedException \DomainException */ public function testTestFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; diff --git a/Tests/Package/Repositories/KeysTest.php b/Tests/Package/Repositories/KeysTest.php index 0baccb59..17cdda38 100644 --- a/Tests/Package/Repositories/KeysTest.php +++ b/Tests/Package/Repositories/KeysTest.php @@ -29,7 +29,7 @@ class KeysTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Repositories/MergingTest.php b/Tests/Package/Repositories/MergingTest.php index 869c06b0..a9a7e11d 100644 --- a/Tests/Package/Repositories/MergingTest.php +++ b/Tests/Package/Repositories/MergingTest.php @@ -30,7 +30,7 @@ class MergingTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -61,11 +61,11 @@ public function testPerform() * Tests the Perform method. * * @return void - * - * @expectedException \UnexpectedValueException */ public function testPerformNoOp() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 204; $this->client->expects($this->once()) @@ -82,12 +82,12 @@ public function testPerformNoOp() /** * Tests the Perform method. * - * @expectedException \UnexpectedValueException - * * @return void */ public function testPerformMissing() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 404; $this->client->expects($this->once()) @@ -104,12 +104,12 @@ public function testPerformMissing() /** * Tests the Perform method. * - * @expectedException \UnexpectedValueException - * * @return void */ public function testPerformConflict() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 409; $this->client->expects($this->once()) @@ -126,12 +126,12 @@ public function testPerformConflict() /** * Tests the Perform method. * - * @expectedException \UnexpectedValueException - * * @return void */ public function testPerformUnexpected() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->client->expects($this->once()) diff --git a/Tests/Package/Repositories/PagesTest.php b/Tests/Package/Repositories/PagesTest.php index 196d59f4..72f68635 100644 --- a/Tests/Package/Repositories/PagesTest.php +++ b/Tests/Package/Repositories/PagesTest.php @@ -29,7 +29,7 @@ class PagesTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Repositories/ReleasesTest.php b/Tests/Package/Repositories/ReleasesTest.php index 02eda981..36d581c3 100644 --- a/Tests/Package/Repositories/ReleasesTest.php +++ b/Tests/Package/Repositories/ReleasesTest.php @@ -30,7 +30,7 @@ class ReleasesTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Repositories/StatisticsTest.php b/Tests/Package/Repositories/StatisticsTest.php index 681c385d..2ae46b21 100644 --- a/Tests/Package/Repositories/StatisticsTest.php +++ b/Tests/Package/Repositories/StatisticsTest.php @@ -30,7 +30,7 @@ class StatisticsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -130,11 +130,12 @@ public function testPunchCard() /** * Tests the ProcessResponse method with failure. * - * @expectedException \DomainException * @return void */ public function testProcessResponse202() { + $this->expectException(\DomainException::class); + $this->response->code = 202; $this->client->expects($this->once()) diff --git a/Tests/Package/Repositories/StatusesTest.php b/Tests/Package/Repositories/StatusesTest.php index 2d666d81..0ffa6d6d 100755 --- a/Tests/Package/Repositories/StatusesTest.php +++ b/Tests/Package/Repositories/StatusesTest.php @@ -32,7 +32,7 @@ class StatusesTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -86,12 +86,12 @@ public function testCreate() * * Failure * - * @expectedException \DomainException - * * @return void */ public function testCreateFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 501; $this->response->body = $this->errorString; @@ -117,12 +117,12 @@ public function testCreateFailure() * * Failure * - * @expectedException \InvalidArgumentException - * * @return void */ public function testCreateInvalidState() { + $this->expectException(\InvalidArgumentException::class); + $this->response->code = 501; $this->response->body = $this->errorString; @@ -156,12 +156,12 @@ public function testGetList() * * Failure * - * @expectedException \DomainException - * * @return void */ public function testGetListFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 500; $this->response->body = $this->errorString; diff --git a/Tests/Package/RepositoriesTest.php b/Tests/Package/RepositoriesTest.php index 474b694d..4818442e 100644 --- a/Tests/Package/RepositoriesTest.php +++ b/Tests/Package/RepositoriesTest.php @@ -29,7 +29,7 @@ class RepositoriesTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -57,36 +57,36 @@ public function testGetListOwn() /** * Tests the GetListOwn method. * - * @expectedException \RuntimeException - * * @return void */ public function testGetListOwnInvalidType() { + $this->expectException(\RuntimeException::class); + $this->object->getListOwn('INVALID'); } /** * Tests the GetListOwn method. * - * @expectedException \RuntimeException - * * @return void */ public function testGetListOwnInvalidSortField() { + $this->expectException(\RuntimeException::class); + $this->object->getListOwn('all', 'INVALID'); } /** * Tests the GetListOwn method. * - * @expectedException \RuntimeException - * * @return void */ public function testGetListOwnInvalidSortOrder() { + $this->expectException(\RuntimeException::class); + $this->object->getListOwn('all', 'full_name', 'INVALID'); } @@ -111,36 +111,36 @@ public function testGetListUser() /** * Tests the GetListUser method. * - * @expectedException \RuntimeException - * * @return void */ public function testGetListUserInvalidType() { + $this->expectException(\RuntimeException::class); + $this->object->getListUser('joomla', 'INVALID'); } /** * Tests the GetListUser method. * - * @expectedException \RuntimeException - * * @return void */ public function testGetListUserInvalidSortField() { + $this->expectException(\RuntimeException::class); + $this->object->getListUser('joomla', 'all', 'INVALID'); } /** * Tests the GetListUser method. * - * @expectedException \RuntimeException - * * @return void */ public function testGetListUserInvalidSortOrder() { + $this->expectException(\RuntimeException::class); + $this->object->getListUser('joomla', 'all', 'full_name', 'INVALID'); } @@ -249,12 +249,12 @@ public function testGet() /** * Tests the GetListOrg method. * - * @expectedException \RuntimeException - * * @return void */ public function testGetListOrgInvalidType() { + $this->expectException(\RuntimeException::class); + $this->object->getListOrg('joomla', 'INVALID'); } diff --git a/Tests/Package/SearchTest.php b/Tests/Package/SearchTest.php index e7808fd5..ac37a4a2 100644 --- a/Tests/Package/SearchTest.php +++ b/Tests/Package/SearchTest.php @@ -29,7 +29,7 @@ class SearchTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -58,11 +58,11 @@ public function testIssues() * Tests the issuesInvalidState method * * @return void - * - * @expectedException \UnexpectedValueException */ public function testIssuesInvalidState() { + $this->expectException(\UnexpectedValueException::class); + $this->object->issues('joomla', 'joomla-platform', 'invalid', 'github'); } diff --git a/Tests/Package/Users/EmailsTest.php b/Tests/Package/Users/EmailsTest.php index 1a842df2..982ec265 100644 --- a/Tests/Package/Users/EmailsTest.php +++ b/Tests/Package/Users/EmailsTest.php @@ -29,7 +29,7 @@ class EmailsTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/Users/FollowersTest.php b/Tests/Package/Users/FollowersTest.php index 12b5a373..4057ab28 100644 --- a/Tests/Package/Users/FollowersTest.php +++ b/Tests/Package/Users/FollowersTest.php @@ -31,7 +31,7 @@ class FollowersTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -174,11 +174,11 @@ public function testCheckNo() * @covers \Joomla\Github\Package\Users\Followers::check() * * @return void - * - * @expectedException \UnexpectedValueException */ public function testCheckUnexpected() { + $this->expectException(\UnexpectedValueException::class); + $this->response->code = 666; $this->response->body = false; @@ -301,12 +301,12 @@ public function testCheckUserFollowingNot() * @return void * * @since 1.0 - * - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage Unexpected response code: 666 */ public function testCheckUserFollowingUnexpected() { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Unexpected response code: 666'); + $this->response->code = 666; $this->client->expects($this->once()) diff --git a/Tests/Package/Users/KeysTest.php b/Tests/Package/Users/KeysTest.php index bb16bd8c..77959e27 100644 --- a/Tests/Package/Users/KeysTest.php +++ b/Tests/Package/Users/KeysTest.php @@ -29,7 +29,7 @@ class KeysTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/Tests/Package/UsersTest.php b/Tests/Package/UsersTest.php index abc0bd1e..39473816 100755 --- a/Tests/Package/UsersTest.php +++ b/Tests/Package/UsersTest.php @@ -29,7 +29,7 @@ class UsersTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -80,11 +80,12 @@ public function testGet() /** * Tests the getUser method with failure * - * @expectedException \DomainException * @return void */ public function testGetFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 404; $this->response->body = '{"message":"Not Found"}'; @@ -154,12 +155,12 @@ public function testGetAuthenticatedUser() /** * Tests the GetAuthenticatedUser method with failure * - * @expectedException \DomainException - * * @return void */ public function testGetAuthenticatedUserFailure() { + $this->expectException(\DomainException::class); + $this->response->code = 401; $this->response->body = '{"message":"Requires authentication"}'; @@ -286,12 +287,12 @@ public function testEdit() /** * Tests the getUsers method * - * @expectedException \DomainException - * * @return void */ public function testEditFailure() { + $this->expectException(\DomainException::class); + $name = 'monalisa octocat'; $email = 'octocat@github.com'; $blog = 'https =>//github.com/blog'; diff --git a/Tests/Package/ZenTest.php b/Tests/Package/ZenTest.php index 7984307e..f7dacefa 100644 --- a/Tests/Package/ZenTest.php +++ b/Tests/Package/ZenTest.php @@ -29,7 +29,7 @@ class ZenTest extends GitHubTestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -60,12 +60,12 @@ public function testGet() /** * Tests the Get method. * - * @expectedException \RuntimeException - * * @return void */ public function testGetFailure() { + $this->expectException(\RuntimeException::class); + $this->response->code = 400; $this->response->body = 'My Zen'; diff --git a/Tests/PackageTest.php b/Tests/PackageTest.php index e691f030..a9226497 100755 --- a/Tests/PackageTest.php +++ b/Tests/PackageTest.php @@ -30,7 +30,7 @@ class PackageTest extends GitHubTestCase * * @since 1.0 */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -58,11 +58,11 @@ public function testGet() * @return void * * @since 1.0 - * - * @expectedException \InvalidArgumentException */ public function testGetInvalid() { + $this->expectException(\InvalidArgumentException::class); + $this->object->repositories->INVALID; } } diff --git a/Tests/Stub/GitHubTestCase.php b/Tests/Stub/GitHubTestCase.php index fdc00ca5..fc5b6f20 100644 --- a/Tests/Stub/GitHubTestCase.php +++ b/Tests/Stub/GitHubTestCase.php @@ -54,7 +54,7 @@ abstract class GitHubTestCase extends TestCase * * @return void */ - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/composer.json b/composer.json index 4788dd3d..3065cbed 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ }, "require-dev": { "joomla/coding-standards": "~2.0@alpha", - "phpunit/phpunit": "~6.3" + "phpunit/phpunit": "~8.2" }, "autoload": { "psr-4": { From dd2a86c2657f29c00979ea7aa26ba49e978ad8fe Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Tue, 3 Dec 2019 19:55:37 -0600 Subject: [PATCH 39/79] Set minimum PHP version to 7.2.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3065cbed..aab5acb0 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "https://github.com/joomla-framework/github-api", "license": "GPL-2.0-or-later", "require": { - "php": "~7.2", + "php": "^7.2.5", "joomla/http": "~1.3|~2.0", "joomla/registry": "^1.4.5|~2.0", "joomla/uri": "~1.0|~2.0" From 0d12689530f85e17ae9b14c76be776685be106e1 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 7 Mar 2020 17:30:16 -0600 Subject: [PATCH 40/79] Support PHPUnit 9 --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index aab5acb0..c5186fe0 100644 --- a/composer.json +++ b/composer.json @@ -7,13 +7,13 @@ "license": "GPL-2.0-or-later", "require": { "php": "^7.2.5", - "joomla/http": "~1.3|~2.0", - "joomla/registry": "^1.4.5|~2.0", - "joomla/uri": "~1.0|~2.0" + "joomla/http": "^1.3|^2.0", + "joomla/registry": "^1.4.5|^2.0", + "joomla/uri": "^1.0|^2.0" }, "require-dev": { - "joomla/coding-standards": "~2.0@alpha", - "phpunit/phpunit": "~8.2" + "joomla/coding-standards": "^2.0@alpha", + "phpunit/phpunit": "^8.5|^9.0" }, "autoload": { "psr-4": { From b1a044d5a37031081a32027896b117c124c8d92e Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Mon, 14 Sep 2020 12:47:57 +0200 Subject: [PATCH 41/79] Provide access_token in header instead of URI --- .gitignore | 1 + Tests/GithubObjectTest.php | 22 ++++++++++++++++------ Tests/Stub/ObjectMock.php | 17 +++++++++++++++++ src/AbstractGithubObject.php | 36 ++++++++++++++++++++++++++---------- 4 files changed, 60 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 871b715c..aa391d7d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor/ composer.phar composer.lock phpunit.xml +build/ diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index 080bda4b..a6721891 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -72,9 +72,14 @@ public function testFetchUrl($apiUrl, $path, $page, $limit, $expected) { $this->options->set('api.url', $apiUrl); - $this->assertThat( - $this->object->fetchUrl($path, $page, $limit), - $this->equalTo($expected) + self::assertEquals( + $expected, + $this->object->fetchUrl($path, $page, $limit) + ); + + self::assertEquals( + array(), + $this->object->authHeader() ); } @@ -109,9 +114,14 @@ public function testFetchUrlToken() $this->options->set('gh.token', 'MyTestToken'); - $this->assertThat( - $this->object->fetchUrl('/gists', 0, 0), - $this->equalTo('https://api.github.com/gists?access_token=MyTestToken') + self::assertEquals( + 'https://api.github.com/gists', + $this->object->fetchUrl('/gists', 0, 0) + ); + + self::assertEquals( + array('Authorization: MyTestToken'), + $this->object->authHeader() ); } } diff --git a/Tests/Stub/ObjectMock.php b/Tests/Stub/ObjectMock.php index 7dc91950..c9fdcdaa 100644 --- a/Tests/Stub/ObjectMock.php +++ b/Tests/Stub/ObjectMock.php @@ -32,4 +32,21 @@ public function fetchUrl($path, $page = 0, $limit = 0) { return parent::fetchUrl($path, $page, $limit); } + + /** + * Returns the Authorization header, if required. + * + * If the options passed to the constructor contain a value for `gh.token`, + * an array with a suitable Authorization header is returned, an empty array + * otherwise. + * + * @return array Authorization header if set in options. + * + * @since 1.8.0 + */ + public function authHeader() + { + return parent::authHeader(); + } + } diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index abd62cde..89c6885a 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -114,12 +114,7 @@ protected function fetchUrl($path, $page = 0, $limit = 0) // Get a new Uri object focusing the api url and given path. $uri = new Uri($this->options->get('api.url') . $path); - if ($this->options->get('gh.token', false)) - { - // Use oAuth authentication - @todo set in request header ? - $uri->setVar('access_token', $this->options->get('gh.token')); - } - else + if (!$this->options->get('gh.token', false)) { // Use basic authentication if ($this->options->get('api.username', false)) @@ -136,16 +131,37 @@ protected function fetchUrl($path, $page = 0, $limit = 0) // If we have a defined page number add it to the JUri object. if ($page > 0) { - $uri->setVar('page', (int) $page); + $uri->setVar('page', (int)$page); } // If we have a defined items per page add it to the JUri object. if ($limit > 0) { - $uri->setVar('per_page', (int) $limit); + $uri->setVar('per_page', (int)$limit); } - return (string) $uri; + return (string)$uri; + } + + /** + * Returns the Authorization header, if required. + * + * If the options passed to the constructor contain a value for `gh.token`, + * an array with a suitable Authorization header is returned, an empty array + * otherwise. + * + * @return array Authorization header if set in options. + * + * @since 1.8.0 + */ + protected function authHeader() + { + if ($this->options->get('gh.token', false)) + { + return array('Authorization: ' . $this->options->get('gh.token')); + } + + return array(); } /** @@ -156,8 +172,8 @@ protected function fetchUrl($path, $page = 0, $limit = 0) * * @return mixed * - * @since 1.0 * @throws UnexpectedResponseException + * @since 1.0 */ protected function processResponse(Response $response, $expectedCode = 200) { From b8e74ee1437f2bb827ef025c8e49984665890e06 Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Mon, 14 Sep 2020 13:13:17 +0200 Subject: [PATCH 42/79] CS --- src/AbstractGithubObject.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index 89c6885a..991188f9 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -131,16 +131,16 @@ protected function fetchUrl($path, $page = 0, $limit = 0) // If we have a defined page number add it to the JUri object. if ($page > 0) { - $uri->setVar('page', (int)$page); + $uri->setVar('page', (int) $page); } // If we have a defined items per page add it to the JUri object. if ($limit > 0) { - $uri->setVar('per_page', (int)$limit); + $uri->setVar('per_page', (int) $limit); } - return (string)$uri; + return (string) $uri; } /** From e63cc09b9c2e8803ef4c97fbc790ac77e2199092 Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Mon, 14 Sep 2020 13:20:46 +0200 Subject: [PATCH 43/79] Fix E_DEPRECATED warnings caused by PHPUnit --- Tests/bootstrap.php | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Tests/bootstrap.php diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php new file mode 100644 index 00000000..ddfe6fa4 --- /dev/null +++ b/Tests/bootstrap.php @@ -0,0 +1,6 @@ + Date: Mon, 14 Sep 2020 13:22:21 +0200 Subject: [PATCH 44/79] Changed PHPUnit configuration to use bootstrap file --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1946888e..6d4f4a38 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + Tests From 4228ae54da764e782b36f9e8b380556322605c33 Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Mon, 14 Sep 2020 16:24:47 +0200 Subject: [PATCH 45/79] Changed to non-B/C approach --- Tests/GithubObjectTest.php | 37 +++++++++++++++--------- Tests/Stub/ObjectMock.php | 17 ------------ Tests/Stub/TransportMock.php | 16 +++++++++++ src/AbstractGithubObject.php | 54 +++++++++++++++++++----------------- 4 files changed, 68 insertions(+), 56 deletions(-) create mode 100644 Tests/Stub/TransportMock.php diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index a6721891..175fc6be 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -6,8 +6,11 @@ namespace Joomla\Github\Tests; +use Joomla\Github\AbstractGithubObject; use Joomla\Github\Tests\Stub\GitHubTestCase; use Joomla\Github\Tests\Stub\ObjectMock; +use Joomla\Github\Tests\Stub\TransportMock; +use Joomla\Http\Http; /** * Test class for Joomla\Github\Object. @@ -17,11 +20,17 @@ class GithubObjectTest extends GitHubTestCase { /** - * @var ObjectMock Object under test. + * @var AbstractGithubObject Object under test. * @since 1.0 */ protected $object; + /** + * @var Http The HTTP client + * @since __DEPLOY_VERSION__ + */ + protected $client; + /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. @@ -34,6 +43,7 @@ protected function setUp() { parent::setUp(); + $this->client = new Http(array(), new TransportMock()); $this->object = new ObjectMock($this->options, $this->client); } @@ -74,12 +84,8 @@ public function testFetchUrl($apiUrl, $path, $page, $limit, $expected) self::assertEquals( $expected, - $this->object->fetchUrl($path, $page, $limit) - ); - - self::assertEquals( - array(), - $this->object->authHeader() + $this->object->fetchUrl($path, $page, $limit), + 'URL is not as expected.' ); } @@ -97,9 +103,10 @@ public function testFetchUrlBasicAuth() $this->options->set('api.username', 'MyTestUser'); $this->options->set('api.password', 'MyTestPass'); - $this->assertThat( + self::assertEquals( + 'https://MyTestUser:MyTestPass@api.github.com/gists', $this->object->fetchUrl('/gists', 0, 0), - $this->equalTo('https://MyTestUser:MyTestPass@api.github.com/gists') + 'URL is not as expected.' ); } @@ -114,14 +121,18 @@ public function testFetchUrlToken() $this->options->set('gh.token', 'MyTestToken'); + $options = clone $this->options; + self::assertEquals( 'https://api.github.com/gists', - $this->object->fetchUrl('/gists', 0, 0) + $this->object->fetchUrl('/gists', 0, 0), + 'URL is not as expected.' ); - + self::assertEquals( - array('Authorization: MyTestToken'), - $this->object->authHeader() + array('Authorization' => 'token MyTestToken'), + $this->client->getOption('headers'), + 'Token should bhe propagated as a header.' ); } } diff --git a/Tests/Stub/ObjectMock.php b/Tests/Stub/ObjectMock.php index c9fdcdaa..7dc91950 100644 --- a/Tests/Stub/ObjectMock.php +++ b/Tests/Stub/ObjectMock.php @@ -32,21 +32,4 @@ public function fetchUrl($path, $page = 0, $limit = 0) { return parent::fetchUrl($path, $page, $limit); } - - /** - * Returns the Authorization header, if required. - * - * If the options passed to the constructor contain a value for `gh.token`, - * an array with a suitable Authorization header is returned, an empty array - * otherwise. - * - * @return array Authorization header if set in options. - * - * @since 1.8.0 - */ - public function authHeader() - { - return parent::authHeader(); - } - } diff --git a/Tests/Stub/TransportMock.php b/Tests/Stub/TransportMock.php new file mode 100644 index 00000000..f7324922 --- /dev/null +++ b/Tests/Stub/TransportMock.php @@ -0,0 +1,16 @@ +options = $options ?: new Registry; $this->client = $client ?: new Http($this->options); + // Make sure the user agent string is defined. + if (!isset($this->options['userAgent'])) + { + $this->options['userAgent'] = 'JGitHub/2.0'; + } + + // Set the default timeout to 120 seconds. + if (!isset($this->options['timeout'])) + { + $this->options['timeout'] = 120; + } + $this->package = \get_class($this); $this->package = substr($this->package, strrpos($this->package, '\\') + 1); } @@ -114,7 +126,18 @@ protected function fetchUrl($path, $page = 0, $limit = 0) // Get a new Uri object focusing the api url and given path. $uri = new Uri($this->options->get('api.url') . $path); - if (!$this->options->get('gh.token', false)) + if ($this->options->get('gh.token', false)) + { + // Use oAuth authentication + $headers = $this->client->getOption('headers', array()); + + if (!isset($headers['Authorization'])) + { + $headers['Authorization'] = 'token ' . $this->options->get('gh.token'); + $this->client->setOption('headers', $headers); + } + } + else { // Use basic authentication if ($this->options->get('api.username', false)) @@ -143,27 +166,6 @@ protected function fetchUrl($path, $page = 0, $limit = 0) return (string) $uri; } - /** - * Returns the Authorization header, if required. - * - * If the options passed to the constructor contain a value for `gh.token`, - * an array with a suitable Authorization header is returned, an empty array - * otherwise. - * - * @return array Authorization header if set in options. - * - * @since 1.8.0 - */ - protected function authHeader() - { - if ($this->options->get('gh.token', false)) - { - return array('Authorization: ' . $this->options->get('gh.token')); - } - - return array(); - } - /** * Process the response and decode it. * @@ -172,8 +174,8 @@ protected function authHeader() * * @return mixed * - * @throws UnexpectedResponseException * @since 1.0 + * @throws UnexpectedResponseException */ protected function processResponse(Response $response, $expectedCode = 200) { From 711e8a6f4e56d858fe41d06745030ebc5f4c4d5d Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Mon, 14 Sep 2020 21:49:56 +0200 Subject: [PATCH 46/79] Don't use external mock object --- Tests/GithubObjectTest.php | 40 ++++++++++++++++++++++++++++-------- Tests/Stub/TransportMock.php | 16 --------------- 2 files changed, 31 insertions(+), 25 deletions(-) delete mode 100644 Tests/Stub/TransportMock.php diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index 175fc6be..7c24b1b3 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -9,7 +9,6 @@ use Joomla\Github\AbstractGithubObject; use Joomla\Github\Tests\Stub\GitHubTestCase; use Joomla\Github\Tests\Stub\ObjectMock; -use Joomla\Github\Tests\Stub\TransportMock; use Joomla\Http\Http; /** @@ -43,7 +42,8 @@ protected function setUp() { parent::setUp(); - $this->client = new Http(array(), new TransportMock()); + $transport = $this->createMock('\Joomla\Http\TransportInterface'); + $this->client = new Http(array(), $transport); $this->object = new ObjectMock($this->options, $this->client); } @@ -57,10 +57,34 @@ protected function setUp() public function fetchUrlData() { return array( - 'Standard github - no pagination data' => array('https://api.github.com', '/gists', 0, 0, 'https://api.github.com/gists'), - 'Enterprise github - no pagination data' => array('https://mygithub.com', '/gists', 0, 0, 'https://mygithub.com/gists'), - 'Standard github - page 3' => array('https://api.github.com', '/gists', 3, 0, 'https://api.github.com/gists?page=3'), - 'Enterprise github - page 3, 50 per page' => array('https://mygithub.com', '/gists', 3, 50, 'https://mygithub.com/gists?page=3&per_page=50'), + 'Standard github - no pagination data' => array( + 'https://api.github.com', + '/gists', + 0, + 0, + 'https://api.github.com/gists' + ), + 'Enterprise github - no pagination data' => array( + 'https://mygithub.com', + '/gists', + 0, + 0, + 'https://mygithub.com/gists' + ), + 'Standard github - page 3' => array( + 'https://api.github.com', + '/gists', + 3, + 0, + 'https://api.github.com/gists?page=3' + ), + 'Enterprise github - page 3, 50 per page' => array( + 'https://mygithub.com', + '/gists', + 3, + 50, + 'https://mygithub.com/gists?page=3&per_page=50' + ), ); } @@ -121,14 +145,12 @@ public function testFetchUrlToken() $this->options->set('gh.token', 'MyTestToken'); - $options = clone $this->options; - self::assertEquals( 'https://api.github.com/gists', $this->object->fetchUrl('/gists', 0, 0), 'URL is not as expected.' ); - + self::assertEquals( array('Authorization' => 'token MyTestToken'), $this->client->getOption('headers'), diff --git a/Tests/Stub/TransportMock.php b/Tests/Stub/TransportMock.php deleted file mode 100644 index f7324922..00000000 --- a/Tests/Stub/TransportMock.php +++ /dev/null @@ -1,16 +0,0 @@ - Date: Mon, 14 Sep 2020 22:03:56 +0200 Subject: [PATCH 47/79] Don't mock Transport at all --- Tests/GithubObjectTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index 7c24b1b3..8e77cf10 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -10,6 +10,7 @@ use Joomla\Github\Tests\Stub\GitHubTestCase; use Joomla\Github\Tests\Stub\ObjectMock; use Joomla\Http\Http; +use Joomla\Http\Transport\Curl; /** * Test class for Joomla\Github\Object. @@ -42,7 +43,7 @@ protected function setUp() { parent::setUp(); - $transport = $this->createMock('\Joomla\Http\TransportInterface'); + $transport = new Curl(array()); $this->client = new Http(array(), $transport); $this->object = new ObjectMock($this->options, $this->client); } From 9d1099cc06d039f138b8525f09ab626c8c37d25e Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Mon, 14 Sep 2020 23:12:04 +0200 Subject: [PATCH 48/79] Re-added alias to Http Fixed typo --- Tests/GithubObjectTest.php | 2 +- src/AbstractGithubObject.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index 8e77cf10..40ba596d 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -155,7 +155,7 @@ public function testFetchUrlToken() self::assertEquals( array('Authorization' => 'token MyTestToken'), $this->client->getOption('headers'), - 'Token should bhe propagated as a header.' + 'Token should be propagated as a header.' ); } } diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index f61886b0..0b22dd33 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -9,7 +9,7 @@ namespace Joomla\Github; use Joomla\Http\Exception\UnexpectedResponseException; -use Joomla\Http\Http; +use Joomla\Http\Http as BaseHttp; use Joomla\Http\Response; use Joomla\Registry\Registry; use Joomla\Uri\Uri; @@ -32,7 +32,7 @@ abstract class AbstractGithubObject /** * The HTTP client object to use in sending HTTP requests. * - * @var Http + * @var BaseHttp * @since 1.0 */ protected $client; @@ -82,14 +82,14 @@ abstract class AbstractGithubObject * Constructor. * * @param Registry $options GitHub options object. - * @param Http $client The HTTP client object. + * @param BaseHttp $client The HTTP client object. * * @since 1.0 */ - public function __construct(Registry $options = null, Http $client = null) + public function __construct(Registry $options = null, BaseHttp $client = null) { $this->options = $options ?: new Registry; - $this->client = $client ?: new Http($this->options); + $this->client = $client ?: new BaseHttp($this->options); // Make sure the user agent string is defined. if (!isset($this->options['userAgent'])) From c009e6f1e26baad2e9cb4228c517d0c0d532a69a Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Sat, 26 Sep 2020 22:07:17 +0200 Subject: [PATCH 49/79] Switching from Travis to Drone --- .drone.jsonnet | 139 +++++++++++++++++ .drone.yml | 393 +++++++++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 40 ----- README.md | 2 +- 4 files changed, 533 insertions(+), 41 deletions(-) create mode 100644 .drone.jsonnet create mode 100644 .drone.yml delete mode 100644 .travis.yml diff --git a/.drone.jsonnet b/.drone.jsonnet new file mode 100644 index 00000000..34be0685 --- /dev/null +++ b/.drone.jsonnet @@ -0,0 +1,139 @@ +local volumes = [ + { + name: "composer-cache", + path: "/tmp/composer-cache", + }, +]; + +local hostvolumes = [ + { + name: "composer-cache", + host: {path: "/tmp/composer-cache"} + }, +]; + +local composer(phpversion, params) = { + name: "composer", + image: "joomlaprojects/docker-images:php" + phpversion, + volumes: volumes, + commands: [ + "php -v", + "composer update " + params, + if phpversion == "8.0" then "wget https://ci.joomla.org/artifacts/phpunit8_php8_match.patch", + if phpversion == "8.0" then "patch -N -p0 < phpunit8_php8_match.patch" + ] +}; + +local phpunit(phpversion) = { + name: "PHPUnit", + image: "joomlaprojects/docker-images:php" + phpversion, + [if phpversion == "8.0" then "failure"]: "ignore", + commands: ["vendor/bin/phpunit"] +}; + +local pipeline(name, phpversion, params) = { + kind: "pipeline", + name: "PHP " + name, + volumes: hostvolumes, + steps: [ + composer(phpversion, params), + phpunit(phpversion) + ], +}; + +[ + { + kind: "pipeline", + name: "Codequality", + volumes: hostvolumes, + steps: [ + { + name: "composer", + image: "joomlaprojects/docker-images:php7.4", + volumes: volumes, + commands: [ + "php -v", + "composer update", + "composer require phpmd/phpmd phpstan/phpstan" + ] + }, + { + name: "phpcs", + image: "joomlaprojects/docker-images:php7.4", + depends: [ "composer" ], + commands: [ + "vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards", + "vendor/bin/phpcs -p --report=full --extensions=php --standard=ruleset.xml src/" + ] + }, + { + name: "phpmd", + image: "joomlaprojects/docker-images:php7.4", + depends: [ "composer" ], + failure: "ignore", + commands: [ + "vendor/bin/phpmd src text cleancode", + "vendor/bin/phpmd src text codesize", + "vendor/bin/phpmd src text controversial", + "vendor/bin/phpmd src text design", + "vendor/bin/phpmd src text unusedcode", + ] + }, + { + name: "phpstan", + image: "joomlaprojects/docker-images:php7.4", + depends: [ "composer" ], + failure: "ignore", + commands: [ + "vendor/bin/phpstan analyse src", + ] + }, + { + name: "phploc", + image: "joomlaprojects/docker-images:php7.4", + depends: [ "composer" ], + failure: "ignore", + commands: [ + "phploc src", + ] + }, + { + name: "phpcpd", + image: "joomlaprojects/docker-images:php7.4", + depends: [ "composer" ], + failure: "ignore", + commands: [ + "phpcpd src", + ] + } + ] + }, + { + kind: "pipeline", + name: "PHP 5.3 lowest", + volumes: hostvolumes, + steps: [ + { + name: "composer", + image: "joomlaprojects/docker-images:php5.3", + volumes: volumes, + commands: [ + "php -v", + "composer update --prefer-stable --prefer-lowest", + "composer update phpunit/phpunit-mock-objects" + ] + }, + phpunit("5.3") + ] + }, + pipeline("5.3", "5.3", "--prefer-stable"), + pipeline("5.4", "5.4", "--prefer-stable"), + pipeline("5.5", "5.5", "--prefer-stable"), + pipeline("5.6", "5.6", "--prefer-stable"), + pipeline("7.0", "7.0", "--prefer-stable"), + pipeline("7.1", "7.1", "--prefer-stable"), + pipeline("7.2", "7.2", "--prefer-stable"), + pipeline("7.3", "7.3", "--prefer-stable"), + pipeline("7.4", "7.4", "--prefer-stable"), + pipeline("8.0", "8.0", "--ignore-platform-reqs --prefer-stable") +] diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 00000000..bb07e3ed --- /dev/null +++ b/.drone.yml @@ -0,0 +1,393 @@ +--- +kind: pipeline +name: Codequality + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.4 + commands: + - php -v + - composer update + - composer require phpmd/phpmd phpstan/phpstan + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: phpcs + image: joomlaprojects/docker-images:php7.4 + commands: + - vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards + - vendor/bin/phpcs -p --report=full --extensions=php --standard=ruleset.xml src/ + +- name: phpmd + image: joomlaprojects/docker-images:php7.4 + commands: + - vendor/bin/phpmd src text cleancode + - vendor/bin/phpmd src text codesize + - vendor/bin/phpmd src text controversial + - vendor/bin/phpmd src text design + - vendor/bin/phpmd src text unusedcode + failure: ignore + +- name: phpstan + image: joomlaprojects/docker-images:php7.4 + commands: + - vendor/bin/phpstan analyse src + failure: ignore + +- name: phploc + image: joomlaprojects/docker-images:php7.4 + commands: + - phploc src + failure: ignore + +- name: phpcpd + image: joomlaprojects/docker-images:php7.4 + commands: + - phpcpd src + failure: ignore + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 5.3 lowest + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php5.3 + commands: + - php -v + - composer update --prefer-stable --prefer-lowest + - composer update phpunit/phpunit-mock-objects + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php5.3 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 5.3 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php5.3 + commands: + - php -v + - composer update --prefer-stable + - "" + - "" + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php5.3 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 5.4 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php5.4 + commands: + - php -v + - composer update --prefer-stable + - "" + - "" + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php5.4 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 5.5 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php5.5 + commands: + - php -v + - composer update --prefer-stable + - "" + - "" + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php5.5 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 5.6 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php5.6 + commands: + - php -v + - composer update --prefer-stable + - "" + - "" + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php5.6 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 7.0 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.0 + commands: + - php -v + - composer update --prefer-stable + - "" + - "" + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php7.0 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 7.1 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.1 + commands: + - php -v + - composer update --prefer-stable + - "" + - "" + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php7.1 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 7.2 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.2 + commands: + - php -v + - composer update --prefer-stable + - "" + - "" + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php7.2 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 7.3 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.3 + commands: + - php -v + - composer update --prefer-stable + - "" + - "" + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php7.3 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 7.4 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.4 + commands: + - php -v + - composer update --prefer-stable + - "" + - "" + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php7.4 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 8.0 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php8.0 + commands: + - php -v + - composer update --ignore-platform-reqs --prefer-stable + - wget https://ci.joomla.org/artifacts/phpunit8_php8_match.patch + - patch -N -p0 < phpunit8_php8_match.patch + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php8.0 + commands: + - vendor/bin/phpunit + failure: ignore + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: signature +hmac: 7aeba2d0a0d57aea8d6b7fcbce2aef1465626120ceaf60fa197211e047affed7 + +... diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9a8a8ad1..00000000 --- a/.travis.yml +++ /dev/null @@ -1,40 +0,0 @@ -language: php -sudo: false -dist: trusty - -env: - global: - - RUN_PHPCS="no" - - COMPOSER_FLAGS="--prefer-stable" - -matrix: - fast_finish: true - include: - - php: 5.3 - dist: precise - - php: 5.3 - dist: precise - env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" - - php: 5.4 - - php: 5.5 - - php: 5.6 - env: RUN_PHPCS="yes" - - php: 7.0 - - php: 7.1 - - php: 7.1 - # This empty flag removes the prefer-stable switch to cause dev dependencies to be installed - env: COMPOSER_FLAGS="" - - php: 7.2 - - php: 7.3 - - php: 7.4 - - php: nightly - allow_failures: - - php: nightly - -before_script: - - composer self-update - - composer update $COMPOSER_FLAGS - -script: - - vendor/bin/phpunit - - if [ "$RUN_PHPCS" == "yes" ]; then vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards && vendor/bin/phpcs -p --report=full --extensions=php --standard=ruleset.xml src/; fi; diff --git a/README.md b/README.md index b67c4964..39a5e136 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# The Github Package [![Build Status](https://travis-ci.org/joomla-framework/github-api.png?branch=master)](https://travis-ci.org/joomla-framework/github-api) +# The Github Package [![Build Status](https://ci.joomla.org/api/badges/joomla-framework/github-api/status.svg)](https://ci.joomla.org/joomla-framework/github-api) ## Using the Github Package From bb50f15a7f606115e0f655d779d4cc43b3eb9a47 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Sat, 26 Sep 2020 22:11:46 +0200 Subject: [PATCH 50/79] Removing PHP8 special cases --- .drone.jsonnet | 2 -- .drone.yml | 22 +--------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 34be0685..872ba3fb 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -19,8 +19,6 @@ local composer(phpversion, params) = { commands: [ "php -v", "composer update " + params, - if phpversion == "8.0" then "wget https://ci.joomla.org/artifacts/phpunit8_php8_match.patch", - if phpversion == "8.0" then "patch -N -p0 < phpunit8_php8_match.patch" ] }; diff --git a/.drone.yml b/.drone.yml index bb07e3ed..7766be1f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -99,8 +99,6 @@ steps: commands: - php -v - composer update --prefer-stable - - "" - - "" volumes: - name: composer-cache path: /tmp/composer-cache @@ -129,8 +127,6 @@ steps: commands: - php -v - composer update --prefer-stable - - "" - - "" volumes: - name: composer-cache path: /tmp/composer-cache @@ -159,8 +155,6 @@ steps: commands: - php -v - composer update --prefer-stable - - "" - - "" volumes: - name: composer-cache path: /tmp/composer-cache @@ -189,8 +183,6 @@ steps: commands: - php -v - composer update --prefer-stable - - "" - - "" volumes: - name: composer-cache path: /tmp/composer-cache @@ -219,8 +211,6 @@ steps: commands: - php -v - composer update --prefer-stable - - "" - - "" volumes: - name: composer-cache path: /tmp/composer-cache @@ -249,8 +239,6 @@ steps: commands: - php -v - composer update --prefer-stable - - "" - - "" volumes: - name: composer-cache path: /tmp/composer-cache @@ -279,8 +267,6 @@ steps: commands: - php -v - composer update --prefer-stable - - "" - - "" volumes: - name: composer-cache path: /tmp/composer-cache @@ -309,8 +295,6 @@ steps: commands: - php -v - composer update --prefer-stable - - "" - - "" volumes: - name: composer-cache path: /tmp/composer-cache @@ -339,8 +323,6 @@ steps: commands: - php -v - composer update --prefer-stable - - "" - - "" volumes: - name: composer-cache path: /tmp/composer-cache @@ -369,8 +351,6 @@ steps: commands: - php -v - composer update --ignore-platform-reqs --prefer-stable - - wget https://ci.joomla.org/artifacts/phpunit8_php8_match.patch - - patch -N -p0 < phpunit8_php8_match.patch volumes: - name: composer-cache path: /tmp/composer-cache @@ -388,6 +368,6 @@ volumes: --- kind: signature -hmac: 7aeba2d0a0d57aea8d6b7fcbce2aef1465626120ceaf60fa197211e047affed7 +hmac: c732468b134cba58a2c7c0148566f552bb2a9c9e22e56d5a425ac284fedab713 ... From 1e8ba220406d15110f4e55cdb7c47ecfccd141e4 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Sat, 26 Sep 2020 22:15:19 +0200 Subject: [PATCH 51/79] Switching from Travis to Drone --- .drone.jsonnet | 114 +++++++++++++++++++++++++++ .drone.yml | 204 +++++++++++++++++++++++++++++++++++++++++++++++++ .travis.yml | 33 -------- README.md | 8 +- composer.json | 2 +- 5 files changed, 323 insertions(+), 38 deletions(-) create mode 100644 .drone.jsonnet create mode 100644 .drone.yml delete mode 100644 .travis.yml diff --git a/.drone.jsonnet b/.drone.jsonnet new file mode 100644 index 00000000..ab2b93f7 --- /dev/null +++ b/.drone.jsonnet @@ -0,0 +1,114 @@ +local volumes = [ + { + name: "composer-cache", + path: "/tmp/composer-cache", + }, +]; + +local hostvolumes = [ + { + name: "composer-cache", + host: {path: "/tmp/composer-cache"} + }, +]; + +local composer(phpversion, params) = { + name: "composer", + image: "joomlaprojects/docker-images:php" + phpversion, + volumes: volumes, + commands: [ + "php -v", + "composer update " + params, + ] +}; + +local phpunit(phpversion) = { + name: "PHPUnit", + image: "joomlaprojects/docker-images:php" + phpversion, + [if phpversion == "8.0" then "failure"]: "ignore", + commands: ["vendor/bin/phpunit"] +}; + +local pipeline(name, phpversion, params) = { + kind: "pipeline", + name: "PHP " + name, + volumes: hostvolumes, + steps: [ + composer(phpversion, params), + phpunit(phpversion) + ], +}; + +[ + { + kind: "pipeline", + name: "Codequality", + volumes: hostvolumes, + steps: [ + { + name: "composer", + image: "joomlaprojects/docker-images:php7.4", + volumes: volumes, + commands: [ + "php -v", + "composer update", + "composer require phpmd/phpmd phpstan/phpstan" + ] + }, + { + name: "phpcs", + image: "joomlaprojects/docker-images:php7.4", + depends: [ "composer" ], + commands: [ + "vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards", + "vendor/bin/phpcs -p --report=full --extensions=php --standard=ruleset.xml src/" + ] + }, + { + name: "phpmd", + image: "joomlaprojects/docker-images:php7.4", + depends: [ "composer" ], + failure: "ignore", + commands: [ + "vendor/bin/phpmd src text cleancode", + "vendor/bin/phpmd src text codesize", + "vendor/bin/phpmd src text controversial", + "vendor/bin/phpmd src text design", + "vendor/bin/phpmd src text unusedcode", + ] + }, + { + name: "phpstan", + image: "joomlaprojects/docker-images:php7.4", + depends: [ "composer" ], + failure: "ignore", + commands: [ + "vendor/bin/phpstan analyse src", + ] + }, + { + name: "phploc", + image: "joomlaprojects/docker-images:php7.4", + depends: [ "composer" ], + failure: "ignore", + commands: [ + "phploc src", + ] + }, + { + name: "phpcpd", + image: "joomlaprojects/docker-images:php7.4", + depends: [ "composer" ], + failure: "ignore", + commands: [ + "phpcpd src", + ] + } + ] + }, + pipeline("7.2 lowest", "7.2", "--prefer-stable --prefer-lowest"), + pipeline("7.2", "7.2", "--prefer-stable"), + pipeline("7.3", "7.3", "--prefer-stable"), + pipeline("7.4", "7.4", "--prefer-stable"), + pipeline("8.0", "8.0", "--ignore-platform-reqs --prefer-stable") +] diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 00000000..dba56c1e --- /dev/null +++ b/.drone.yml @@ -0,0 +1,204 @@ +--- +kind: pipeline +name: Codequality + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.4 + commands: + - php -v + - composer update + - composer require phpmd/phpmd phpstan/phpstan + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: phpcs + image: joomlaprojects/docker-images:php7.4 + commands: + - vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards + - vendor/bin/phpcs -p --report=full --extensions=php --standard=ruleset.xml src/ + +- name: phpmd + image: joomlaprojects/docker-images:php7.4 + commands: + - vendor/bin/phpmd src text cleancode + - vendor/bin/phpmd src text codesize + - vendor/bin/phpmd src text controversial + - vendor/bin/phpmd src text design + - vendor/bin/phpmd src text unusedcode + failure: ignore + +- name: phpstan + image: joomlaprojects/docker-images:php7.4 + commands: + - vendor/bin/phpstan analyse src + failure: ignore + +- name: phploc + image: joomlaprojects/docker-images:php7.4 + commands: + - phploc src + failure: ignore + +- name: phpcpd + image: joomlaprojects/docker-images:php7.4 + commands: + - phpcpd src + failure: ignore + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 7.2 lowest + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.2 + commands: + - php -v + - composer update --prefer-stable --prefer-lowest + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php7.2 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 7.2 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.2 + commands: + - php -v + - composer update --prefer-stable + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php7.2 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 7.3 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.3 + commands: + - php -v + - composer update --prefer-stable + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php7.3 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 7.4 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php7.4 + commands: + - php -v + - composer update --prefer-stable + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php7.4 + commands: + - vendor/bin/phpunit + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: pipeline +name: PHP 8.0 + +platform: + os: linux + arch: amd64 + +steps: +- name: composer + image: joomlaprojects/docker-images:php8.0 + commands: + - php -v + - composer update --ignore-platform-reqs --prefer-stable + volumes: + - name: composer-cache + path: /tmp/composer-cache + +- name: PHPUnit + image: joomlaprojects/docker-images:php8.0 + commands: + - vendor/bin/phpunit + failure: ignore + +volumes: +- name: composer-cache + host: + path: /tmp/composer-cache + +--- +kind: signature +hmac: 0fef580d9a845caea4e052805765ee3f357d4e1b1f1573f69bbb428ae7822e7b + +... diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6d84b825..00000000 --- a/.travis.yml +++ /dev/null @@ -1,33 +0,0 @@ -language: php -sudo: false -dist: trusty - -env: - global: - - RUN_PHPCS="no" - - COMPOSER_FLAGS="--prefer-stable" - -matrix: - fast_finish: true - include: - - php: 7.2 - - php: 7.2 - env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" - - php: 7.2 - env: RUN_PHPCS="yes" - - php: 7.3 - - php: 7.3 - # This empty flag removes the prefer-stable switch to cause dev dependencies to be installed - env: COMPOSER_FLAGS="" - - php: 7.4 - - php: nightly - allow_failures: - - php: nightly - -before_script: - - composer self-update - - composer update $COMPOSER_FLAGS - -script: - - vendor/bin/phpunit - - if [ "$RUN_PHPCS" == "yes" ]; then vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards && vendor/bin/phpcs -p --report=full --extensions=php --standard=ruleset.xml src/; fi; diff --git a/README.md b/README.md index b02f646a..54ebaf78 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# The Github Package [![Build Status](https://travis-ci.org/joomla-framework/github-api.png?branch=master)](https://travis-ci.org/joomla-framework/github-api) +# The Github Package [![Build Status](https://ci.joomla.org/api/badges/joomla-framework/github-api/status.svg?ref=refs/heads/2.0-dev)](https://ci.joomla.org/joomla-framework/github-api) ## Using the Github Package @@ -751,12 +751,12 @@ The following resources contain more information: [Joomla! API Reference](http: ## Installation via Composer -Add `"joomla/github": "2.0.*@dev"` to the require block in your composer.json and then run `composer install`. +Add `"joomla/github": "~1.0"` to the require block in your composer.json and then run `composer install`. ```json { "require": { - "joomla/github": "2.0.*@dev" + "joomla/github": "~1.0" } } ``` @@ -764,5 +764,5 @@ Add `"joomla/github": "2.0.*@dev"` to the require block in your composer.json an Alternatively, you can simply run the following from the command line: ```sh -composer require joomla/github "2.0.*@dev" +composer require joomla/github "~1.0" ``` diff --git a/composer.json b/composer.json index c5186fe0..5cd9fa5e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "joomla/uri": "^1.0|^2.0" }, "require-dev": { - "joomla/coding-standards": "^2.0@alpha", + "joomla/coding-standards": "^3.0@dev", "phpunit/phpunit": "^8.5|^9.0" }, "autoload": { From 01c106fe0e9c079f897763bfd7fc9487e840bc80 Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Fri, 27 Nov 2020 14:40:05 +0100 Subject: [PATCH 52/79] Don't include development related files in distribution package --- .gitattributes | 10 +++++++--- README.md | 15 +++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.gitattributes b/.gitattributes index bfb8d891..4d38e471 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,9 @@ +.github/ export-ignore +build/ export-ignore +Tests/ export-ignore +.drone.jsonnet export-ignore +.drone.yml export-ignore .gitattributes export-ignore .gitignore export-ignore -.gitmodules export-ignore -.travis/ export-ignore -.travis.yml export-ignore +phpunit.xml.dist export-ignore +ruleset.xml export-ignore diff --git a/README.md b/README.md index 39a5e136..ef61a36a 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@ ## Using the Github Package The Github package is designed to be a straightforward interface for working with Github. It is based on version 3 of -the Github API. You can find documentation on the API at [http://developer.github.com/v3/.] -(http://developer.github.com/v3/) +the Github API. You can find documentation on the API at [http://developer.github.com/v3/](http://developer.github.com/v3/). Github is built upon the Http package which provides an easy way to consume URLs and web services in a transport independent way. `Joomla\Http` currently supports streams, sockets and cURL. It is possible to create a custom @@ -20,13 +19,11 @@ use Joomla\Github\Github; $github = new Github; ``` -This creates a basic Github object that can be used to access publicly available resources on [github.com] -(https://github.com). +This creates a basic Github object that can be used to access publicly available resources on [github.com](https://github.com). Sometimes it is necessary to specify additional options. This can be done by injecting in a Registry object with your preferred options. Support is available for optionally providing a custom Github account username and password, -as well as a custom URL for the Github server (as would be the case for using a local instance of [Github Enterprise] -(https://enterprise.github.com)). +as well as a custom URL for the Github server (as would be the case for using a local instance of [Github Enterprise](https://enterprise.github.com)). ```php use Joomla\Github\Github; @@ -766,3 +763,9 @@ Alternatively, you can simply run the following from the command line: ```sh composer require joomla/github "~1.0" ``` + +If you want to include the test sources, use + +```sh +composer require --prefer-source joomla/github "~1.0" +``` From 7d47119c5502aca78277855031a5f5684b57500a Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Sun, 29 Nov 2020 11:37:32 +0100 Subject: [PATCH 53/79] Modernisation - Prepare Test for uri-2.0 joomla/uri-2.0 will return a URI object instead of a string for `fetchUrl()`. --- Tests/GithubObjectTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index 40ba596d..4d75ff4b 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -148,7 +148,7 @@ public function testFetchUrlToken() self::assertEquals( 'https://api.github.com/gists', - $this->object->fetchUrl('/gists', 0, 0), + (string) $this->object->fetchUrl('/gists', 0, 0), 'URL is not as expected.' ); From f79ba423cc6f9afb7360fe3feb6af94201aa5789 Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Mon, 4 Jan 2021 16:54:43 +0100 Subject: [PATCH 54/79] Build - Add PHPUnit cache to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index aa391d7d..caa2a39c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ composer.phar composer.lock phpunit.xml build/ +/.phpunit.result.cache From 44ab61cbdb5cec5e55920821119dcb5065d79c4e Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Mon, 4 Jan 2021 17:11:10 +0100 Subject: [PATCH 55/79] Merge - Add missing change --- src/AbstractGithubObject.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index 2f00c0ff..c5a7e580 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -115,8 +115,14 @@ protected function fetchUrl($path, $page = 0, $limit = 0) if ($this->options->get('gh.token', false)) { - // Use oAuth authentication - @todo set in request header ? - $uri->setVar('access_token', $this->options->get('gh.token')); + // Use oAuth authentication + $headers = $this->client->getOption('headers', array()); + + if (!isset($headers['Authorization'])) + { + $headers['Authorization'] = 'token ' . $this->options->get('gh.token'); + $this->client->setOption('headers', $headers); + } } else { From e5b418a7d124889d25a024557d1f089c5356f1c6 Mon Sep 17 00:00:00 2001 From: "Phil E. Taylor" Date: Tue, 6 Apr 2021 18:39:18 +0100 Subject: [PATCH 56/79] EditorConfig Signed-off-by: Phil E. Taylor --- .editorconfig | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..c8bb3e7b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +# EditorConfig is awesome: https://EditorConfig.org + +# Unix-style newlines with a newline ending every file +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true From 7364303752eba90fadc1f73d00dee0ce82e93f47 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Mon, 16 Aug 2021 21:26:42 +0100 Subject: [PATCH 57/79] Tag 2.0 stable --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8c32897b..56187dc1 100644 --- a/README.md +++ b/README.md @@ -748,12 +748,12 @@ The following resources contain more information: [Joomla! API Reference](http: ## Installation via Composer -Add `"joomla/github": "~1.0"` to the require block in your composer.json and then run `composer install`. +Add `"joomla/github": "~2.0"` to the require block in your composer.json and then run `composer install`. ```json { "require": { - "joomla/github": "~1.0" + "joomla/github": "~2.0" } } ``` @@ -761,11 +761,11 @@ Add `"joomla/github": "~1.0"` to the require block in your composer.json and the Alternatively, you can simply run the following from the command line: ```sh -composer require joomla/github "~1.0" +composer require joomla/github "~2.0" ``` If you want to include the test sources, use ```sh -composer require --prefer-source joomla/github "~1.0" +composer require --prefer-source joomla/github "~2.0" ``` From b67f52d2e806793dc6e95998d0fcad894a405065 Mon Sep 17 00:00:00 2001 From: Joomla Jenkins Date: Mon, 16 Aug 2021 15:27:12 -0500 Subject: [PATCH 58/79] Tagging release 2.0.0 --- Tests/GithubObjectTest.php | 2 +- Tests/GithubTest.php | 2 +- Tests/Package/Activity/EventsTest.php | 2 +- Tests/Package/Activity/FeedsTest.php | 2 +- Tests/Package/Activity/NotificationsTest.php | 2 +- Tests/Package/Activity/StarringTest.php | 2 +- Tests/Package/Activity/WatchingTest.php | 2 +- Tests/Package/ActivityTest.php | 2 +- Tests/Package/AuthorizationsTest.php | 2 +- Tests/Package/Data/BlobsTest.php | 2 +- Tests/Package/Data/CommitsTest.php | 2 +- Tests/Package/Data/RefsTest.php | 2 +- Tests/Package/Data/TagsTest.php | 2 +- Tests/Package/Data/TreesTest.php | 2 +- Tests/Package/DataTest.php | 2 +- Tests/Package/EmojisTest.php | 2 +- Tests/Package/GistsTest.php | 2 +- Tests/Package/GitignoreTest.php | 2 +- Tests/Package/GraphqlTest.php | 2 +- Tests/Package/Issues/AssigneesTest.php | 2 +- Tests/Package/Issues/CommentsTest.php | 2 +- Tests/Package/Issues/EventsTest.php | 2 +- Tests/Package/Issues/LabelsTest.php | 2 +- Tests/Package/Issues/MilestonesTest.php | 2 +- Tests/Package/IssuesTest.php | 2 +- Tests/Package/MarkdownTest.php | 2 +- Tests/Package/MetaTest.php | 2 +- Tests/Package/Orgs/HooksTest.php | 2 +- Tests/Package/Orgs/MembersTest.php | 2 +- Tests/Package/Orgs/TeamsTest.php | 2 +- Tests/Package/OrgsTest.php | 2 +- Tests/Package/Pulls/CommentsTest.php | 2 +- Tests/Package/PullsTest.php | 2 +- Tests/Package/Repositories/CollaboratorsTest.php | 2 +- Tests/Package/Repositories/CommentsTest.php | 2 +- Tests/Package/Repositories/CommitsTest.php | 2 +- Tests/Package/Repositories/ContentsTest.php | 2 +- Tests/Package/Repositories/DeploymentsTest.php | 2 +- Tests/Package/Repositories/DownloadsTest.php | 2 +- Tests/Package/Repositories/ForksTest.php | 2 +- Tests/Package/Repositories/HooksTest.php | 2 +- Tests/Package/Repositories/KeysTest.php | 2 +- Tests/Package/Repositories/MergingTest.php | 2 +- Tests/Package/Repositories/PagesTest.php | 2 +- Tests/Package/Repositories/ReleasesTest.php | 2 +- Tests/Package/Repositories/StatisticsTest.php | 2 +- Tests/Package/Repositories/StatusesTest.php | 2 +- Tests/Package/RepositoriesTest.php | 2 +- Tests/Package/SearchTest.php | 2 +- Tests/Package/Users/EmailsTest.php | 2 +- Tests/Package/Users/FollowersTest.php | 2 +- Tests/Package/Users/KeysTest.php | 2 +- Tests/Package/UsersTest.php | 2 +- Tests/Package/ZenTest.php | 2 +- Tests/PackageTest.php | 2 +- Tests/Stub/GitHubTestCase.php | 2 +- Tests/Stub/ObjectMock.php | 2 +- src/AbstractGithubObject.php | 2 +- src/AbstractPackage.php | 2 +- src/Github.php | 2 +- src/Package/Activity.php | 2 +- src/Package/Activity/Events.php | 2 +- src/Package/Activity/Feeds.php | 2 +- src/Package/Activity/Notifications.php | 2 +- src/Package/Activity/Starring.php | 2 +- src/Package/Activity/Watching.php | 2 +- src/Package/Authorization.php | 2 +- src/Package/Data.php | 2 +- src/Package/Data/Blobs.php | 2 +- src/Package/Data/Commits.php | 2 +- src/Package/Data/Refs.php | 2 +- src/Package/Data/Tags.php | 2 +- src/Package/Data/Trees.php | 2 +- src/Package/Emojis.php | 2 +- src/Package/Gists.php | 2 +- src/Package/Gists/Comments.php | 2 +- src/Package/Gitignore.php | 2 +- src/Package/Graphql.php | 2 +- src/Package/Issues.php | 2 +- src/Package/Issues/Assignees.php | 2 +- src/Package/Issues/Comments.php | 2 +- src/Package/Issues/Events.php | 2 +- src/Package/Issues/Labels.php | 2 +- src/Package/Issues/Milestones.php | 2 +- src/Package/Markdown.php | 2 +- src/Package/Meta.php | 2 +- src/Package/Orgs.php | 2 +- src/Package/Orgs/Hooks.php | 2 +- src/Package/Orgs/Members.php | 2 +- src/Package/Orgs/Teams.php | 2 +- src/Package/Pulls.php | 2 +- src/Package/Pulls/Comments.php | 2 +- src/Package/Repositories.php | 2 +- src/Package/Repositories/Branches.php | 2 +- src/Package/Repositories/Collaborators.php | 2 +- src/Package/Repositories/Comments.php | 2 +- src/Package/Repositories/Commits.php | 2 +- src/Package/Repositories/Contents.php | 2 +- src/Package/Repositories/Deployments.php | 2 +- src/Package/Repositories/Downloads.php | 2 +- src/Package/Repositories/Forks.php | 2 +- src/Package/Repositories/Hooks.php | 2 +- src/Package/Repositories/Keys.php | 2 +- src/Package/Repositories/Merging.php | 2 +- src/Package/Repositories/Pages.php | 2 +- src/Package/Repositories/Releases.php | 2 +- src/Package/Repositories/Statistics.php | 2 +- src/Package/Repositories/Statuses.php | 2 +- src/Package/Search.php | 2 +- src/Package/Users.php | 2 +- src/Package/Users/Emails.php | 2 +- src/Package/Users/Followers.php | 2 +- src/Package/Users/Keys.php | 2 +- src/Package/Zen.php | 2 +- 114 files changed, 114 insertions(+), 114 deletions(-) diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index 5543ad3d..c42d371f 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -1,6 +1,6 @@ Date: Sat, 18 Sep 2021 12:46:59 +0200 Subject: [PATCH 59/79] Create SECURITY.md --- SECURITY.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..4574d2ad --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,22 @@ +# Security Policy + +## Supported Versions + +These versions are currently being supported with security updates: + +| Version | Supported | +| ------- | ------------------ | +| 2.0.x | :white_check_mark: | +| 1.7.x | :white_check_mark: | +| < 1.7 | :x: | + +## Reporting a Vulnerability + +To report a security issue in the core Joomla! CMS or Framework, or with a joomla.org website, please submit +[the form on our portal](https://developer.joomla.org/security/contact-the-team.html) containing as much detail +as possible about the issue. Additional information about our security team and their processes may be found on +our [Security page](https://developer.joomla.org/security.html). + +To report an issue in a Joomla! extension, please submit it to the [Vulnerable Extensions List](https://vel.joomla.org/submit-vel). + +For support with a site which has been attacked, please visit the [Joomla! Forum](https://forum.joomla.org/viewforum.php?f=714). From dcdf2227ec0b1cf6670cb6438b405ebd2be798a5 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Mon, 11 Apr 2022 09:56:34 +0200 Subject: [PATCH 60/79] Adding missing use statement --- src/AbstractGithubObject.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index 510b61fd..bd4cc371 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -10,6 +10,7 @@ use Joomla\Http\Exception\UnexpectedResponseException; use Joomla\Http\Http as BaseHttp; +use Joomla\Http\HttpFactory; use Joomla\Http\Response; use Joomla\Registry\Registry; use Joomla\Uri\Uri; From f213af97aa04e763f042cd528c9adaee4141b2b1 Mon Sep 17 00:00:00 2001 From: Joomla Jenkins Date: Tue, 3 May 2022 13:12:28 -0500 Subject: [PATCH 61/79] Tagging release 2.0.1 --- Tests/GithubObjectTest.php | 2 +- Tests/GithubTest.php | 2 +- Tests/Package/Activity/EventsTest.php | 2 +- Tests/Package/Activity/FeedsTest.php | 2 +- Tests/Package/Activity/NotificationsTest.php | 2 +- Tests/Package/Activity/StarringTest.php | 2 +- Tests/Package/Activity/WatchingTest.php | 2 +- Tests/Package/ActivityTest.php | 2 +- Tests/Package/AuthorizationsTest.php | 2 +- Tests/Package/Data/BlobsTest.php | 2 +- Tests/Package/Data/CommitsTest.php | 2 +- Tests/Package/Data/RefsTest.php | 2 +- Tests/Package/Data/TagsTest.php | 2 +- Tests/Package/Data/TreesTest.php | 2 +- Tests/Package/DataTest.php | 2 +- Tests/Package/EmojisTest.php | 2 +- Tests/Package/GistsTest.php | 2 +- Tests/Package/GitignoreTest.php | 2 +- Tests/Package/GraphqlTest.php | 2 +- Tests/Package/Issues/AssigneesTest.php | 2 +- Tests/Package/Issues/CommentsTest.php | 2 +- Tests/Package/Issues/EventsTest.php | 2 +- Tests/Package/Issues/LabelsTest.php | 2 +- Tests/Package/Issues/MilestonesTest.php | 2 +- Tests/Package/IssuesTest.php | 2 +- Tests/Package/MarkdownTest.php | 2 +- Tests/Package/MetaTest.php | 2 +- Tests/Package/Orgs/HooksTest.php | 2 +- Tests/Package/Orgs/MembersTest.php | 2 +- Tests/Package/Orgs/TeamsTest.php | 2 +- Tests/Package/OrgsTest.php | 2 +- Tests/Package/Pulls/CommentsTest.php | 2 +- Tests/Package/PullsTest.php | 2 +- Tests/Package/Repositories/CollaboratorsTest.php | 2 +- Tests/Package/Repositories/CommentsTest.php | 2 +- Tests/Package/Repositories/CommitsTest.php | 2 +- Tests/Package/Repositories/ContentsTest.php | 2 +- Tests/Package/Repositories/DeploymentsTest.php | 2 +- Tests/Package/Repositories/DownloadsTest.php | 2 +- Tests/Package/Repositories/ForksTest.php | 2 +- Tests/Package/Repositories/HooksTest.php | 2 +- Tests/Package/Repositories/KeysTest.php | 2 +- Tests/Package/Repositories/MergingTest.php | 2 +- Tests/Package/Repositories/PagesTest.php | 2 +- Tests/Package/Repositories/ReleasesTest.php | 2 +- Tests/Package/Repositories/StatisticsTest.php | 2 +- Tests/Package/Repositories/StatusesTest.php | 2 +- Tests/Package/RepositoriesTest.php | 2 +- Tests/Package/SearchTest.php | 2 +- Tests/Package/Users/EmailsTest.php | 2 +- Tests/Package/Users/FollowersTest.php | 2 +- Tests/Package/Users/KeysTest.php | 2 +- Tests/Package/UsersTest.php | 2 +- Tests/Package/ZenTest.php | 2 +- Tests/PackageTest.php | 2 +- Tests/Stub/GitHubTestCase.php | 2 +- Tests/Stub/ObjectMock.php | 2 +- src/AbstractGithubObject.php | 2 +- src/AbstractPackage.php | 2 +- src/Github.php | 2 +- src/Package/Activity.php | 2 +- src/Package/Activity/Events.php | 2 +- src/Package/Activity/Feeds.php | 2 +- src/Package/Activity/Notifications.php | 2 +- src/Package/Activity/Starring.php | 2 +- src/Package/Activity/Watching.php | 2 +- src/Package/Authorization.php | 2 +- src/Package/Data.php | 2 +- src/Package/Data/Blobs.php | 2 +- src/Package/Data/Commits.php | 2 +- src/Package/Data/Refs.php | 2 +- src/Package/Data/Tags.php | 2 +- src/Package/Data/Trees.php | 2 +- src/Package/Emojis.php | 2 +- src/Package/Gists.php | 2 +- src/Package/Gists/Comments.php | 2 +- src/Package/Gitignore.php | 2 +- src/Package/Graphql.php | 2 +- src/Package/Issues.php | 2 +- src/Package/Issues/Assignees.php | 2 +- src/Package/Issues/Comments.php | 2 +- src/Package/Issues/Events.php | 2 +- src/Package/Issues/Labels.php | 2 +- src/Package/Issues/Milestones.php | 2 +- src/Package/Markdown.php | 2 +- src/Package/Meta.php | 2 +- src/Package/Orgs.php | 2 +- src/Package/Orgs/Hooks.php | 2 +- src/Package/Orgs/Members.php | 2 +- src/Package/Orgs/Teams.php | 2 +- src/Package/Pulls.php | 2 +- src/Package/Pulls/Comments.php | 2 +- src/Package/Repositories.php | 2 +- src/Package/Repositories/Branches.php | 2 +- src/Package/Repositories/Collaborators.php | 2 +- src/Package/Repositories/Comments.php | 2 +- src/Package/Repositories/Commits.php | 2 +- src/Package/Repositories/Contents.php | 2 +- src/Package/Repositories/Deployments.php | 2 +- src/Package/Repositories/Downloads.php | 2 +- src/Package/Repositories/Forks.php | 2 +- src/Package/Repositories/Hooks.php | 2 +- src/Package/Repositories/Keys.php | 2 +- src/Package/Repositories/Merging.php | 2 +- src/Package/Repositories/Pages.php | 2 +- src/Package/Repositories/Releases.php | 2 +- src/Package/Repositories/Statistics.php | 2 +- src/Package/Repositories/Statuses.php | 2 +- src/Package/Search.php | 2 +- src/Package/Users.php | 2 +- src/Package/Users/Emails.php | 2 +- src/Package/Users/Followers.php | 2 +- src/Package/Users/Keys.php | 2 +- src/Package/Zen.php | 2 +- 114 files changed, 114 insertions(+), 114 deletions(-) diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index c42d371f..b85cb8eb 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -1,6 +1,6 @@ Date: Sun, 21 Aug 2022 15:26:06 +0200 Subject: [PATCH 62/79] Enable CI for PHP 8.2 --- .drone.jsonnet | 8 +- .drone.yml | 531 +++++++++++++++++++++++++++++++------------------ composer.json | 8 +- 3 files changed, 346 insertions(+), 201 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index ab2b93f7..0bedfefe 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -25,7 +25,7 @@ local composer(phpversion, params) = { local phpunit(phpversion) = { name: "PHPUnit", image: "joomlaprojects/docker-images:php" + phpversion, - [if phpversion == "8.0" then "failure"]: "ignore", + [if phpversion == "8.2" then "failure"]: "ignore", commands: ["vendor/bin/phpunit"] }; @@ -61,7 +61,7 @@ local pipeline(name, phpversion, params) = { depends: [ "composer" ], commands: [ "vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards", - "vendor/bin/phpcs -p --report=full --extensions=php --standard=ruleset.xml src/" + "vendor/bin/phpcs --standard=ruleset.xml src/" ] }, { @@ -110,5 +110,7 @@ local pipeline(name, phpversion, params) = { pipeline("7.2", "7.2", "--prefer-stable"), pipeline("7.3", "7.3", "--prefer-stable"), pipeline("7.4", "7.4", "--prefer-stable"), - pipeline("8.0", "8.0", "--ignore-platform-reqs --prefer-stable") + pipeline("8.0", "8.0", "--prefer-stable"), + pipeline("8.1", "8.1", "--prefer-stable"), + pipeline("8.2", "8.2", "--prefer-stable --ignore-platform-reqs"), ] diff --git a/.drone.yml b/.drone.yml index dba56c1e..6a9a6920 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,204 +1,347 @@ --- -kind: pipeline -name: Codequality - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php7.4 - commands: - - php -v - - composer update - - composer require phpmd/phpmd phpstan/phpstan - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: phpcs - image: joomlaprojects/docker-images:php7.4 - commands: - - vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards - - vendor/bin/phpcs -p --report=full --extensions=php --standard=ruleset.xml src/ - -- name: phpmd - image: joomlaprojects/docker-images:php7.4 - commands: - - vendor/bin/phpmd src text cleancode - - vendor/bin/phpmd src text codesize - - vendor/bin/phpmd src text controversial - - vendor/bin/phpmd src text design - - vendor/bin/phpmd src text unusedcode - failure: ignore - -- name: phpstan - image: joomlaprojects/docker-images:php7.4 - commands: - - vendor/bin/phpstan analyse src - failure: ignore - -- name: phploc - image: joomlaprojects/docker-images:php7.4 - commands: - - phploc src - failure: ignore - -- name: phpcpd - image: joomlaprojects/docker-images:php7.4 - commands: - - phpcpd src - failure: ignore - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - +{ + "kind": "pipeline", + "name": "Codequality", + "steps": [ + { + "commands": [ + "php -v", + "composer update", + "composer require phpmd/phpmd phpstan/phpstan" + ], + "image": "joomlaprojects/docker-images:php7.4", + "name": "composer", + "volumes": [ + { + "name": "composer-cache", + "path": "/tmp/composer-cache" + } + ] + }, + { + "commands": [ + "vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards", + "vendor/bin/phpcs --standard=ruleset.xml src/" + ], + "depends": [ + "composer" + ], + "image": "joomlaprojects/docker-images:php7.4", + "name": "phpcs" + }, + { + "commands": [ + "vendor/bin/phpmd src text cleancode", + "vendor/bin/phpmd src text codesize", + "vendor/bin/phpmd src text controversial", + "vendor/bin/phpmd src text design", + "vendor/bin/phpmd src text unusedcode" + ], + "depends": [ + "composer" + ], + "failure": "ignore", + "image": "joomlaprojects/docker-images:php7.4", + "name": "phpmd" + }, + { + "commands": [ + "vendor/bin/phpstan analyse src" + ], + "depends": [ + "composer" + ], + "failure": "ignore", + "image": "joomlaprojects/docker-images:php7.4", + "name": "phpstan" + }, + { + "commands": [ + "phploc src" + ], + "depends": [ + "composer" + ], + "failure": "ignore", + "image": "joomlaprojects/docker-images:php7.4", + "name": "phploc" + }, + { + "commands": [ + "phpcpd src" + ], + "depends": [ + "composer" + ], + "failure": "ignore", + "image": "joomlaprojects/docker-images:php7.4", + "name": "phpcpd" + } + ], + "volumes": [ + { + "host": { + "path": "/tmp/composer-cache" + }, + "name": "composer-cache" + } + ] +} --- -kind: pipeline -name: PHP 7.2 lowest - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php7.2 - commands: - - php -v - - composer update --prefer-stable --prefer-lowest - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php7.2 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - +{ + "kind": "pipeline", + "name": "PHP 7.2 lowest", + "steps": [ + { + "commands": [ + "php -v", + "composer update --prefer-stable --prefer-lowest" + ], + "image": "joomlaprojects/docker-images:php7.2", + "name": "composer", + "volumes": [ + { + "name": "composer-cache", + "path": "/tmp/composer-cache" + } + ] + }, + { + "commands": [ + "vendor/bin/phpunit" + ], + "image": "joomlaprojects/docker-images:php7.2", + "name": "PHPUnit" + } + ], + "volumes": [ + { + "host": { + "path": "/tmp/composer-cache" + }, + "name": "composer-cache" + } + ] +} --- -kind: pipeline -name: PHP 7.2 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php7.2 - commands: - - php -v - - composer update --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php7.2 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - +{ + "kind": "pipeline", + "name": "PHP 7.2", + "steps": [ + { + "commands": [ + "php -v", + "composer update --prefer-stable" + ], + "image": "joomlaprojects/docker-images:php7.2", + "name": "composer", + "volumes": [ + { + "name": "composer-cache", + "path": "/tmp/composer-cache" + } + ] + }, + { + "commands": [ + "vendor/bin/phpunit" + ], + "image": "joomlaprojects/docker-images:php7.2", + "name": "PHPUnit" + } + ], + "volumes": [ + { + "host": { + "path": "/tmp/composer-cache" + }, + "name": "composer-cache" + } + ] +} --- -kind: pipeline -name: PHP 7.3 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php7.3 - commands: - - php -v - - composer update --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php7.3 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - +{ + "kind": "pipeline", + "name": "PHP 7.3", + "steps": [ + { + "commands": [ + "php -v", + "composer update --prefer-stable" + ], + "image": "joomlaprojects/docker-images:php7.3", + "name": "composer", + "volumes": [ + { + "name": "composer-cache", + "path": "/tmp/composer-cache" + } + ] + }, + { + "commands": [ + "vendor/bin/phpunit" + ], + "image": "joomlaprojects/docker-images:php7.3", + "name": "PHPUnit" + } + ], + "volumes": [ + { + "host": { + "path": "/tmp/composer-cache" + }, + "name": "composer-cache" + } + ] +} --- -kind: pipeline -name: PHP 7.4 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php7.4 - commands: - - php -v - - composer update --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php7.4 - commands: - - vendor/bin/phpunit - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - +{ + "kind": "pipeline", + "name": "PHP 7.4", + "steps": [ + { + "commands": [ + "php -v", + "composer update --prefer-stable" + ], + "image": "joomlaprojects/docker-images:php7.4", + "name": "composer", + "volumes": [ + { + "name": "composer-cache", + "path": "/tmp/composer-cache" + } + ] + }, + { + "commands": [ + "vendor/bin/phpunit" + ], + "image": "joomlaprojects/docker-images:php7.4", + "name": "PHPUnit" + } + ], + "volumes": [ + { + "host": { + "path": "/tmp/composer-cache" + }, + "name": "composer-cache" + } + ] +} --- -kind: pipeline -name: PHP 8.0 - -platform: - os: linux - arch: amd64 - -steps: -- name: composer - image: joomlaprojects/docker-images:php8.0 - commands: - - php -v - - composer update --ignore-platform-reqs --prefer-stable - volumes: - - name: composer-cache - path: /tmp/composer-cache - -- name: PHPUnit - image: joomlaprojects/docker-images:php8.0 - commands: - - vendor/bin/phpunit - failure: ignore - -volumes: -- name: composer-cache - host: - path: /tmp/composer-cache - +{ + "kind": "pipeline", + "name": "PHP 8.0", + "steps": [ + { + "commands": [ + "php -v", + "composer update --prefer-stable" + ], + "image": "joomlaprojects/docker-images:php8.0", + "name": "composer", + "volumes": [ + { + "name": "composer-cache", + "path": "/tmp/composer-cache" + } + ] + }, + { + "commands": [ + "vendor/bin/phpunit" + ], + "image": "joomlaprojects/docker-images:php8.0", + "name": "PHPUnit" + } + ], + "volumes": [ + { + "host": { + "path": "/tmp/composer-cache" + }, + "name": "composer-cache" + } + ] +} +--- +{ + "kind": "pipeline", + "name": "PHP 8.1", + "steps": [ + { + "commands": [ + "php -v", + "composer update --prefer-stable" + ], + "image": "joomlaprojects/docker-images:php8.1", + "name": "composer", + "volumes": [ + { + "name": "composer-cache", + "path": "/tmp/composer-cache" + } + ] + }, + { + "commands": [ + "vendor/bin/phpunit" + ], + "image": "joomlaprojects/docker-images:php8.1", + "name": "PHPUnit" + } + ], + "volumes": [ + { + "host": { + "path": "/tmp/composer-cache" + }, + "name": "composer-cache" + } + ] +} +--- +{ + "kind": "pipeline", + "name": "PHP 8.2", + "steps": [ + { + "commands": [ + "php -v", + "composer update --prefer-stable --ignore-platform-reqs" + ], + "image": "joomlaprojects/docker-images:php8.2", + "name": "composer", + "volumes": [ + { + "name": "composer-cache", + "path": "/tmp/composer-cache" + } + ] + }, + { + "commands": [ + "vendor/bin/phpunit" + ], + "failure": "ignore", + "image": "joomlaprojects/docker-images:php8.2", + "name": "PHPUnit" + } + ], + "volumes": [ + { + "host": { + "path": "/tmp/composer-cache" + }, + "name": "composer-cache" + } + ] +} --- kind: signature -hmac: 0fef580d9a845caea4e052805765ee3f357d4e1b1f1573f69bbb428ae7822e7b +hmac: 0f630909a1c433137ead18e482d0367110ab613381af2840e3cde18d54fd9ac9 ... diff --git a/composer.json b/composer.json index 5cd9fa5e..ed71f64f 100644 --- a/composer.json +++ b/composer.json @@ -6,10 +6,10 @@ "homepage": "https://github.com/joomla-framework/github-api", "license": "GPL-2.0-or-later", "require": { - "php": "^7.2.5", - "joomla/http": "^1.3|^2.0", - "joomla/registry": "^1.4.5|^2.0", - "joomla/uri": "^1.0|^2.0" + "php": "^7.2.5|~8.0.0|~8.1.0", + "joomla/http": "^2.0", + "joomla/registry": "^2.0", + "joomla/uri": "^2.0" }, "require-dev": { "joomla/coding-standards": "^3.0@dev", From 2f4d5a2be36681cb8eaf62c640514a93c115cb8d Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Sun, 21 Aug 2022 17:54:32 +0200 Subject: [PATCH 63/79] Update badges --- README.md | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 56187dc1..8296f2b2 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,22 @@ -# The Github Package [![Build Status](https://ci.joomla.org/api/badges/joomla-framework/github-api/status.svg?ref=refs/heads/2.0-dev)](https://ci.joomla.org/joomla-framework/github-api) +# The GitHub Package [![Build Status](https://ci.joomla.org/api/badges/joomla-framework/github-api/status.svg?ref=refs/heads/2.0-dev)](https://ci.joomla.org/joomla-framework/github-api) -## Using the Github Package +[![Latest Stable Version](https://poser.pugx.org/joomla/github/v/stable)](https://packagist.org/packages/joomla/github) +[![Total Downloads](https://poser.pugx.org/joomla/github/downloads)](https://packagist.org/packages/joomla/github) +[![Latest Unstable Version](https://poser.pugx.org/joomla/github/v/unstable)](https://packagist.org/packages/joomla/github) +[![License](https://poser.pugx.org/joomla/github/license)](https://packagist.org/packages/joomla/github) -The Github package is designed to be a straightforward interface for working with Github. It is based on version 3 of -the Github API. You can find documentation on the API at [http://developer.github.com/v3/](http://developer.github.com/v3/). +## Using the GitHub Package -Github is built upon the Http package which provides an easy way to consume URLs and web services in a transport +The GitHub package is designed to be a straightforward interface for working with GitHub. It is based on version 3 of +the GitHub API. You can find documentation on the API at [http://developer.github.com/v3/](http://developer.github.com/v3/). + +GitHub is built upon the Http package which provides an easy way to consume URLs and web services in a transport independent way. `Joomla\Http` currently supports streams, sockets and cURL. It is possible to create a custom -context and inject it into the Github class if one so desires. +context and inject it into the GitHub class if one so desires. -### Instantiating Github +### Instantiating GitHub -Instantiating Github is easy: +Instantiating GitHub is easy: ```php use Joomla\Github\Github; @@ -19,11 +24,11 @@ use Joomla\Github\Github; $github = new Github; ``` -This creates a basic Github object that can be used to access publicly available resources on [github.com](https://github.com). +This creates a basic GitHub object that can be used to access publicly available resources on [github.com](https://github.com). Sometimes it is necessary to specify additional options. This can be done by injecting in a Registry object with your -preferred options. Support is available for optionally providing a custom Github account username and password, -as well as a custom URL for the Github server (as would be the case for using a local instance of [Github Enterprise](https://enterprise.github.com)). +preferred options. Support is available for optionally providing a custom GitHub account username and password, +as well as a custom URL for the GitHub server (as would be the case for using a local instance of [GitHub Enterprise](https://enterprise.github.com)). ```php use Joomla\Github\Github; @@ -39,7 +44,7 @@ $github = new Github($options); A `gh.token` option is also available. -Here is an example demonstrating more of the Github package: +Here is an example demonstrating more of the GitHub package: ```php use Joomla\Github\Github; @@ -67,13 +72,13 @@ $summary = implode("\n", $issueSummary); $github->gists->create(array('issue_summary.txt' => $summary)); ``` -## Accessing the Github APIs +## Accessing the GitHub APIs -The Github object using magic methods to access sub-packages of the Github server's API that can be accessed using +The GitHub object using magic methods to access sub-packages of the GitHub server's API that can be accessed using the `->` object operator. Where a result is returned by a PHP method, the result is the PHP equivalent of the JSON response that can be found in -the Github API documentation. +the GitHub API documentation. ### Activity @@ -743,7 +748,7 @@ $github->pulls->comments->delete(':owner', ':repo', ':commentId'); ## See Also The following resources contain more information: [Joomla! API Reference](http://api.joomla.org), -[Github API Reference](http://developer.github.com). +[GitHub API Reference](http://developer.github.com). ## Installation via Composer From 805bf428ccd2ba3d9dbb98b70f6ca7705ebb186d Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Tue, 31 Jan 2023 20:56:28 +0100 Subject: [PATCH 64/79] Raising PHP minimum requirements to 8.1.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ed71f64f..faeeadee 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "homepage": "https://github.com/joomla-framework/github-api", "license": "GPL-2.0-or-later", "require": { - "php": "^7.2.5|~8.0.0|~8.1.0", + "php": "~8.1.0", "joomla/http": "^2.0", "joomla/registry": "^2.0", "joomla/uri": "^2.0" From df3bc0980e27412b92a9222ab26a39a735acf7bd Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Tue, 31 Jan 2023 21:04:53 +0100 Subject: [PATCH 65/79] Setting codestyle to PSR-12 --- ruleset.xml | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/ruleset.xml b/ruleset.xml index 07be5d2b..84b19745 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,28 +1,23 @@ - + + + This is a PSR-12 compliant ruleset for Joomla. + + src + Tests + + */Tests/Stubs/* + + - + - - */.github/* - */.travis/* - - - */vendor/* - - - - - - - - - - - + + + From c76e73f45b741e79260873691b09ea68a1c9af89 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Tue, 31 Jan 2023 21:18:00 +0100 Subject: [PATCH 66/79] Removing Joomla codingstandard dependency and adding php_codesniffer --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index faeeadee..b98ce4ac 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,8 @@ "joomla/uri": "^2.0" }, "require-dev": { - "joomla/coding-standards": "^3.0@dev", - "phpunit/phpunit": "^8.5|^9.0" + "phpunit/phpunit": "^8.5|^9.0", + "squizlabs/php_codesniffer": "~3.7.1" }, "autoload": { "psr-4": { From 7649a8dc35146bf66a9d6106f66ed2591af3bd32 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Tue, 31 Jan 2023 21:54:50 +0100 Subject: [PATCH 67/79] Updating drone configuration --- .drone.jsonnet | 19 +++--- .drone.yml | 165 +++---------------------------------------------- 2 files changed, 17 insertions(+), 167 deletions(-) diff --git a/.drone.jsonnet b/.drone.jsonnet index 0bedfefe..1e236fb3 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -47,7 +47,7 @@ local pipeline(name, phpversion, params) = { steps: [ { name: "composer", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", volumes: volumes, commands: [ "php -v", @@ -57,16 +57,15 @@ local pipeline(name, phpversion, params) = { }, { name: "phpcs", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", depends: [ "composer" ], commands: [ - "vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards", "vendor/bin/phpcs --standard=ruleset.xml src/" ] }, { name: "phpmd", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", depends: [ "composer" ], failure: "ignore", commands: [ @@ -79,7 +78,7 @@ local pipeline(name, phpversion, params) = { }, { name: "phpstan", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", depends: [ "composer" ], failure: "ignore", commands: [ @@ -88,7 +87,7 @@ local pipeline(name, phpversion, params) = { }, { name: "phploc", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", depends: [ "composer" ], failure: "ignore", commands: [ @@ -97,7 +96,7 @@ local pipeline(name, phpversion, params) = { }, { name: "phpcpd", - image: "joomlaprojects/docker-images:php7.4", + image: "joomlaprojects/docker-images:php8.1", depends: [ "composer" ], failure: "ignore", commands: [ @@ -106,11 +105,7 @@ local pipeline(name, phpversion, params) = { } ] }, - pipeline("7.2 lowest", "7.2", "--prefer-stable --prefer-lowest"), - pipeline("7.2", "7.2", "--prefer-stable"), - pipeline("7.3", "7.3", "--prefer-stable"), - pipeline("7.4", "7.4", "--prefer-stable"), - pipeline("8.0", "8.0", "--prefer-stable"), + pipeline("8.1 lowest", "8.1", "--prefer-stable --prefer-lowest"), pipeline("8.1", "8.1", "--prefer-stable"), pipeline("8.2", "8.2", "--prefer-stable --ignore-platform-reqs"), ] diff --git a/.drone.yml b/.drone.yml index 6a9a6920..341d9d51 100644 --- a/.drone.yml +++ b/.drone.yml @@ -9,7 +9,7 @@ "composer update", "composer require phpmd/phpmd phpstan/phpstan" ], - "image": "joomlaprojects/docker-images:php7.4", + "image": "joomlaprojects/docker-images:php8.1", "name": "composer", "volumes": [ { @@ -20,13 +20,12 @@ }, { "commands": [ - "vendor/bin/phpcs --config-set installed_paths vendor/joomla/coding-standards", "vendor/bin/phpcs --standard=ruleset.xml src/" ], "depends": [ "composer" ], - "image": "joomlaprojects/docker-images:php7.4", + "image": "joomlaprojects/docker-images:php8.1", "name": "phpcs" }, { @@ -41,7 +40,7 @@ "composer" ], "failure": "ignore", - "image": "joomlaprojects/docker-images:php7.4", + "image": "joomlaprojects/docker-images:php8.1", "name": "phpmd" }, { @@ -52,7 +51,7 @@ "composer" ], "failure": "ignore", - "image": "joomlaprojects/docker-images:php7.4", + "image": "joomlaprojects/docker-images:php8.1", "name": "phpstan" }, { @@ -63,7 +62,7 @@ "composer" ], "failure": "ignore", - "image": "joomlaprojects/docker-images:php7.4", + "image": "joomlaprojects/docker-images:php8.1", "name": "phploc" }, { @@ -74,7 +73,7 @@ "composer" ], "failure": "ignore", - "image": "joomlaprojects/docker-images:php7.4", + "image": "joomlaprojects/docker-images:php8.1", "name": "phpcpd" } ], @@ -90,158 +89,14 @@ --- { "kind": "pipeline", - "name": "PHP 7.2 lowest", + "name": "PHP 8.1 lowest", "steps": [ { "commands": [ "php -v", "composer update --prefer-stable --prefer-lowest" ], - "image": "joomlaprojects/docker-images:php7.2", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php7.2", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 7.2", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable" - ], - "image": "joomlaprojects/docker-images:php7.2", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php7.2", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 7.3", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable" - ], - "image": "joomlaprojects/docker-images:php7.3", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php7.3", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 7.4", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable" - ], - "image": "joomlaprojects/docker-images:php7.4", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php7.4", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} ---- -{ - "kind": "pipeline", - "name": "PHP 8.0", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable" - ], - "image": "joomlaprojects/docker-images:php8.0", + "image": "joomlaprojects/docker-images:php8.1", "name": "composer", "volumes": [ { @@ -254,7 +109,7 @@ "commands": [ "vendor/bin/phpunit" ], - "image": "joomlaprojects/docker-images:php8.0", + "image": "joomlaprojects/docker-images:php8.1", "name": "PHPUnit" } ], @@ -342,6 +197,6 @@ } --- kind: signature -hmac: 0f630909a1c433137ead18e482d0367110ab613381af2840e3cde18d54fd9ac9 +hmac: 76b430f45f715002fd687d4ae23425ab479d656bdc36645198e302b6052f070f ... From 6215bab3896b7223da9862496ef63ddc28166af5 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Tue, 31 Jan 2023 22:45:16 +0100 Subject: [PATCH 68/79] Converting Codestyle to PSR12 --- Tests/GithubObjectTest.php | 236 +- Tests/GithubTest.php | 232 +- Tests/Package/Activity/EventsTest.php | 460 ++-- Tests/Package/Activity/FeedsTest.php | 68 +- Tests/Package/Activity/NotificationsTest.php | 548 ++-- Tests/Package/Activity/StarringTest.php | 456 ++-- Tests/Package/Activity/WatchingTest.php | 470 ++-- Tests/Package/ActivityTest.php | 62 +- Tests/Package/AuthorizationsTest.php | 1404 +++++----- Tests/Package/Data/BlobsTest.php | 102 +- Tests/Package/Data/CommitsTest.php | 102 +- Tests/Package/Data/RefsTest.php | 536 ++-- Tests/Package/Data/TagsTest.php | 106 +- Tests/Package/Data/TreesTest.php | 134 +- Tests/Package/DataTest.php | 62 +- Tests/Package/EmojisTest.php | 119 +- Tests/Package/GistsTest.php | 2368 ++++++++--------- Tests/Package/GitignoreTest.php | 220 +- Tests/Package/GraphqlTest.php | 195 +- Tests/Package/Issues/AssigneesTest.php | 348 +-- Tests/Package/Issues/CommentsTest.php | 354 +-- Tests/Package/Issues/EventsTest.php | 132 +- Tests/Package/Issues/LabelsTest.php | 494 ++-- Tests/Package/Issues/MilestonesTest.php | 548 ++-- Tests/Package/IssuesTest.php | 1016 +++---- Tests/Package/MarkdownTest.php | 222 +- Tests/Package/MetaTest.php | 124 +- Tests/Package/Orgs/HooksTest.php | 410 +-- Tests/Package/Orgs/MembersTest.php | 962 +++---- Tests/Package/Orgs/TeamsTest.php | 1164 ++++---- Tests/Package/OrgsTest.php | 130 +- Tests/Package/Pulls/CommentsTest.php | 340 +-- Tests/Package/PullsTest.php | 856 +++--- Tests/Package/Repositories/BranchesTest.php | 106 +- .../Repositories/CollaboratorsTest.php | 284 +- Tests/Package/Repositories/CommentsTest.php | 262 +- Tests/Package/Repositories/CommitsTest.php | 370 +-- Tests/Package/Repositories/ContentsTest.php | 675 ++--- .../Package/Repositories/DeploymentsTest.php | 315 +-- Tests/Package/Repositories/DownloadsTest.php | 217 +- Tests/Package/Repositories/ForksTest.php | 220 +- Tests/Package/Repositories/HooksTest.php | 968 +++---- Tests/Package/Repositories/KeysTest.php | 228 +- Tests/Package/Repositories/MergingTest.php | 256 +- Tests/Package/Repositories/PagesTest.php | 130 +- Tests/Package/Repositories/ReleasesTest.php | 535 ++-- Tests/Package/Repositories/StatisticsTest.php | 264 +- Tests/Package/Repositories/StatusesTest.php | 352 +-- Tests/Package/RepositoriesTest.php | 712 ++--- Tests/Package/SearchTest.php | 182 +- Tests/Package/Users/EmailsTest.php | 134 +- Tests/Package/Users/FollowersTest.php | 602 ++--- Tests/Package/Users/KeysTest.php | 262 +- Tests/Package/UsersTest.php | 420 +-- Tests/Package/ZenTest.php | 108 +- Tests/PackageTest.php | 88 +- Tests/Stub/GitHubTestCase.php | 92 +- Tests/Stub/ObjectMock.php | 38 +- Tests/bootstrap.php | 3 +- src/AbstractGithubObject.php | 305 ++- src/AbstractPackage.php | 84 +- src/Github.php | 172 +- src/Package/Activity/Events.php | 402 +-- src/Package/Activity/Feeds.php | 30 +- src/Package/Activity/Notifications.php | 556 ++-- src/Package/Activity/Starring.php | 299 ++- src/Package/Activity/Watching.php | 379 ++- src/Package/Authorization.php | 698 +++-- src/Package/Data/Blobs.php | 88 +- src/Package/Data/Commits.php | 92 +- src/Package/Data/Refs.php | 272 +- src/Package/Data/Tags.php | 122 +- src/Package/Data/Trees.php | 169 +- src/Package/Emojis.php | 30 +- src/Package/Gists.php | 800 +++--- src/Package/Gists/Comments.php | 202 +- src/Package/Gitignore.php | 94 +- src/Package/Graphql.php | 59 +- src/Package/Issues.php | 656 +++-- src/Package/Issues/Assignees.php | 217 +- src/Package/Issues/Comments.php | 384 ++- src/Package/Issues/Events.php | 116 +- src/Package/Issues/Labels.php | 484 ++-- src/Package/Issues/Milestones.php | 331 ++- src/Package/Markdown.php | 94 +- src/Package/Meta.php | 26 +- src/Package/Orgs.php | 144 +- src/Package/Orgs/Hooks.php | 435 ++- src/Package/Orgs/Members.php | 663 +++-- src/Package/Orgs/Teams.php | 951 ++++--- src/Package/Pulls.php | 571 ++-- src/Package/Pulls/Comments.php | 382 +-- src/Package/Repositories.php | 754 +++--- src/Package/Repositories/Branches.php | 78 +- src/Package/Repositories/Collaborators.php | 177 +- src/Package/Repositories/Comments.php | 312 +-- src/Package/Repositories/Commits.php | 260 +- src/Package/Repositories/Contents.php | 635 ++--- src/Package/Repositories/Deployments.php | 386 ++- src/Package/Repositories/Downloads.php | 270 +- src/Package/Repositories/Forks.php | 95 +- src/Package/Repositories/Hooks.php | 424 ++- src/Package/Repositories/Keys.php | 216 +- src/Package/Repositories/Merging.php | 124 +- src/Package/Repositories/Pages.php | 112 +- src/Package/Repositories/Releases.php | 618 +++-- src/Package/Repositories/Statistics.php | 277 +- src/Package/Repositories/Statuses.php | 166 +- src/Package/Search.php | 210 +- src/Package/Users.php | 185 +- src/Package/Users/Emails.php | 104 +- src/Package/Users/Followers.php | 302 ++- src/Package/Users/Keys.php | 264 +- src/Package/Zen.php | 31 +- 114 files changed, 19502 insertions(+), 19608 deletions(-) diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index b85cb8eb..5ad836f4 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -16,134 +16,134 @@ */ class GithubObjectTest extends GitHubTestCase { - /** - * @var ObjectMock Object under test. - * @since 1.0 - */ - protected $object; + /** + * @var ObjectMock Object under test. + * @since 1.0 + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @return void - * - * @since 1.0 - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new ObjectMock($this->options, $this->client); - } + $this->object = new ObjectMock($this->options, $this->client); + } - /** - * Data provider method for the fetchUrl method tests. - * - * @return array - * - * @since 1.0 - */ - public function fetchUrlData() - { - return array( - 'Standard github - no pagination data' => array( - 'https://api.github.com', - '/gists', - 0, - 0, - 'https://api.github.com/gists' - ), - 'Enterprise github - no pagination data' => array( - 'https://mygithub.com', - '/gists', - 0, - 0, - 'https://mygithub.com/gists' - ), - 'Standard github - page 3' => array( - 'https://api.github.com', - '/gists', - 3, - 0, - 'https://api.github.com/gists?page=3' - ), - 'Enterprise github - page 3, 50 per page' => array( - 'https://mygithub.com', - '/gists', - 3, - 50, - 'https://mygithub.com/gists?page=3&per_page=50' - ), - ); - } + /** + * Data provider method for the fetchUrl method tests. + * + * @return array + * + * @since 1.0 + */ + public function fetchUrlData() + { + return [ + 'Standard github - no pagination data' => [ + 'https://api.github.com', + '/gists', + 0, + 0, + 'https://api.github.com/gists', + ], + 'Enterprise github - no pagination data' => [ + 'https://mygithub.com', + '/gists', + 0, + 0, + 'https://mygithub.com/gists', + ], + 'Standard github - page 3' => [ + 'https://api.github.com', + '/gists', + 3, + 0, + 'https://api.github.com/gists?page=3', + ], + 'Enterprise github - page 3, 50 per page' => [ + 'https://mygithub.com', + '/gists', + 3, + 50, + 'https://mygithub.com/gists?page=3&per_page=50', + ], + ]; + } - /** - * Tests the fetchUrl method - * - * @param string $apiUrl @todo - * @param string $path @todo - * @param integer $page @todo - * @param integer $limit @todo - * @param string $expected @todo - * - * @return void - * - * @since 1.0 - * @dataProvider fetchUrlData - */ - public function testFetchUrl($apiUrl, $path, $page, $limit, $expected) - { - $this->options->set('api.url', $apiUrl); + /** + * Tests the fetchUrl method + * + * @param string $apiUrl @todo + * @param string $path @todo + * @param integer $page @todo + * @param integer $limit @todo + * @param string $expected @todo + * + * @return void + * + * @since 1.0 + * @dataProvider fetchUrlData + */ + public function testFetchUrl($apiUrl, $path, $page, $limit, $expected) + { + $this->options->set('api.url', $apiUrl); - $this->assertThat( - $this->object->fetchUrl($path, $page, $limit), - $this->equalTo($expected) - ); - } + $this->assertThat( + $this->object->fetchUrl($path, $page, $limit), + $this->equalTo($expected) + ); + } - /** - * Tests the fetchUrl method with basic authentication data - * - * @return void - * - * @since 1.0 - */ - public function testFetchUrlBasicAuth() - { - $this->options->set('api.url', 'https://api.github.com'); + /** + * Tests the fetchUrl method with basic authentication data + * + * @return void + * + * @since 1.0 + */ + public function testFetchUrlBasicAuth() + { + $this->options->set('api.url', 'https://api.github.com'); - $this->options->set('api.username', 'MyTestUser'); - $this->options->set('api.password', 'MyTestPass'); + $this->options->set('api.username', 'MyTestUser'); + $this->options->set('api.password', 'MyTestPass'); - $this->assertThat( - $this->object->fetchUrl('/gists', 0, 0), - $this->equalTo('https://MyTestUser:MyTestPass@api.github.com/gists'), - 'URL is not as expected.' - ); - } + $this->assertThat( + $this->object->fetchUrl('/gists', 0, 0), + $this->equalTo('https://MyTestUser:MyTestPass@api.github.com/gists'), + 'URL is not as expected.' + ); + } - /** - * Tests the fetchUrl method using an oAuth token. - * - * @return void - */ - public function testFetchUrlToken() - { - $this->options->set('api.url', 'https://api.github.com'); + /** + * Tests the fetchUrl method using an oAuth token. + * + * @return void + */ + public function testFetchUrlToken() + { + $this->options->set('api.url', 'https://api.github.com'); - $this->options->set('gh.token', 'MyTestToken'); + $this->options->set('gh.token', 'MyTestToken'); - $this->assertThat( - (string) $this->object->fetchUrl('/gists', 0, 0), - $this->equalTo('https://api.github.com/gists'), - 'URL is not as expected.' - ); + $this->assertThat( + (string) $this->object->fetchUrl('/gists', 0, 0), + $this->equalTo('https://api.github.com/gists'), + 'URL is not as expected.' + ); - $this->assertThat( - $this->client->getOption('headers'), - $this->equalTo(['Authorization' => 'token MyTestToken']), - 'Token should be propagated as a header.' - ); - } + $this->assertThat( + $this->client->getOption('headers'), + $this->equalTo(['Authorization' => 'token MyTestToken']), + 'Token should be propagated as a header.' + ); + } } diff --git a/Tests/GithubTest.php b/Tests/GithubTest.php index 68960064..f916a7ac 100755 --- a/Tests/GithubTest.php +++ b/Tests/GithubTest.php @@ -16,132 +16,132 @@ */ class GithubTest extends GitHubTestCase { - /** - * @var Github Object under test. - * @since 1.0 - */ - protected $object; + /** + * @var Github Object under test. + * @since 1.0 + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @return void - * - * @since 1.0 - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Github($this->options, $this->client); - } + $this->object = new Github($this->options, $this->client); + } - /** - * Tests the magic __get method - forks - * - * @return void - * - * @since 1.0 - */ - public function testGetForks() - { - $this->assertThat( - $this->object->repositories->forks, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Forks') - ); - } + /** + * Tests the magic __get method - forks + * + * @return void + * + * @since 1.0 + */ + public function testGetForks() + { + $this->assertThat( + $this->object->repositories->forks, + $this->isInstanceOf('Joomla\Github\Package\Repositories\Forks') + ); + } - /** - * Tests the magic __get method - commits - * - * @return void - * - * @since 1.0 - */ - public function testGetCommits() - { - $this->assertThat( - $this->object->repositories->commits, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Commits') - ); - } + /** + * Tests the magic __get method - commits + * + * @return void + * + * @since 1.0 + */ + public function testGetCommits() + { + $this->assertThat( + $this->object->repositories->commits, + $this->isInstanceOf('Joomla\Github\Package\Repositories\Commits') + ); + } - /** - * Tests the magic __get method - statuses - * - * @return void - * - * @since 1.0 - */ - public function testGetStatuses() - { - $this->assertThat( - $this->object->repositories->statuses, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Statuses') - ); - } + /** + * Tests the magic __get method - statuses + * + * @return void + * + * @since 1.0 + */ + public function testGetStatuses() + { + $this->assertThat( + $this->object->repositories->statuses, + $this->isInstanceOf('Joomla\Github\Package\Repositories\Statuses') + ); + } - /** - * Tests the magic __get method - hooks - * - * @return void - * - * @since 1.0 - */ - public function testGetHooks() - { - $this->assertThat( - $this->object->repositories->hooks, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Hooks') - ); - } + /** + * Tests the magic __get method - hooks + * + * @return void + * + * @since 1.0 + */ + public function testGetHooks() + { + $this->assertThat( + $this->object->repositories->hooks, + $this->isInstanceOf('Joomla\Github\Package\Repositories\Hooks') + ); + } - /** - * Tests the magic __get method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetFailure() - { - $this->expectException(\InvalidArgumentException::class); + /** + * Tests the magic __get method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetFailure() + { + $this->expectException(\InvalidArgumentException::class); - $this->object->other; - } + $this->object->other; + } - /** - * Tests the setOption method - * - * @return void - * - * @since 1.0 - */ - public function testSetOption() - { - $this->object->setOption('api.url', 'https://example.com/settest'); + /** + * Tests the setOption method + * + * @return void + * + * @since 1.0 + */ + public function testSetOption() + { + $this->object->setOption('api.url', 'https://example.com/settest'); - $this->assertThat( - $this->options->get('api.url'), - $this->equalTo('https://example.com/settest') - ); - } + $this->assertThat( + $this->options->get('api.url'), + $this->equalTo('https://example.com/settest') + ); + } - /** - * Tests the getOption method - * - * @return void - * - * @since 1.0 - */ - public function testGetOption() - { - $this->options->set('api.url', 'https://example.com/gettest'); + /** + * Tests the getOption method + * + * @return void + * + * @since 1.0 + */ + public function testGetOption() + { + $this->options->set('api.url', 'https://example.com/gettest'); - $this->assertThat( - $this->object->getOption('api.url'), - $this->equalTo('https://example.com/gettest') - ); - } + $this->assertThat( + $this->object->getOption('api.url'), + $this->equalTo('https://example.com/gettest') + ); + } } diff --git a/Tests/Package/Activity/EventsTest.php b/Tests/Package/Activity/EventsTest.php index c214f922..a0f41891 100644 --- a/Tests/Package/Activity/EventsTest.php +++ b/Tests/Package/Activity/EventsTest.php @@ -16,234 +16,234 @@ */ class EventsTest extends GitHubTestCase { - /** - * @var Events Object under test. - * @since 1.0 - */ - protected $object; - - /** - * @var string - * @since 1.0 - */ - protected $owner = 'joomla'; - - /** - * @var string - * @since 1.0 - */ - protected $repo = 'joomla-framework'; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Events($this->options, $this->client); - } - - /** - * Tests the getPublic method - * - * @return void - */ - public function testGetPublic() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/events') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getPublic(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getRepository method - * - * @return void - */ - public function testGetRepository() - { - $path = '/repos/' . $this->owner . '/' . $this->repo . '/events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepository($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getIssue method - * - * @return void - */ - public function testGetIssue() - { - $path = '/repos/' . $this->owner . '/' . $this->repo . '/issues/events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getIssue($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getNetwork method - * - * @return void - */ - public function testGetNetwork() - { - $path = '/networks/' . $this->owner . '/' . $this->repo . '/events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getNetwork($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getOrg method - * - * @return void - */ - public function testGetOrg() - { - $path = '/orgs/' . $this->owner . '/events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getOrg($this->owner), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUser method - * - * @return void - */ - public function testGetUser() - { - $path = '/users/' . $this->owner . '/received_events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getUser($this->owner), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUserPublic method - * - * @return void - */ - public function testGetUserPublic() - { - $path = '/users/' . $this->owner . '/received_events/public'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getUserPublic($this->owner), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getByUser method - * - * @return void - */ - public function testGetByUser() - { - $path = '/users/' . $this->owner . '/events'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getByUser($this->owner), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getByUserPublic method - * - * @return void - */ - public function testGetByUserPublic() - { - $path = '/users/' . $this->owner . '/events/public'; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getByUserPublic($this->owner), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUserOrg method - * - * @return void - */ - public function testGetUserOrg() - { - $path = '/users/' . $this->owner . '/events/orgs/' . $this->repo; - - $this->client->expects($this->once()) - ->method('get') - ->with($path) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getUserOrg($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Events Object under test. + * @since 1.0 + */ + protected $object; + + /** + * @var string + * @since 1.0 + */ + protected $owner = 'joomla'; + + /** + * @var string + * @since 1.0 + */ + protected $repo = 'joomla-framework'; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Events($this->options, $this->client); + } + + /** + * Tests the getPublic method + * + * @return void + */ + public function testGetPublic() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/events') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getPublic(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getRepository method + * + * @return void + */ + public function testGetRepository() + { + $path = '/repos/' . $this->owner . '/' . $this->repo . '/events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepository($this->owner, $this->repo), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getIssue method + * + * @return void + */ + public function testGetIssue() + { + $path = '/repos/' . $this->owner . '/' . $this->repo . '/issues/events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getIssue($this->owner, $this->repo), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getNetwork method + * + * @return void + */ + public function testGetNetwork() + { + $path = '/networks/' . $this->owner . '/' . $this->repo . '/events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getNetwork($this->owner, $this->repo), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getOrg method + * + * @return void + */ + public function testGetOrg() + { + $path = '/orgs/' . $this->owner . '/events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getOrg($this->owner), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUser method + * + * @return void + */ + public function testGetUser() + { + $path = '/users/' . $this->owner . '/received_events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getUser($this->owner), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUserPublic method + * + * @return void + */ + public function testGetUserPublic() + { + $path = '/users/' . $this->owner . '/received_events/public'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getUserPublic($this->owner), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getByUser method + * + * @return void + */ + public function testGetByUser() + { + $path = '/users/' . $this->owner . '/events'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getByUser($this->owner), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getByUserPublic method + * + * @return void + */ + public function testGetByUserPublic() + { + $path = '/users/' . $this->owner . '/events/public'; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getByUserPublic($this->owner), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUserOrg method + * + * @return void + */ + public function testGetUserOrg() + { + $path = '/users/' . $this->owner . '/events/orgs/' . $this->repo; + + $this->client->expects($this->once()) + ->method('get') + ->with($path) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getUserOrg($this->owner, $this->repo), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Activity/FeedsTest.php b/Tests/Package/Activity/FeedsTest.php index bb8c8d2e..2c02611e 100644 --- a/Tests/Package/Activity/FeedsTest.php +++ b/Tests/Package/Activity/FeedsTest.php @@ -16,42 +16,42 @@ */ class FeedsTest extends GitHubTestCase { - /** - * @var Feeds Object under test. - * @since 1.4.0 - */ - protected $object; + /** + * @var Feeds Object under test. + * @since 1.4.0 + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.4.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.4.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Feeds($this->options, $this->client); - } + $this->object = new Feeds($this->options, $this->client); + } - /** - * Tests the getFeeds method - * - * @return void - */ - public function testGetFeeds() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/feeds') - ->will($this->returnValue($this->response)); + /** + * Tests the getFeeds method + * + * @return void + */ + public function testGetFeeds() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/feeds') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getFeeds(), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->getFeeds(), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Activity/NotificationsTest.php b/Tests/Package/Activity/NotificationsTest.php index ade094b7..6cbaf0c2 100644 --- a/Tests/Package/Activity/NotificationsTest.php +++ b/Tests/Package/Activity/NotificationsTest.php @@ -18,278 +18,278 @@ */ class NotificationsTest extends GitHubTestCase { - /** - * @var Notifications Object under test. - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Notifications($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/notifications?all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(true, true, new \DateTime('2005-8-17', new \DateTimeZone('UTC')), new \DateTime('2005-8-17', new \DateTimeZone('UTC'))), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::getListRepository() - * - * @return void - */ - public function testGetListRepository() - { - $args = 'all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/notifications?' . $args, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListRepository( - '{owner}', - '{repo}', - true, - true, - new \DateTime('2005-8-17', new \DateTimeZone('UTC')), - new \DateTime('2005-8-17', new \DateTimeZone('UTC')) - ), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::markRead() - * - * @return void - */ - public function testMarkRead() - { - $this->response->code = 205; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('put') - ->with('/notifications', '{"unread":true,"read":true}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->markRead(), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::markRead() - * - * @return void - */ - public function testMarkReadLastRead() - { - $this->response->code = 205; - $this->response->body = ''; - - $date = new \DateTime('1966-09-14', new \DateTimeZone('UTC')); - $data = '{"unread":true,"read":true,"last_read_at":"1966-09-14T00:00:00+00:00"}'; - - $this->client->expects($this->once()) - ->method('put') - ->with('/notifications', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->markRead(true, true, $date), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::markReadRepository() - * - * @return void - */ - public function testMarkReadRepository() - { - $this->response->code = 205; - $this->response->body = ''; - - $data = '{"unread":true,"read":true}'; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/notifications', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->markReadRepository('joomla', 'joomla-platform', true, true), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::markReadRepository() - * - * @return void - */ - public function testMarkReadRepositoryLastRead() - { - $this->response->code = 205; - $this->response->body = ''; - - $date = new \DateTime('1966-09-14', new \DateTimeZone('UTC')); - $data = '{"unread":true,"read":true,"last_read_at":"1966-09-14T00:00:00+00:00"}'; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/notifications', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->markReadRepository('joomla', 'joomla-platform', true, true, $date), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::viewThread() - * - * @return void - */ - public function testViewThread() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/notifications/threads/1', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->viewThread(1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::markReadThread() - * - * @return void - */ - public function testMarkReadThread() - { - $this->response->code = 205; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/notifications/threads/1', '{"unread":true,"read":true}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->markReadThread(1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::getThreadSubscription() - * - * @return void - */ - public function testGetThreadSubscription() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/notifications/threads/1/subscription', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getThreadSubscription(1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::setThreadSubscription() - * - * @return void - */ - public function testSetThreadSubscription() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/notifications/threads/1/subscription', '{"subscribed":true,"ignored":false}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->setThreadSubscription(1, true, false), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Notifications::deleteThreadSubscription() - * - * @return void - */ - public function testDeleteThreadSubscription() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/notifications/threads/1/subscription', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->deleteThreadSubscription(1), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Notifications Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Notifications($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/notifications?all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(true, true, new \DateTime('2005-8-17', new \DateTimeZone('UTC')), new \DateTime('2005-8-17', new \DateTimeZone('UTC'))), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::getListRepository() + * + * @return void + */ + public function testGetListRepository() + { + $args = 'all=1&participating=1&since=2005-08-17T00:00:00+00:00&before=2005-08-17T00:00:00+00:00'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/notifications?' . $args, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListRepository( + '{owner}', + '{repo}', + true, + true, + new \DateTime('2005-8-17', new \DateTimeZone('UTC')), + new \DateTime('2005-8-17', new \DateTimeZone('UTC')) + ), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markRead() + * + * @return void + */ + public function testMarkRead() + { + $this->response->code = 205; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('put') + ->with('/notifications', '{"unread":true,"read":true}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->markRead(), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markRead() + * + * @return void + */ + public function testMarkReadLastRead() + { + $this->response->code = 205; + $this->response->body = ''; + + $date = new \DateTime('1966-09-14', new \DateTimeZone('UTC')); + $data = '{"unread":true,"read":true,"last_read_at":"1966-09-14T00:00:00+00:00"}'; + + $this->client->expects($this->once()) + ->method('put') + ->with('/notifications', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->markRead(true, true, $date), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markReadRepository() + * + * @return void + */ + public function testMarkReadRepository() + { + $this->response->code = 205; + $this->response->body = ''; + + $data = '{"unread":true,"read":true}'; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/notifications', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->markReadRepository('joomla', 'joomla-platform', true, true), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markReadRepository() + * + * @return void + */ + public function testMarkReadRepositoryLastRead() + { + $this->response->code = 205; + $this->response->body = ''; + + $date = new \DateTime('1966-09-14', new \DateTimeZone('UTC')); + $data = '{"unread":true,"read":true,"last_read_at":"1966-09-14T00:00:00+00:00"}'; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/notifications', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->markReadRepository('joomla', 'joomla-platform', true, true, $date), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::viewThread() + * + * @return void + */ + public function testViewThread() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/notifications/threads/1', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->viewThread(1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::markReadThread() + * + * @return void + */ + public function testMarkReadThread() + { + $this->response->code = 205; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/notifications/threads/1', '{"unread":true,"read":true}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->markReadThread(1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::getThreadSubscription() + * + * @return void + */ + public function testGetThreadSubscription() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/notifications/threads/1/subscription', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getThreadSubscription(1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::setThreadSubscription() + * + * @return void + */ + public function testSetThreadSubscription() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/notifications/threads/1/subscription', '{"subscribed":true,"ignored":false}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->setThreadSubscription(1, true, false), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Notifications::deleteThreadSubscription() + * + * @return void + */ + public function testDeleteThreadSubscription() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/notifications/threads/1/subscription', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->deleteThreadSubscription(1), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Activity/StarringTest.php b/Tests/Package/Activity/StarringTest.php index cc8b6dc9..096a4187 100644 --- a/Tests/Package/Activity/StarringTest.php +++ b/Tests/Package/Activity/StarringTest.php @@ -18,232 +18,232 @@ */ class StarringTest extends GitHubTestCase { - /** - * @var Starring Object under test. - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Starring($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/stargazers', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() - * - * @return void - */ - public function testGetRepositories() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/starred?sort=created&direction=desc', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositories(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() - * - * @return void - */ - public function testGetRepositoriesWithName() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/{user}/starred?sort=created&direction=desc', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositories('{user}'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() - * - * Invalid sort option - * - * @return void - */ - public function testGetRepositoriesInvalidSort() - { - $this->expectException(\InvalidArgumentException::class); - - $this->object->getRepositories('', 'invalid'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() - * - * Invalid direction option - * - * @return void - */ - public function testGetRepositoriesInvalidDirection() - { - $this->expectException(\InvalidArgumentException::class); - - $this->object->getRepositories('', 'created', 'invalid'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::check() - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - $this->response->body = true; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/starred/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::check() - * - * @return void - */ - public function testCheckFalse() - { - $this->response->code = 404; - $this->response->body = false; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/starred/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::check() - * - * @return void - */ - public function testCheckUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - $this->response->body = false; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/starred/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::star() - * - * @return void - */ - public function testStar() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/user/starred/joomla/joomla-platform', '', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->star('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity\Starring::unstar() - * - * @return void - */ - public function testUnstar() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/user/starred/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->unstar('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Starring Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Starring($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/stargazers', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * @return void + */ + public function testGetRepositories() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/starred?sort=created&direction=desc', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositories(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * @return void + */ + public function testGetRepositoriesWithName() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/{user}/starred?sort=created&direction=desc', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositories('{user}'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * Invalid sort option + * + * @return void + */ + public function testGetRepositoriesInvalidSort() + { + $this->expectException(\InvalidArgumentException::class); + + $this->object->getRepositories('', 'invalid'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::getRepositories() + * + * Invalid direction option + * + * @return void + */ + public function testGetRepositoriesInvalidDirection() + { + $this->expectException(\InvalidArgumentException::class); + + $this->object->getRepositories('', 'created', 'invalid'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::check() + * + * @return void + */ + public function testCheck() + { + $this->response->code = 204; + $this->response->body = true; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/starred/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::check() + * + * @return void + */ + public function testCheckFalse() + { + $this->response->code = 404; + $this->response->body = false; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/starred/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::check() + * + * @return void + */ + public function testCheckUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + $this->response->body = false; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/starred/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::star() + * + * @return void + */ + public function testStar() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/user/starred/joomla/joomla-platform', '', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->star('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity\Starring::unstar() + * + * @return void + */ + public function testUnstar() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/user/starred/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->unstar('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Activity/WatchingTest.php b/Tests/Package/Activity/WatchingTest.php index fca3fdef..9c0055f6 100644 --- a/Tests/Package/Activity/WatchingTest.php +++ b/Tests/Package/Activity/WatchingTest.php @@ -16,239 +16,239 @@ */ class WatchingTest extends GitHubTestCase { - /** - * @var Watching Object under test. - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Watching($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/subscribers', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getRepositories method - * - * @return void - */ - public function testGetRepositories() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositories(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getRepositoriesUser method - * - * @return void - */ - public function testGetRepositoriesUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/subscriptions', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositories('joomla'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getSubscription method - * - * @return void - */ - public function testGetSubscription() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/subscription', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getSubscription('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the setSubscription method - * - * @return void - */ - public function testSetSubscription() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/subscription', '{"subscribed":true,"ignored":false}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->setSubscription('joomla', 'joomla-platform', true, false), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the deleteSubscription method - * - * @return void - */ - public function testDeleteSubscription() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/subscription', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->deleteSubscription('joomla', 'joomla-platform'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the check method - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(true) - ); - } - - /** - * Tests the checkFalse method - * - * @return void - */ - public function testCheckFalse() - { - $this->response->code = 404; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'joomla-platform'), - $this->equalTo(false) - ); - } - - /** - * Tests the checkUnexpected method - * - * @return void - */ - public function testCheckUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/subscriptions/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->object->check('joomla', 'joomla-platform'); - } - - /** - * Tests the watch method - * - * @return void - */ - public function testWatch() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('put') - ->with('/user/subscriptions/joomla/joomla-platform', '', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->watch('joomla', 'joomla-platform'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the unwatch method - * - * @return void - */ - public function testUnwatch() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/user/subscriptions/joomla/joomla-platform', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->unwatch('joomla', 'joomla-platform'), - $this->equalTo($this->response->body) - ); - } + /** + * @var Watching Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Watching($this->options, $this->client); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/subscribers', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getRepositories method + * + * @return void + */ + public function testGetRepositories() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/subscriptions', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositories(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getRepositoriesUser method + * + * @return void + */ + public function testGetRepositoriesUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/subscriptions', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositories('joomla'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getSubscription method + * + * @return void + */ + public function testGetSubscription() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/subscription', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getSubscription('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the setSubscription method + * + * @return void + */ + public function testSetSubscription() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/subscription', '{"subscribed":true,"ignored":false}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->setSubscription('joomla', 'joomla-platform', true, false), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the deleteSubscription method + * + * @return void + */ + public function testDeleteSubscription() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/subscription', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->deleteSubscription('joomla', 'joomla-platform'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the check method + * + * @return void + */ + public function testCheck() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/subscriptions/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'joomla-platform'), + $this->equalTo(true) + ); + } + + /** + * Tests the checkFalse method + * + * @return void + */ + public function testCheckFalse() + { + $this->response->code = 404; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/subscriptions/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'joomla-platform'), + $this->equalTo(false) + ); + } + + /** + * Tests the checkUnexpected method + * + * @return void + */ + public function testCheckUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/subscriptions/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->object->check('joomla', 'joomla-platform'); + } + + /** + * Tests the watch method + * + * @return void + */ + public function testWatch() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('put') + ->with('/user/subscriptions/joomla/joomla-platform', '', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->watch('joomla', 'joomla-platform'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the unwatch method + * + * @return void + */ + public function testUnwatch() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/user/subscriptions/joomla/joomla-platform', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->unwatch('joomla', 'joomla-platform'), + $this->equalTo($this->response->body) + ); + } } diff --git a/Tests/Package/ActivityTest.php b/Tests/Package/ActivityTest.php index da2d6a54..04a65d6c 100644 --- a/Tests/Package/ActivityTest.php +++ b/Tests/Package/ActivityTest.php @@ -18,38 +18,38 @@ */ class ActivityTest extends GitHubTestCase { - /** - * @var Activity - */ - protected $object; + /** + * @var Activity + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Activity($this->options, $this->client); - } + $this->object = new Activity($this->options, $this->client); + } - /** - * Test method. - * - * @covers \Joomla\Github\Package\Activity::__construct() - * - * @return void - * - * @since 1.0 - */ - public function testConstruct() - { - // Dummy to make PHPUnit "happy" - self::assertEquals(true, true); - } + /** + * Test method. + * + * @covers \Joomla\Github\Package\Activity::__construct() + * + * @return void + * + * @since 1.0 + */ + public function testConstruct() + { + // Dummy to make PHPUnit "happy" + self::assertEquals(true, true); + } } diff --git a/Tests/Package/AuthorizationsTest.php b/Tests/Package/AuthorizationsTest.php index 5314e433..58adb78e 100644 --- a/Tests/Package/AuthorizationsTest.php +++ b/Tests/Package/AuthorizationsTest.php @@ -16,712 +16,700 @@ */ class AuthorizationsTest extends GitHubTestCase { - /** - * @var Authorization - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @return void - * - * @since 1.0 - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Authorization($this->options, $this->client); - } - - /** - * Tests the createAuthorisation method - * - * @return void - * - * @since 1.0 - */ - public function testCreate() - { - $this->response->code = 201; - - $authorisation = '{' - . '"scopes":["public_repo"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/authorizations', $authorisation) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create(array('public_repo'), 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the createAuthorisation method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testCreateFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $authorisation = '{' - . '"scopes":["public_repo"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/authorizations', $authorisation) - ->will($this->returnValue($this->response)); - - try - { - $this->object->create(array('public_repo'), 'My test app', 'http://www.joomla.org'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the delete method - * - * @return void - * - * @since 1.0 - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the delete method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testDeleteFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/42') - ->will($this->returnValue($this->response)); - - try - { - $this->object->delete(42); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the deleteGrant method - * - * @return void - * - * @since 1.0 - */ - public function testDeleteGrant() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->deleteGrant(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the deleteGrant method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testDeleteGrantFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); - - try - { - $this->object->deleteGrant(42); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the editAuthorisation method - Add scopes - * - * @return void - * - * @since 1.0 - */ - public function testEditAddScopes() - { - $authorisation = '{' - . '"add_scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit(42, array(), array('public_repo', 'gist'), array(), 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editAuthorisation method - Remove scopes - * - * @return void - * - * @since 1.0 - */ - public function testEditRemoveScopes() - { - $authorisation = '{' - . '"remove_scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit(42, array(), array(), array('public_repo', 'gist'), 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editAuthorisation method - Scopes param - * - * @return void - * - * @since 1.0 - */ - public function testEditScopes() - { - $authorisation = '{' - . '"scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit(42, array('public_repo', 'gist'), array(), array(), 'My test app', 'http://www.joomla.org'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editAuthorisation method - simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testEditFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $authorisation = '{' - . '"add_scopes":["public_repo","gist"],' - . '"note":"My test app",' - . '"note_url":"http:\/\/www.joomla.org"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/authorizations/42', $authorisation) - ->will($this->returnValue($this->response)); - - try - { - $this->object->edit(42, array(), array('public_repo', 'gist'), array(), 'My test app', 'http://www.joomla.org'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the editAuthorisation method - too many scope params - * - * @return void - * - * @since 1.0 - */ - public function testEditTooManyScopes() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit(42, array(), array('public_repo', 'gist'), array('public_repo', 'gist'), 'My test app', 'http://www.joomla.org'); - } - - /** - * Tests the get method - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/42') - ->will($this->returnValue($this->response)); - - $this->object->get(42); - } - - /** - * Tests the getGrant method - * - * @return void - * - * @since 1.0 - */ - public function testGetGrant() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getGrant(42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getGrant method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetGrantFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants/42') - ->will($this->returnValue($this->response)); - - $this->object->getGrant(42); - } - - /** - * Tests the getList method - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations') - ->will($this->returnValue($this->response)); - - $this->object->getList(); - } - - /** - * Tests the getListGrants method - * - * @return void - * - * @since 1.0 - */ - public function testGetListGrants() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListGrants(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getListGrants method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetListGrantsFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/authorizations/grants') - ->will($this->returnValue($this->response)); - - $this->object->getListGrants(); - } - - /** - * Tests the getRateLimit method - * - * @return void - * - * @since 1.0 - */ - public function testGetRateLimit() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/rate_limit') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRateLimit(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getRateLimit method for an unlimited user. - * - * @return void - * - * @since 1.0 - */ - public function testGetRateLimitUnlimited() - { - $this->response->code = 404; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('get') - ->with('/rate_limit') - ->will($this->returnValue($this->response)); - - $this->assertFalse($this->object->getRateLimit()->limit, 'The limit should be false for unlimited'); - } - - /** - * Tests the getRateLimit method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetRateLimitFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/rate_limit') - ->will($this->returnValue($this->response)); - - $this->object->getRateLimit(); - } - - /** - * Tests the getAuthorizationLink method - * - * @return void - */ - public function testGetAuthorizationLink() - { - $this->response->code = 200; - $this->response->body = 'https://github.com/login/oauth/authorize?client_id=12345' - . '&redirect_uri=aaa&scope=bbb&state=ccc'; - - $this->assertThat( - $this->object->getAuthorizationLink('12345', 'aaa', 'bbb', 'ccc'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the requestToken method - * - * @return void - */ - public function testRequestToken() - { - $this->response->code = 200; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('post') - ->with('https://github.com/login/oauth/access_token') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the requestTokenJson method - * - * @return void - */ - public function testRequestTokenJson() - { - $this->response->code = 200; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('post') - ->with('https://github.com/login/oauth/access_token') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'json'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the requestTokenXml method - * - * @return void - */ - public function testRequestTokenXml() - { - $this->response->code = 200; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('post') - ->with('https://github.com/login/oauth/access_token') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'xml'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the requestTokenInvalidFormat method - * - * @return void - */ - public function testRequestTokenInvalidFormat() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 200; - $this->response->body = ''; - - $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'invalid'); - } - - /** - * Tests the revokeGrantForApplication method - * - * @return void - * - * @since 1.0 - */ - public function testRevokeGrantForApplication() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/applications/42/grants/1a2b3c') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->revokeGrantForApplication(42, '1a2b3c'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the revokeGrantForApplication method - failure - * - * @return void - * - * @since 1.0 - */ - public function testRevokeGrantForApplicationFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/applications/42/grants/1a2b3c') - ->will($this->returnValue($this->response)); - - $this->object->revokeGrantForApplication(42, '1a2b3c'); - } + /** + * @var Authorization + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Authorization($this->options, $this->client); + } + + /** + * Tests the createAuthorisation method + * + * @return void + * + * @since 1.0 + */ + public function testCreate() + { + $this->response->code = 201; + + $authorisation = '{' + . '"scopes":["public_repo"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/authorizations', $authorisation) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create(['public_repo'], 'My test app', 'http://www.joomla.org'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the createAuthorisation method - simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testCreateFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $authorisation = '{' + . '"scopes":["public_repo"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/authorizations', $authorisation) + ->will($this->returnValue($this->response)); + + try { + $this->object->create(['public_repo'], 'My test app', 'http://www.joomla.org'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the delete method + * + * @return void + * + * @since 1.0 + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/authorizations/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete(42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the delete method - simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testDeleteFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/authorizations/42') + ->will($this->returnValue($this->response)); + + try { + $this->object->delete(42); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the deleteGrant method + * + * @return void + * + * @since 1.0 + */ + public function testDeleteGrant() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/authorizations/grants/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->deleteGrant(42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the deleteGrant method - simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testDeleteGrantFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/authorizations/grants/42') + ->will($this->returnValue($this->response)); + + try { + $this->object->deleteGrant(42); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the editAuthorisation method - Add scopes + * + * @return void + * + * @since 1.0 + */ + public function testEditAddScopes() + { + $authorisation = '{' + . '"add_scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/authorizations/42', $authorisation) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit(42, [], ['public_repo', 'gist'], [], 'My test app', 'http://www.joomla.org'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the editAuthorisation method - Remove scopes + * + * @return void + * + * @since 1.0 + */ + public function testEditRemoveScopes() + { + $authorisation = '{' + . '"remove_scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/authorizations/42', $authorisation) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit(42, [], [], ['public_repo', 'gist'], 'My test app', 'http://www.joomla.org'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the editAuthorisation method - Scopes param + * + * @return void + * + * @since 1.0 + */ + public function testEditScopes() + { + $authorisation = '{' + . '"scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/authorizations/42', $authorisation) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit(42, ['public_repo', 'gist'], [], [], 'My test app', 'http://www.joomla.org'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the editAuthorisation method - simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testEditFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $authorisation = '{' + . '"add_scopes":["public_repo","gist"],' + . '"note":"My test app",' + . '"note_url":"http:\/\/www.joomla.org"' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/authorizations/42', $authorisation) + ->will($this->returnValue($this->response)); + + try { + $this->object->edit(42, [], ['public_repo', 'gist'], [], 'My test app', 'http://www.joomla.org'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the editAuthorisation method - too many scope params + * + * @return void + * + * @since 1.0 + */ + public function testEditTooManyScopes() + { + $this->expectException(\RuntimeException::class); + + $this->object->edit(42, [], ['public_repo', 'gist'], ['public_repo', 'gist'], 'My test app', 'http://www.joomla.org'); + } + + /** + * Tests the get method + * + * @return void + * + * @since 1.0 + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get(42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/42') + ->will($this->returnValue($this->response)); + + $this->object->get(42); + } + + /** + * Tests the getGrant method + * + * @return void + * + * @since 1.0 + */ + public function testGetGrant() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/grants/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getGrant(42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getGrant method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetGrantFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/grants/42') + ->will($this->returnValue($this->response)); + + $this->object->getGrant(42); + } + + /** + * Tests the getList method + * + * @return void + * + * @since 1.0 + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations') + ->will($this->returnValue($this->response)); + + $this->object->getList(); + } + + /** + * Tests the getListGrants method + * + * @return void + * + * @since 1.0 + */ + public function testGetListGrants() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/grants') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListGrants(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getListGrants method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetListGrantsFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/authorizations/grants') + ->will($this->returnValue($this->response)); + + $this->object->getListGrants(); + } + + /** + * Tests the getRateLimit method + * + * @return void + * + * @since 1.0 + */ + public function testGetRateLimit() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/rate_limit') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRateLimit(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getRateLimit method for an unlimited user. + * + * @return void + * + * @since 1.0 + */ + public function testGetRateLimitUnlimited() + { + $this->response->code = 404; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('get') + ->with('/rate_limit') + ->will($this->returnValue($this->response)); + + $this->assertFalse($this->object->getRateLimit()->limit, 'The limit should be false for unlimited'); + } + + /** + * Tests the getRateLimit method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetRateLimitFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/rate_limit') + ->will($this->returnValue($this->response)); + + $this->object->getRateLimit(); + } + + /** + * Tests the getAuthorizationLink method + * + * @return void + */ + public function testGetAuthorizationLink() + { + $this->response->code = 200; + $this->response->body = 'https://github.com/login/oauth/authorize?client_id=12345' + . '&redirect_uri=aaa&scope=bbb&state=ccc'; + + $this->assertThat( + $this->object->getAuthorizationLink('12345', 'aaa', 'bbb', 'ccc'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the requestToken method + * + * @return void + */ + public function testRequestToken() + { + $this->response->code = 200; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('post') + ->with('https://github.com/login/oauth/access_token') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the requestTokenJson method + * + * @return void + */ + public function testRequestTokenJson() + { + $this->response->code = 200; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('post') + ->with('https://github.com/login/oauth/access_token') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'json'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the requestTokenXml method + * + * @return void + */ + public function testRequestTokenXml() + { + $this->response->code = 200; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('post') + ->with('https://github.com/login/oauth/access_token') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'xml'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the requestTokenInvalidFormat method + * + * @return void + */ + public function testRequestTokenInvalidFormat() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 200; + $this->response->body = ''; + + $this->object->requestToken('12345', 'aaa', 'bbb', 'ccc', 'invalid'); + } + + /** + * Tests the revokeGrantForApplication method + * + * @return void + * + * @since 1.0 + */ + public function testRevokeGrantForApplication() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/applications/42/grants/1a2b3c') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->revokeGrantForApplication(42, '1a2b3c'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the revokeGrantForApplication method - failure + * + * @return void + * + * @since 1.0 + */ + public function testRevokeGrantForApplicationFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/applications/42/grants/1a2b3c') + ->will($this->returnValue($this->response)); + + $this->object->revokeGrantForApplication(42, '1a2b3c'); + } } diff --git a/Tests/Package/Data/BlobsTest.php b/Tests/Package/Data/BlobsTest.php index f84a2330..ec032ee6 100644 --- a/Tests/Package/Data/BlobsTest.php +++ b/Tests/Package/Data/BlobsTest.php @@ -16,62 +16,62 @@ */ class BlobsTest extends GitHubTestCase { - /** - * @var Blobs Object under test. - * @since 1.0 - */ - protected $object; + /** + * @var Blobs Object under test. + * @since 1.0 + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Blobs($this->options, $this->client); - } + $this->object = new Blobs($this->options, $this->client); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/blobs/12345', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/blobs/12345', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/blobs', '{"content":"Hello w\u00f6rld","encoding":"utf-8"}', array(), 0) - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/git/blobs', '{"content":"Hello w\u00f6rld","encoding":"utf-8"}', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'Hello wörld'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'Hello wörld'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Data/CommitsTest.php b/Tests/Package/Data/CommitsTest.php index c9f129e0..fa4d28d0 100644 --- a/Tests/Package/Data/CommitsTest.php +++ b/Tests/Package/Data/CommitsTest.php @@ -16,62 +16,62 @@ */ class CommitsTest extends GitHubTestCase { - /** - * @var Commits Object under test. - * @since 1.0 - */ - protected $object; + /** + * @var Commits Object under test. + * @since 1.0 + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Commits($this->options, $this->client); - } + $this->object = new Commits($this->options, $this->client); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/commits/12345', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/commits/12345', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/commits', '{"message":"My Message","tree":"12345","parents":[]}', array(), 0) - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/git/commits', '{"message":"My Message","tree":"12345","parents":[]}', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'My Message', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'My Message', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Data/RefsTest.php b/Tests/Package/Data/RefsTest.php index ce2ba7e9..04147312 100755 --- a/Tests/Package/Data/RefsTest.php +++ b/Tests/Package/Data/RefsTest.php @@ -16,272 +16,272 @@ */ class RefsTest extends GitHubTestCase { - /** - * @var Refs Object under test. - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Refs($this->options, $this->client); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/refs/heads/master') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 'heads/master'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/refs/heads/master') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 'heads/master'); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - // Build the request data. - $data = json_encode( - array( - 'ref' => '/ref/heads/myhead', - 'sha' => 'This is the sha' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/refs', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '/ref/heads/myhead', 'This is the sha'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method - failure - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array( - 'ref' => '/ref/heads/myhead', - 'sha' => 'This is the sha' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/refs', $data) - ->will($this->returnValue($this->response)); - - $this->object->create('joomla', 'joomla-platform', '/ref/heads/myhead', 'This is the sha'); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - // Build the request data. - $data = json_encode( - array( - 'force' => true, - 'sha' => 'This is the sha' - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/git/refs/heads/master', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 'heads/master', 'This is the sha', true), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - failure - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array( - 'sha' => 'This is the sha' - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/git/refs/heads/master', $data) - ->will($this->returnValue($this->response)); - - $this->object->edit('joomla', 'joomla-platform', 'heads/master', 'This is the sha'); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/refs') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method with a namespace - * - * @return void - */ - public function testGetListWithNamespace() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/refs/tags') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', 'tags'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/refs') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = ''; - - $ref = 'refs/heads/sc/featureA'; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/git/refs/' . $ref) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', $ref), - $this->equalTo('') - ); - } - - /** - * Tests the delete method - failure - * - * @return void - */ - public function testDeleteFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $ref = 'refs/heads/sc/featureA'; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/git/refs/' . $ref) - ->will($this->returnValue($this->response)); - - $this->object->delete('joomla', 'joomla-platform', $ref); - } + /** + * @var Refs Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Refs($this->options, $this->client); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/refs/heads/master') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 'heads/master'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/refs/heads/master') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 'heads/master'); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + // Build the request data. + $data = json_encode( + [ + 'ref' => '/ref/heads/myhead', + 'sha' => 'This is the sha', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/git/refs', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', '/ref/heads/myhead', 'This is the sha'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method - failure + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + [ + 'ref' => '/ref/heads/myhead', + 'sha' => 'This is the sha', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/git/refs', $data) + ->will($this->returnValue($this->response)); + + $this->object->create('joomla', 'joomla-platform', '/ref/heads/myhead', 'This is the sha'); + } + + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + // Build the request data. + $data = json_encode( + [ + 'force' => true, + 'sha' => 'This is the sha', + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/git/refs/heads/master', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 'heads/master', 'This is the sha', true), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the edit method - failure + * + * @return void + */ + public function testEditFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + [ + 'sha' => 'This is the sha', + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/git/refs/heads/master', $data) + ->will($this->returnValue($this->response)); + + $this->object->edit('joomla', 'joomla-platform', 'heads/master', 'This is the sha'); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/refs') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method with a namespace + * + * @return void + */ + public function testGetListWithNamespace() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/refs/tags') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', 'tags'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method - failure + * + * @return void + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/refs') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + $this->response->body = ''; + + $ref = 'refs/heads/sc/featureA'; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/git/refs/' . $ref) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', $ref), + $this->equalTo('') + ); + } + + /** + * Tests the delete method - failure + * + * @return void + */ + public function testDeleteFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $ref = 'refs/heads/sc/featureA'; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/git/refs/' . $ref) + ->will($this->returnValue($this->response)); + + $this->object->delete('joomla', 'joomla-platform', $ref); + } } diff --git a/Tests/Package/Data/TagsTest.php b/Tests/Package/Data/TagsTest.php index 02a4dec4..6a2cc537 100644 --- a/Tests/Package/Data/TagsTest.php +++ b/Tests/Package/Data/TagsTest.php @@ -16,64 +16,64 @@ */ class TagsTest extends GitHubTestCase { - /** - * @var Tags Object under test. - * @since 1.0 - */ - protected $object; + /** + * @var Tags Object under test. + * @since 1.0 + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Tags($this->options, $this->client); - } + $this->object = new Tags($this->options, $this->client); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/tags/12345', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/tags/12345', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; - $data = '{"tag":"0.1","message":"Message","object":"12345","type":"commit","tagger":' - . '{"name":"elkuku","email":"email@example.com","date":"123456789"}}'; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/tags', $data, array(), 0) - ->will($this->returnValue($this->response)); + $data = '{"tag":"0.1","message":"Message","object":"12345","type":"commit","tagger":' + . '{"name":"elkuku","email":"email@example.com","date":"123456789"}}'; + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/git/tags', $data, [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '0.1', 'Message', '12345', 'commit', 'elkuku', 'email@example.com', '123456789'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', '0.1', 'Message', '12345', 'commit', 'elkuku', 'email@example.com', '123456789'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Data/TreesTest.php b/Tests/Package/Data/TreesTest.php index 5f66eac5..b7760144 100644 --- a/Tests/Package/Data/TreesTest.php +++ b/Tests/Package/Data/TreesTest.php @@ -16,80 +16,80 @@ */ class TreesTest extends GitHubTestCase { - /** - * @var Trees Object under test. - * @since 1.0 - */ - protected $object; + /** + * @var Trees Object under test. + * @since 1.0 + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Trees($this->options, $this->client); - } + $this->object = new Trees($this->options, $this->client); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/trees/12345', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/trees/12345', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the getRecursively method - * - * @return void - */ - public function testGetRecursively() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/git/trees/12345?recursive=1', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the getRecursively method + * + * @return void + */ + public function testGetRecursively() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/git/trees/12345?recursive=1', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getRecursively('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->getRecursively('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/git/trees', '{"tree":"12345","base_tree":"678"}', array(), 0) - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/git/trees', '{"tree":"12345","base_tree":"678"}', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '12345', '678'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', '12345', '678'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/DataTest.php b/Tests/Package/DataTest.php index 5594c18a..8f22c364 100644 --- a/Tests/Package/DataTest.php +++ b/Tests/Package/DataTest.php @@ -18,38 +18,38 @@ */ class DataTest extends GitHubTestCase { - /** - * @var Data - */ - protected $object; + /** + * @var Data + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Data($this->options, $this->client); - } + $this->object = new Data($this->options, $this->client); + } - /** - * Test method. - * - * @covers \Joomla\Github\Package\Data::__construct() - * - * @return void - * - * @since 1.0 - */ - public function testConstruct() - { - // Dummy to make PHPUnit "happy" - self::assertEquals(true, true); - } + /** + * Test method. + * + * @covers \Joomla\Github\Package\Data::__construct() + * + * @return void + * + * @since 1.0 + */ + public function testConstruct() + { + // Dummy to make PHPUnit "happy" + self::assertEquals(true, true); + } } diff --git a/Tests/Package/EmojisTest.php b/Tests/Package/EmojisTest.php index 59685a55..aa446808 100755 --- a/Tests/Package/EmojisTest.php +++ b/Tests/Package/EmojisTest.php @@ -16,75 +16,72 @@ */ class EmojisTest extends GitHubTestCase { - /** - * @var Emojis - */ - protected $object; + /** + * @var Emojis + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Emojis($this->options, $this->client); - } + $this->object = new Emojis($this->options, $this->client); + } - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/emojis') - ->will($this->returnValue($this->response)); + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/emojis') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the getList method - simulated failure - * - * @return void - */ - public function testGetListFailure() - { - $exception = false; + /** + * Tests the getList method - simulated failure + * + * @return void + */ + public function testGetListFailure() + { + $exception = false; - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response->code = 500; + $this->response->body = $this->errorString; - $this->client->expects($this->once()) - ->method('get') - ->with('/emojis') - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('get') + ->with('/emojis') + ->will($this->returnValue($this->response)); - try - { - $this->object->getList(); - } - catch (\DomainException $e) - { - $exception = true; + try { + $this->object->getList(); + } catch (\DomainException $e) { + $exception = true; - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } - $this->assertTrue($exception); - } + $this->assertTrue($exception); + } } diff --git a/Tests/Package/GistsTest.php b/Tests/Package/GistsTest.php index dde9503f..33d063eb 100755 --- a/Tests/Package/GistsTest.php +++ b/Tests/Package/GistsTest.php @@ -16,1218 +16,1158 @@ */ class GistsTest extends GitHubTestCase { - /** - * @var Gists - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Gists($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - // Build the request data. - $data = json_encode( - array( - 'files' => array( - 'file2.txt' => array('content' => 'This is the second file') - ), - 'public' => true, - 'description' => 'This is a gist' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create( - array( - 'file2.txt' => 'This is the second file' - ), - true, - 'This is a gist' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method loading file content from a file - * - * @return void - */ - public function testCreateGistFromFile() - { - $this->response->code = 201; - - // Build the request data. - $data = json_encode( - array( - 'files' => array( - 'gittest' => array('content' => 'GistContent' . PHP_EOL) - ), - 'public' => true, - 'description' => 'This is a gist' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create( - array( - __DIR__ . '/../data/gittest' - ), - true, - 'This is a gist' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method loading file content from a file - file does not exist - * - * @return void - */ - public function testCreateGistFromFileNotFound() - { - $this->expectException(\InvalidArgumentException::class); - - $this->response->code = 501; - - $this->object->create( - array( - '/file/not/found' - ), - true, - 'This is a gist' - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreateFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array('files' => array(), 'public' => true, 'description' => 'This is a gist') - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists', $data) - ->will($this->returnValue($this->response)); - - try - { - $this->object->create(array(), true, 'This is a gist'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the createComment method - simulated failure - * - * @return void - */ - public function testCreateComment() - { - $this->response->code = 201; - - $gist = new \stdClass; - $gist->body = 'My Insightful Comment'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists/523/comments', json_encode($gist)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->comments->create(523, 'My Insightful Comment'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the createComment method - simulated failure - * - * @return void - */ - public function testCreateCommentFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $gist = new \stdClass; - $gist->body = 'My Insightful Comment'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists/523/comments', json_encode($gist)) - ->will($this->returnValue($this->response)); - - try - { - $this->object->comments->create(523, 'My Insightful Comment'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/254') - ->will($this->returnValue($this->response)); - - $this->object->delete(254); - } - - /** - * Tests the delete method - simulated failure - * - * @return void - */ - public function testDeleteFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/254') - ->will($this->returnValue($this->response)); - - try - { - $this->object->delete(254); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the deleteComment method - * - * @return void - */ - public function testDeleteComment() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/comments/254') - ->will($this->returnValue($this->response)); - - $this->object->comments->delete(254); - } - - /** - * Tests the deleteComment method - simulated failure - * - * @return void - */ - public function testDeleteCommentFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/comments/254') - ->will($this->returnValue($this->response)); - - try - { - $this->object->comments->delete(254); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - // Build the request data. - $data = json_encode( - array( - 'description' => 'This is a gist', - 'public' => true, - 'files' => array( - 'file1.txt' => array('content' => 'This is the first file'), - 'file2.txt' => array('content' => 'This is the second file') - ) - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/gists/512', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit( - 512, - array( - 'file1.txt' => 'This is the first file', - 'file2.txt' => 'This is the second file' - ), - true, - 'This is a gist' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - simulated failure - * - * @return void - */ - public function testEditFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array( - 'description' => 'This is a gist', - 'public' => true, - 'files' => array( - 'file1.txt' => array('content' => 'This is the first file'), - 'file2.txt' => array('content' => 'This is the second file') - ) - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/gists/512', $data) - ->will($this->returnValue($this->response)); - - try - { - $this->object->edit( - 512, - array( - 'file1.txt' => 'This is the first file', - 'file2.txt' => 'This is the second file' - ), - true, - 'This is a gist' - ); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the editComment method - * - * @return void - */ - public function testEditComment() - { - $gist = new \stdClass; - $gist->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/gists/comments/523', json_encode($gist)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->comments->edit(523, 'This comment is now even more insightful'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the editComment method - simulated failure - * - * @return void - */ - public function testEditCommentFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $gist = new \stdClass; - $gist->body = 'This comment is now even more insightful'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/gists/comments/523', json_encode($gist)) - ->will($this->returnValue($this->response)); - - try - { - $this->object->comments->edit(523, 'This comment is now even more insightful'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the fork method - * - * @return void - */ - public function testFork() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->fork(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the fork method - simulated failure - * - * @return void - */ - public function testForkFailure() - { - $exception = false; - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('post') - ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); - - try - { - $this->object->fork(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - simulated failure - * - * @return void - */ - public function testGetFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523') - ->will($this->returnValue($this->response)); - - try - { - $this->object->get(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getComment method - * - * @return void - */ - public function testGetComment() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/comments/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->comments->get(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getComment method - simulated failure - * - * @return void - */ - public function testGetCommentFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/comments/523') - ->will($this->returnValue($this->response)); - - try - { - $this->object->comments->get(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getComments method - * - * @return void - */ - public function testGetComments() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->comments->getList(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getComments method - simulated failure - * - * @return void - */ - public function testGetCommentsFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/comments') - ->will($this->returnValue($this->response)); - - try - { - $this->object->comments->getList(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getCommitList method - * - * @return void - */ - public function testGetCommitList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/commits') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getCommitList(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getCommitList method - simulated failure - * - * @return void - */ - public function testGetCommitListFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/commits') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getCommitList(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getForkList method - * - * @return void - */ - public function testGetForkList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getForkList(523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getForkList method - simulated failure - * - * @return void - */ - public function testGetForkListFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/forks') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getForkList(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - simulated failure - * - * @return void - */ - public function testGetListFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getList(); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getListByUser method - * - * @return void - */ - public function testGetListByUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/gists') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListByUser('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getListByUser method - simulated failure - * - * @return void - */ - public function testGetListByUserFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/gists') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getListByUser('joomla'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getListPublic method - * - * @return void - */ - public function testGetListPublic() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/public') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListPublic(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getListPublic method - simulated failure - * - * @return void - */ - public function testGetListPublicFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/public') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getListPublic(); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getListStarred method - * - * @return void - */ - public function testGetListStarred() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/starred') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListStarred(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getListStarred method - simulated failure - * - * @return void - */ - public function testGetListStarredFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/starred') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getListStarred(); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the getRevision method - * - * @return void - */ - public function testGetRevision() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/a1b2c3') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRevision(523, 'a1b2c3'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getRevision method - simulated failure - * - * @return void - */ - public function testGetRevisionFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/a1b2c3') - ->will($this->returnValue($this->response)); - - try - { - $this->object->getRevision(523, 'a1b2c3'); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the isStarred method when the gist has been starred - * - * @return void - */ - public function testIsStarredTrue() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/star') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isStarred(523), - $this->equalTo(true) - ); - } - - /** - * Tests the isStarred method when the gist has not been starred - * - * @return void - */ - public function testIsStarredFalse() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/star') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isStarred(523), - $this->equalTo(false) - ); - } - - /** - * Tests the isStarred method expecting a failure response - * - * @return void - */ - public function testIsStarredFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gists/523/star') - ->will($this->returnValue($this->response)); - - try - { - $this->object->isStarred(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the star method - * - * @return void - */ - public function testStar() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/gists/523/star', '') - ->will($this->returnValue($this->response)); - - $this->object->star(523); - } - - /** - * Tests the star method - simulated failure - * - * @return void - */ - public function testStarFailure() - { - $exception = false; - - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('put') - ->with('/gists/523/star', '') - ->will($this->returnValue($this->response)); - - try - { - $this->object->star(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Tests the unstar method - * - * @return void - */ - public function testUnstar() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/523/star') - ->will($this->returnValue($this->response)); - - $this->object->unstar(523); - } - - /** - * Tests the unstar method - simulated failure - * - * @return void - */ - public function testUnstarFailure() - { - $exception = false; - - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/gists/523/star') - ->will($this->returnValue($this->response)); - - try - { - $this->object->unstar(523); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } + /** + * @var Gists + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Gists($this->options, $this->client); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + // Build the request data. + $data = json_encode( + [ + 'files' => [ + 'file2.txt' => ['content' => 'This is the second file'], + ], + 'public' => true, + 'description' => 'This is a gist', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + [ + 'file2.txt' => 'This is the second file', + ], + true, + 'This is a gist' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method loading file content from a file + * + * @return void + */ + public function testCreateGistFromFile() + { + $this->response->code = 201; + + // Build the request data. + $data = json_encode( + [ + 'files' => [ + 'gittest' => ['content' => 'GistContent' . PHP_EOL], + ], + 'public' => true, + 'description' => 'This is a gist', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + [ + __DIR__ . '/../data/gittest', + ], + true, + 'This is a gist' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method loading file content from a file - file does not exist + * + * @return void + */ + public function testCreateGistFromFileNotFound() + { + $this->expectException(\InvalidArgumentException::class); + + $this->response->code = 501; + + $this->object->create( + [ + '/file/not/found', + ], + true, + 'This is a gist' + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreateFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + ['files' => [], 'public' => true, 'description' => 'This is a gist'] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists', $data) + ->will($this->returnValue($this->response)); + + try { + $this->object->create([], true, 'This is a gist'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the createComment method - simulated failure + * + * @return void + */ + public function testCreateComment() + { + $this->response->code = 201; + + $gist = new \stdClass(); + $gist->body = 'My Insightful Comment'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists/523/comments', json_encode($gist)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->comments->create(523, 'My Insightful Comment'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the createComment method - simulated failure + * + * @return void + */ + public function testCreateCommentFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $gist = new \stdClass(); + $gist->body = 'My Insightful Comment'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists/523/comments', json_encode($gist)) + ->will($this->returnValue($this->response)); + + try { + $this->object->comments->create(523, 'My Insightful Comment'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/254') + ->will($this->returnValue($this->response)); + + $this->object->delete(254); + } + + /** + * Tests the delete method - simulated failure + * + * @return void + */ + public function testDeleteFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/254') + ->will($this->returnValue($this->response)); + + try { + $this->object->delete(254); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the deleteComment method + * + * @return void + */ + public function testDeleteComment() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/comments/254') + ->will($this->returnValue($this->response)); + + $this->object->comments->delete(254); + } + + /** + * Tests the deleteComment method - simulated failure + * + * @return void + */ + public function testDeleteCommentFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/comments/254') + ->will($this->returnValue($this->response)); + + try { + $this->object->comments->delete(254); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + // Build the request data. + $data = json_encode( + [ + 'description' => 'This is a gist', + 'public' => true, + 'files' => [ + 'file1.txt' => ['content' => 'This is the first file'], + 'file2.txt' => ['content' => 'This is the second file'], + ], + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/gists/512', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit( + 512, + [ + 'file1.txt' => 'This is the first file', + 'file2.txt' => 'This is the second file', + ], + true, + 'This is a gist' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the edit method - simulated failure + * + * @return void + */ + public function testEditFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + [ + 'description' => 'This is a gist', + 'public' => true, + 'files' => [ + 'file1.txt' => ['content' => 'This is the first file'], + 'file2.txt' => ['content' => 'This is the second file'], + ], + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/gists/512', $data) + ->will($this->returnValue($this->response)); + + try { + $this->object->edit( + 512, + [ + 'file1.txt' => 'This is the first file', + 'file2.txt' => 'This is the second file', + ], + true, + 'This is a gist' + ); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the editComment method + * + * @return void + */ + public function testEditComment() + { + $gist = new \stdClass(); + $gist->body = 'This comment is now even more insightful'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/gists/comments/523', json_encode($gist)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->comments->edit(523, 'This comment is now even more insightful'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the editComment method - simulated failure + * + * @return void + */ + public function testEditCommentFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $gist = new \stdClass(); + $gist->body = 'This comment is now even more insightful'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/gists/comments/523', json_encode($gist)) + ->will($this->returnValue($this->response)); + + try { + $this->object->comments->edit(523, 'This comment is now even more insightful'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the fork method + * + * @return void + */ + public function testFork() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists/523/forks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->fork(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the fork method - simulated failure + * + * @return void + */ + public function testForkFailure() + { + $exception = false; + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('post') + ->with('/gists/523/forks') + ->will($this->returnValue($this->response)); + + try { + $this->object->fork(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method - simulated failure + * + * @return void + */ + public function testGetFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523') + ->will($this->returnValue($this->response)); + + try { + $this->object->get(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getComment method + * + * @return void + */ + public function testGetComment() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/comments/523') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->comments->get(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getComment method - simulated failure + * + * @return void + */ + public function testGetCommentFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/comments/523') + ->will($this->returnValue($this->response)); + + try { + $this->object->comments->get(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getComments method + * + * @return void + */ + public function testGetComments() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/comments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->comments->getList(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getComments method - simulated failure + * + * @return void + */ + public function testGetCommentsFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/comments') + ->will($this->returnValue($this->response)); + + try { + $this->object->comments->getList(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getCommitList method + * + * @return void + */ + public function testGetCommitList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/commits') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getCommitList(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getCommitList method - simulated failure + * + * @return void + */ + public function testGetCommitListFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/commits') + ->will($this->returnValue($this->response)); + + try { + $this->object->getCommitList(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getForkList method + * + * @return void + */ + public function testGetForkList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/forks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getForkList(523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getForkList method - simulated failure + * + * @return void + */ + public function testGetForkListFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/forks') + ->will($this->returnValue($this->response)); + + try { + $this->object->getForkList(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method - simulated failure + * + * @return void + */ + public function testGetListFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists') + ->will($this->returnValue($this->response)); + + try { + $this->object->getList(); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getListByUser method + * + * @return void + */ + public function testGetListByUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/gists') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListByUser('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getListByUser method - simulated failure + * + * @return void + */ + public function testGetListByUserFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/gists') + ->will($this->returnValue($this->response)); + + try { + $this->object->getListByUser('joomla'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getListPublic method + * + * @return void + */ + public function testGetListPublic() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/public') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListPublic(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getListPublic method - simulated failure + * + * @return void + */ + public function testGetListPublicFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/public') + ->will($this->returnValue($this->response)); + + try { + $this->object->getListPublic(); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getListStarred method + * + * @return void + */ + public function testGetListStarred() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/starred') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListStarred(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getListStarred method - simulated failure + * + * @return void + */ + public function testGetListStarredFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/starred') + ->will($this->returnValue($this->response)); + + try { + $this->object->getListStarred(); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the getRevision method + * + * @return void + */ + public function testGetRevision() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/a1b2c3') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRevision(523, 'a1b2c3'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getRevision method - simulated failure + * + * @return void + */ + public function testGetRevisionFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/a1b2c3') + ->will($this->returnValue($this->response)); + + try { + $this->object->getRevision(523, 'a1b2c3'); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the isStarred method when the gist has been starred + * + * @return void + */ + public function testIsStarredTrue() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/star') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isStarred(523), + $this->equalTo(true) + ); + } + + /** + * Tests the isStarred method when the gist has not been starred + * + * @return void + */ + public function testIsStarredFalse() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/star') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isStarred(523), + $this->equalTo(false) + ); + } + + /** + * Tests the isStarred method expecting a failure response + * + * @return void + */ + public function testIsStarredFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gists/523/star') + ->will($this->returnValue($this->response)); + + try { + $this->object->isStarred(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the star method + * + * @return void + */ + public function testStar() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/gists/523/star', '') + ->will($this->returnValue($this->response)); + + $this->object->star(523); + } + + /** + * Tests the star method - simulated failure + * + * @return void + */ + public function testStarFailure() + { + $exception = false; + + $this->response->code = 504; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('put') + ->with('/gists/523/star', '') + ->will($this->returnValue($this->response)); + + try { + $this->object->star(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Tests the unstar method + * + * @return void + */ + public function testUnstar() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/523/star') + ->will($this->returnValue($this->response)); + + $this->object->unstar(523); + } + + /** + * Tests the unstar method - simulated failure + * + * @return void + */ + public function testUnstarFailure() + { + $exception = false; + + $this->response->code = 504; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/gists/523/star') + ->will($this->returnValue($this->response)); + + try { + $this->object->unstar(523); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } } diff --git a/Tests/Package/GitignoreTest.php b/Tests/Package/GitignoreTest.php index 536523eb..c537d559 100644 --- a/Tests/Package/GitignoreTest.php +++ b/Tests/Package/GitignoreTest.php @@ -16,37 +16,37 @@ */ class GitignoreTest extends GitHubTestCase { - /** - * @var Gitignore - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Gitignore($this->options, $this->client); - } - - /** - * Tests the getList method. - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = '[ + /** + * @var Gitignore + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Gitignore($this->options, $this->client); + } + + /** + * Tests the getList method. + * + * @return void + * + * @since 1.0 + */ + public function testGetList() + { + $this->response->code = 200; + $this->response->body = '[ "Actionscript", "Android", "AppceleratorTitanium", @@ -56,55 +56,55 @@ public function testGetList() "C++" ]'; - $this->client->expects($this->once()) - ->method('get') - ->with('/gitignore/templates', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the get method. - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = '{ + $this->client->expects($this->once()) + ->method('get') + ->with('/gitignore/templates', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the get method. + * + * @return void + * + * @since 1.0 + */ + public function testGet() + { + $this->response->code = 200; + $this->response->body = '{ "name": "C", "source": "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Windows DLLs)\n' - . '*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n" + . '*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n" }'; - $this->client->expects($this->once()) - ->method('get') - ->with('/gitignore/templates/C', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('C'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the get method with raw return data. - * - * @return void - * - * @since 1.0 - */ - public function testGetRaw() - { - $this->response->code = 200; - $this->response->body = '# Object files + $this->client->expects($this->once()) + ->method('get') + ->with('/gitignore/templates/C', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('C'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the get method with raw return data. + * + * @return void + * + * @since 1.0 + */ + public function testGetRaw() + { + $this->response->code = 200; + $this->response->body = '# Object files *.o # Libraries @@ -123,38 +123,38 @@ public function testGetRaw() *.app '; - $this->client->expects($this->once()) - ->method('get') - ->with('/gitignore/templates/C', array('Accept' => 'application/vnd.github.raw+json'), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('C', true), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the get method with failure. - * - * @since 1.0 - * @return void - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 404; - $this->response->body = '{"message":"Not found"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/gitignore/templates/X', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('X'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->client->expects($this->once()) + ->method('get') + ->with('/gitignore/templates/C', ['Accept' => 'application/vnd.github.raw+json'], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('C', true), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the get method with failure. + * + * @since 1.0 + * @return void + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 404; + $this->response->body = '{"message":"Not found"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/gitignore/templates/X', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('X'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/GraphqlTest.php b/Tests/Package/GraphqlTest.php index d36e017a..b9aa9a3c 100644 --- a/Tests/Package/GraphqlTest.php +++ b/Tests/Package/GraphqlTest.php @@ -16,103 +16,100 @@ */ class GraphqlTest extends GitHubTestCase { - /** - * @var Graphql - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Graphql($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 200; - $this->response->body = $this->sampleString; - - // Build the query. - $query = 'foo'; - - // Build the request data. - $data = array( - 'query' => $query, - ); - - // Build the headers. - $headers = array( - 'Accept' => 'application/vnd.github.v4+json', - 'Content-Type' => 'application/json', - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/graphql', json_encode($data), $headers) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->execute($query), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreateFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - // Build the query. - $query = 'foo'; - - // Build the request data. - $data = array( - 'query' => $query, - ); - - // Build the headers. - $headers = array( - 'Accept' => 'application/vnd.github.v4+json', - 'Content-Type' => 'application/json', - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/graphql', json_encode($data), $headers) - ->will($this->returnValue($this->response)); - - try - { - $this->object->execute($query); - $this->fail('Exception not thrown'); - } - catch (\DomainException $e) - { - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - } + /** + * @var Graphql + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Graphql($this->options, $this->client); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 200; + $this->response->body = $this->sampleString; + + // Build the query. + $query = 'foo'; + + // Build the request data. + $data = [ + 'query' => $query, + ]; + + // Build the headers. + $headers = [ + 'Accept' => 'application/vnd.github.v4+json', + 'Content-Type' => 'application/json', + ]; + + $this->client->expects($this->once()) + ->method('post') + ->with('/graphql', json_encode($data), $headers) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->execute($query), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreateFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + // Build the query. + $query = 'foo'; + + // Build the request data. + $data = [ + 'query' => $query, + ]; + + // Build the headers. + $headers = [ + 'Accept' => 'application/vnd.github.v4+json', + 'Content-Type' => 'application/json', + ]; + + $this->client->expects($this->once()) + ->method('post') + ->with('/graphql', json_encode($data), $headers) + ->will($this->returnValue($this->response)); + + try { + $this->object->execute($query); + $this->fail('Exception not thrown'); + } catch (\DomainException $e) { + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + } } diff --git a/Tests/Package/Issues/AssigneesTest.php b/Tests/Package/Issues/AssigneesTest.php index b17450b1..18d98733 100644 --- a/Tests/Package/Issues/AssigneesTest.php +++ b/Tests/Package/Issues/AssigneesTest.php @@ -16,48 +16,48 @@ */ class AssigneesTest extends GitHubTestCase { - /** - * @var Assignees Object under test. - * @since 1.0 - */ - protected $object; - - /** - * @var string - * @since 1.0 - */ - protected $owner = 'joomla'; - - /** - * @var string - * @since 1.0 - */ - protected $repo = 'joomla-framework'; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Assignees($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = '[ + /** + * @var Assignees Object under test. + * @since 1.0 + */ + protected $object; + + /** + * @var string + * @since 1.0 + */ + protected $owner = 'joomla'; + + /** + * @var string + * @since 1.0 + */ + protected $repo = 'joomla-framework'; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Assignees($this->options, $this->client); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->response->code = 200; + $this->response->body = '[ { "login": "octocat", "id": 1, @@ -67,109 +67,109 @@ public function testGetList() } ]'; - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList($this->owner, $this->repo), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getList method - * Response: - * If the given assignee login belongs to an assignee for the repository, - * a 204 header with no content is returned. - * Otherwise a 404 status code is returned. - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - $this->response->body = ''; - - $assignee = 'elkuku'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check($this->owner, $this->repo, $assignee), - $this->equalTo(true) - ); - } - - /** - * Tests the getList method with a negative response - * Response: - * If the given assignee login belongs to an assignee for the repository, - * a 204 header with no content is returned. - * Otherwise a 404 status code is returned. - * - * @return void - */ - public function testCheckNo() - { - $this->response->code = 404; - $this->response->body = ''; - - $assignee = 'elkuku'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check($this->owner, $this->repo, $assignee), - $this->equalTo(false) - ); - } - - /** - * Tests the getList method with a negative response - * Response: - * If the given assignee login belongs to an assignee for the repository, - * a 204 header with no content is returned. - * Otherwise a 404 status code is returned. - * - * @return void - */ - public function testCheckException() - { - $this->expectException(\DomainException::class); - - $this->response->code = 666; - $this->response->body = ''; - - $assignee = 'elkuku'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check($this->owner, $this->repo, $assignee), - $this->equalTo(false) - ); - } - - /** - * Tests the add method - * - * @return void - */ - public function testAdd() - { - $this->response->code = 201; - $this->response->body = '[ + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList($this->owner, $this->repo), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getList method + * Response: + * If the given assignee login belongs to an assignee for the repository, + * a 204 header with no content is returned. + * Otherwise a 404 status code is returned. + * + * @return void + */ + public function testCheck() + { + $this->response->code = 204; + $this->response->body = ''; + + $assignee = 'elkuku'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check($this->owner, $this->repo, $assignee), + $this->equalTo(true) + ); + } + + /** + * Tests the getList method with a negative response + * Response: + * If the given assignee login belongs to an assignee for the repository, + * a 204 header with no content is returned. + * Otherwise a 404 status code is returned. + * + * @return void + */ + public function testCheckNo() + { + $this->response->code = 404; + $this->response->body = ''; + + $assignee = 'elkuku'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check($this->owner, $this->repo, $assignee), + $this->equalTo(false) + ); + } + + /** + * Tests the getList method with a negative response + * Response: + * If the given assignee login belongs to an assignee for the repository, + * a 204 header with no content is returned. + * Otherwise a 404 status code is returned. + * + * @return void + */ + public function testCheckException() + { + $this->expectException(\DomainException::class); + + $this->response->code = 666; + $this->response->body = ''; + + $assignee = 'elkuku'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/' . $this->owner . '/' . $this->repo . '/assignees/' . $assignee, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check($this->owner, $this->repo, $assignee), + $this->equalTo(false) + ); + } + + /** + * Tests the add method + * + * @return void + */ + public function testAdd() + { + $this->response->code = 201; + $this->response->body = '[ { "login": "octocat", "id": 1, @@ -179,26 +179,26 @@ public function testAdd() } ]'; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/issues/123/assignees', json_encode(array('assignees' => array('joomla')))) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->add($this->owner, $this->repo, 123, array('joomla')), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the remove method - * - * @return void - */ - public function testRemove() - { - $this->response->code = 200; - $this->response->body = '[ + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/' . $this->owner . '/' . $this->repo . '/issues/123/assignees', json_encode(['assignees' => ['joomla']])) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->add($this->owner, $this->repo, 123, ['joomla']), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the remove method + * + * @return void + */ + public function testRemove() + { + $this->response->code = 200; + $this->response->body = '[ { "login": "octocat", "id": 1, @@ -208,14 +208,14 @@ public function testRemove() } ]'; - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/' . $this->owner . '/' . $this->repo . '/issues/123/assignees', [], null, json_encode(['assignees' => ['joomla']])) - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/' . $this->owner . '/' . $this->repo . '/issues/123/assignees', [], null, json_encode(['assignees' => ['joomla']])) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->remove($this->owner, $this->repo, 123, array('joomla')), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->remove($this->owner, $this->repo, 123, ['joomla']), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Issues/CommentsTest.php b/Tests/Package/Issues/CommentsTest.php index 184baf65..c125f1f3 100644 --- a/Tests/Package/Issues/CommentsTest.php +++ b/Tests/Package/Issues/CommentsTest.php @@ -16,181 +16,181 @@ */ class CommentsTest extends GitHubTestCase { - /** - * @var Comments Object under test. - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Comments($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/1/comments', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getRepositoryList method - * - * @return void - */ - public function testGetRepositoryList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/comments?sort=created&direction=asc', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositoryList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getRepositoryListInvalidSort method - * - * @return void - */ - public function testGetRepositoryListInvalidSort() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->getRepositoryList('joomla', 'joomla-platform', 'invalid'); - } - - /** - * Tests the getRepositoryListInvalidDirection method - * - * @return void - */ - public function testGetRepositoryListInvalidDirection() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'invalid'); - } - - /** - * Tests the getRepositoryListSince method - * - * @return void - */ - public function testGetRepositoryListSince() - { - $date = new \DateTime('1966-09-15 12:34:56', new \DateTimeZone('UTC')); - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/comments?sort=created&direction=asc&since=1966-09-15T12:34:56+00:00', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'asc', $date), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/comments/1', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/issues/comments/1', '{"body":"Hello"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 1, 'Hello'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/issues/1/comments', '{"body":"Hello"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 1, 'Hello'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/comments/1', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 1), - $this->equalTo(true) - ); - } + /** + * @var Comments Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Comments($this->options, $this->client); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/1/comments', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getRepositoryList method + * + * @return void + */ + public function testGetRepositoryList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/comments?sort=created&direction=asc', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositoryList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getRepositoryListInvalidSort method + * + * @return void + */ + public function testGetRepositoryListInvalidSort() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->getRepositoryList('joomla', 'joomla-platform', 'invalid'); + } + + /** + * Tests the getRepositoryListInvalidDirection method + * + * @return void + */ + public function testGetRepositoryListInvalidDirection() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'invalid'); + } + + /** + * Tests the getRepositoryListSince method + * + * @return void + */ + public function testGetRepositoryListSince() + { + $date = new \DateTime('1966-09-15 12:34:56', new \DateTimeZone('UTC')); + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/comments?sort=created&direction=asc&since=1966-09-15T12:34:56+00:00', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getRepositoryList('joomla', 'joomla-platform', 'created', 'asc', $date), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/comments/1', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/issues/comments/1', '{"body":"Hello"}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 1, 'Hello'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/issues/1/comments', '{"body":"Hello"}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 1, 'Hello'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/issues/comments/1', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 1), + $this->equalTo(true) + ); + } } diff --git a/Tests/Package/Issues/EventsTest.php b/Tests/Package/Issues/EventsTest.php index 7347cde3..d9bee5f9 100644 --- a/Tests/Package/Issues/EventsTest.php +++ b/Tests/Package/Issues/EventsTest.php @@ -16,78 +16,78 @@ */ class EventsTest extends GitHubTestCase { - /** - * @var Events Object under test. - * @since 1.0 - */ - protected $object; + /** + * @var Events Object under test. + * @since 1.0 + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Events($this->options, $this->client); - } + $this->object = new Events($this->options, $this->client); + } - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/1/events', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/1/events', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the getListRepository method - * - * @return void - */ - public function testGetListRepository() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/1/comments', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the getListRepository method + * + * @return void + */ + public function testGetListRepository() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/1/comments', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getListRepository('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->getListRepository('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/events/1', array(), 0) - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/events/1', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Issues/LabelsTest.php b/Tests/Package/Issues/LabelsTest.php index 4593795f..b5221ada 100644 --- a/Tests/Package/Issues/LabelsTest.php +++ b/Tests/Package/Issues/LabelsTest.php @@ -16,251 +16,251 @@ */ class LabelsTest extends GitHubTestCase { - /** - * @var Labels Object under test. - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Labels($this->options, $this->client); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/labels/1', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '1'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/labels', '{"name":"foobar","color":"red"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'foobar', 'red'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the createFailure method - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 404; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/labels', '{"name":"foobar","color":"red"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'foobar', 'red'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the update method - * - * @return void - */ - public function testUpdate() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/labels/foobar', '{"name":"boofaz","color":"red"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->update('joomla', 'joomla-platform', 'foobar', 'boofaz', 'red'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/labels/foobar', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 'foobar'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getListByIssue method - * - * @return void - */ - public function testGetListByIssue() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/1/labels', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListByIssue('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the add method - * - * @return void - */ - public function testAdd() - { - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/issues/1/labels', '["A","B"]', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->add('joomla', 'joomla-platform', 1, array('A', 'B')), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the removeFromIssue method - * - * @return void - */ - public function testRemoveFromIssue() - { - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/1/labels/foobar', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeFromIssue('joomla', 'joomla-platform', 1, 'foobar'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the replace method - * - * @return void - */ - public function testReplace() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/issues/1/labels', '["A","B"]', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->replace('joomla', 'joomla-platform', 1, array('A', 'B')), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the removeAllFromIssue method - * - * @return void - */ - public function testRemoveAllFromIssue() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/1/labels', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeAllFromIssue('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getListByMilestone method - * - * @return void - */ - public function testGetListByMilestone() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/milestones/1/labels', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListByMilestone('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Labels Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Labels($this->options, $this->client); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/labels', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/labels/1', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '1'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/labels', '{"name":"foobar","color":"red"}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'foobar', 'red'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the createFailure method + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 404; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/labels', '{"name":"foobar","color":"red"}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'foobar', 'red'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the update method + * + * @return void + */ + public function testUpdate() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/labels/foobar', '{"name":"boofaz","color":"red"}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->update('joomla', 'joomla-platform', 'foobar', 'boofaz', 'red'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/labels/foobar', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 'foobar'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getListByIssue method + * + * @return void + */ + public function testGetListByIssue() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/1/labels', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListByIssue('joomla', 'joomla-platform', 1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the add method + * + * @return void + */ + public function testAdd() + { + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/issues/1/labels', '["A","B"]', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->add('joomla', 'joomla-platform', 1, ['A', 'B']), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the removeFromIssue method + * + * @return void + */ + public function testRemoveFromIssue() + { + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/issues/1/labels/foobar', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeFromIssue('joomla', 'joomla-platform', 1, 'foobar'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the replace method + * + * @return void + */ + public function testReplace() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/issues/1/labels', '["A","B"]', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->replace('joomla', 'joomla-platform', 1, ['A', 'B']), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the removeAllFromIssue method + * + * @return void + */ + public function testRemoveAllFromIssue() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/issues/1/labels', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeAllFromIssue('joomla', 'joomla-platform', 1), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getListByMilestone method + * + * @return void + */ + public function testGetListByMilestone() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/milestones/1/labels', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListByMilestone('joomla', 'joomla-platform', 1), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/Issues/MilestonesTest.php b/Tests/Package/Issues/MilestonesTest.php index d42a67de..3a415ff8 100644 --- a/Tests/Package/Issues/MilestonesTest.php +++ b/Tests/Package/Issues/MilestonesTest.php @@ -16,275 +16,281 @@ */ class MilestonesTest extends GitHubTestCase { - /** - * @var Milestones Object under test. - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Milestones($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - * - * @since 1.0 - */ - public function testCreate() - { - $this->response->code = 201; - - $milestone = '{' - . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' - . '}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/milestones', $milestone) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'My Milestone', 'open', 'This milestone is impossible', '2012-12-25T20:09:31Z'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the create method - failure - * - * @return void - * - * @since 12.3 - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $milestone = '{' - . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' - . '}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/milestones', $milestone) - ->will($this->returnValue($this->response)); - - $this->object->create('joomla', 'joomla-platform', 'My Milestone', 'open', 'This milestone is impossible', '2012-12-25T20:09:31Z'); - } - - /** - * Tests the edit method - * - * @return void - * - * @since 12.3 - */ - public function testEdit() - { - $milestone = new \stdClass; - $milestone->state = 'closed'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the edit method with all parameters - * - * @return void - * - * @since 12.3 - */ - public function testEditAllParameters() - { - $milestone = '{' - . '"title":"{title}","state":"closed","description":"{description}","due_on":"2012-12-25T20:09:31Z"' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/{user}/{repo}/milestones/523', $milestone) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('{user}', '{repo}', 523, '{title}', 'closed', '{description}', - '2012-12-25T20:09:31Z' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - failure - * - * @return void - * - * @since 12.3 - */ - public function testEditFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $milestone = new \stdClass; - $milestone->state = 'closed'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) - ->will($this->returnValue($this->response)); - - $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'); - } - - /** - * Tests the get method - * - * @return void - * - * @since 12.3 - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/milestones/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - failure - * - * @return void - * - * @since 12.3 - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/milestones/523') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 523); - } - - /** - * Tests the getList method - * - * @return void - * - * @since 12.3 - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - * - * @since 12.3 - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } - - /** - * Tests the delete method - * - * @return void - * - * @since 12.3 - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/milestones/254') - ->will($this->returnValue($this->response)); - - $this->object->delete('joomla', 'joomla-platform', 254); - } - - /** - * Tests the delete method - failure - * - * @return void - * - * @since 12.3 - */ - public function testDeleteFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/milestones/254') - ->will($this->returnValue($this->response)); - - $this->object->delete('joomla', 'joomla-platform', 254); - } + /** + * @var Milestones Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Milestones($this->options, $this->client); + } + + /** + * Tests the create method + * + * @return void + * + * @since 1.0 + */ + public function testCreate() + { + $this->response->code = 201; + + $milestone = '{' + . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' + . '}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/milestones', $milestone) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'My Milestone', 'open', 'This milestone is impossible', '2012-12-25T20:09:31Z'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the create method - failure + * + * @return void + * + * @since 12.3 + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $milestone = '{' + . '"title":"My Milestone","state":"open","description":"This milestone is impossible","due_on":"2012-12-25T20:09:31Z"' + . '}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/milestones', $milestone) + ->will($this->returnValue($this->response)); + + $this->object->create('joomla', 'joomla-platform', 'My Milestone', 'open', 'This milestone is impossible', '2012-12-25T20:09:31Z'); + } + + /** + * Tests the edit method + * + * @return void + * + * @since 12.3 + */ + public function testEdit() + { + $milestone = new \stdClass(); + $milestone->state = 'closed'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the edit method with all parameters + * + * @return void + * + * @since 12.3 + */ + public function testEditAllParameters() + { + $milestone = '{' + . '"title":"{title}","state":"closed","description":"{description}","due_on":"2012-12-25T20:09:31Z"' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/{user}/{repo}/milestones/523', $milestone) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit( + '{user}', + '{repo}', + 523, + '{title}', + 'closed', + '{description}', + '2012-12-25T20:09:31Z' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the edit method - failure + * + * @return void + * + * @since 12.3 + */ + public function testEditFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $milestone = new \stdClass(); + $milestone->state = 'closed'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/milestones/523', json_encode($milestone)) + ->will($this->returnValue($this->response)); + + $this->object->edit('joomla', 'joomla-platform', 523, null, 'closed'); + } + + /** + * Tests the get method + * + * @return void + * + * @since 12.3 + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/milestones/523') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method - failure + * + * @return void + * + * @since 12.3 + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/milestones/523') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 523); + } + + /** + * Tests the getList method + * + * @return void + * + * @since 12.3 + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method - failure + * + * @return void + * + * @since 12.3 + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/milestones?state=open&sort=due_date&direction=desc') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } + + /** + * Tests the delete method + * + * @return void + * + * @since 12.3 + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/milestones/254') + ->will($this->returnValue($this->response)); + + $this->object->delete('joomla', 'joomla-platform', 254); + } + + /** + * Tests the delete method - failure + * + * @return void + * + * @since 12.3 + */ + public function testDeleteFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 504; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/milestones/254') + ->will($this->returnValue($this->response)); + + $this->object->delete('joomla', 'joomla-platform', 254); + } } diff --git a/Tests/Package/IssuesTest.php b/Tests/Package/IssuesTest.php index 466e7750..2d252bdf 100755 --- a/Tests/Package/IssuesTest.php +++ b/Tests/Package/IssuesTest.php @@ -18,508 +18,516 @@ */ class IssuesTest extends GitHubTestCase { - /** - * @var Issues Object under test. - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Issues($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::create() - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $issue = new \stdClass; - $issue->title = '{title}'; - $issue->milestone = '{milestone}'; - $issue->labels = ['{label1}']; - $issue->body = '{body}'; - $issue->assignee = '{assignee}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{user}/{repo}/issues', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', array('{label1}')), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::create() - * - * @return void - */ - public function testCreate2() - { - $this->response->code = 201; - - $issue = new \stdClass; - $issue->title = '{title}'; - $issue->milestone = '{milestone}'; - $issue->labels = array('{label1}'); - $issue->body = '{body}'; - $issue->assignees = array('{assignee1}'); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{user}/{repo}/issues', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('{user}', '{repo}', '{title}', '{body}', null, '{milestone}', array('{label1}'), array('{assignee1}')), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::create() - * - * Failure - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->title = '{title}'; - $issue->milestone = '{milestone}'; - $issue->labels = array('{label1}'); - $issue->body = '{body}'; - $issue->assignee = '{assignee}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{user}/{repo}/issues', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', array('{label1}')); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::create() - * - * @return void - */ - public function testCreateComment() - { - $this->response->code = 201; - - $issue = new \stdClass; - $issue->body = 'My Insightful Comment'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/issues/523/comments', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->comments->create('joomla', 'joomla-platform', 523, 'My Insightful Comment'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::create() - * - * Failure - * - * @return void - */ - public function testCreateCommentFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->body = 'My Insightful Comment'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/issues/523/comments', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->comments->create('joomla', 'joomla-platform', 523, 'My Insightful Comment'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::edit() - * - * @return void - */ - public function testEdit() - { - $issue = new \stdClass; - $issue->title = 'My issue'; - $issue->body = 'These are my changes - please review them'; - $issue->state = 'Closed'; - $issue->assignee = 'JoeAssignee'; - $issue->milestone = '12.2'; - $issue->labels = array('Fixed'); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/issues/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 523, 'Closed', 'My issue', 'These are my changes - please review them', - 'JoeAssignee', '12.2', array('Fixed') - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::edit() - * - * Failure - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $issue = new \stdClass; - $issue->title = 'My issue'; - $issue->body = 'These are my changes - please review them'; - $issue->state = 'Closed'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/issues/523', json_encode($issue)) - ->will($this->returnValue($this->response)); - - $this->object->edit('joomla', 'joomla-platform', 523, 'Closed', 'My issue', 'These are my changes - please review them'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::get() - * - * Failure - * - * @return void - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues/523') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 523); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/issues') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getList() - * - * @return void - */ - public function testGetListAll() - { - $since = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); - - $this->client->expects($this->once()) - ->method('get') - ->with('/issues?filter={filter}&state={state}&labels={labels}&sort={sort}&direction={direction}&since=2012-01-01T12:12:12+0000') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('{filter}', '{state}', '{labels}', '{sort}', '{direction}', $since), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getList() - * - * Failure - * - * @return void - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/issues') - ->will($this->returnValue($this->response)); - - $this->object->getList(); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getListByRepository() - * - * @return void - */ - public function testGetListByRepository() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListByRepository('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getListByRepository() - * - * With all parameters - * - * @return void - */ - public function testGetListByRepositoryAll() - { - $date = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); - - $this->client->expects($this->once()) - ->method('get') - ->with( - '/repos/joomla/joomla-platform/issues?milestone=25&state=closed&assignee=none&' . - 'mentioned=joomla-jenkins&labels=bug&sort=created&direction=asc&since=2012-01-01T12:12:12+00:00' - ) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListByRepository( - 'joomla', - 'joomla-platform', - '25', - 'closed', - 'none', - 'joomla-jenkins', - 'bug', - 'created', - 'asc', - $date - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::getListByRepository() - * - * Failure - * - * @return void - */ - public function testGetListByRepositoryFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/issues') - ->will($this->returnValue($this->response)); - - $this->object->getListByRepository('joomla', 'joomla-platform'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::lock() - * - * @return void - */ - public function testLock() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->lock('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::lock() - * - * Failure - * - * @return void - */ - public function testLockFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); - - $this->object->lock('joomla', 'joomla-platform', 523); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::unlock() - * - * @return void - */ - public function testUnlock() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->unlock('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Issues::unlock() - * - * Failure - * - * @return void - */ - public function testUnlockFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/523/lock') - ->will($this->returnValue($this->response)); - - $this->object->unlock('joomla', 'joomla-platform', 523); - } + /** + * @var Issues Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Issues($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $issue = new \stdClass(); + $issue->title = '{title}'; + $issue->milestone = '{milestone}'; + $issue->labels = ['{label1}']; + $issue->body = '{body}'; + $issue->assignee = '{assignee}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{user}/{repo}/issues', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', ['{label1}']), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * @return void + */ + public function testCreate2() + { + $this->response->code = 201; + + $issue = new \stdClass(); + $issue->title = '{title}'; + $issue->milestone = '{milestone}'; + $issue->labels = ['{label1}']; + $issue->body = '{body}'; + $issue->assignees = ['{assignee1}']; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{user}/{repo}/issues', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('{user}', '{repo}', '{title}', '{body}', null, '{milestone}', ['{label1}'], ['{assignee1}']), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * Failure + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $issue = new \stdClass(); + $issue->title = '{title}'; + $issue->milestone = '{milestone}'; + $issue->labels = ['{label1}']; + $issue->body = '{body}'; + $issue->assignee = '{assignee}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{user}/{repo}/issues', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->object->create('{user}', '{repo}', '{title}', '{body}', '{assignee}', '{milestone}', ['{label1}']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * @return void + */ + public function testCreateComment() + { + $this->response->code = 201; + + $issue = new \stdClass(); + $issue->body = 'My Insightful Comment'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/issues/523/comments', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->comments->create('joomla', 'joomla-platform', 523, 'My Insightful Comment'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::create() + * + * Failure + * + * @return void + */ + public function testCreateCommentFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $issue = new \stdClass(); + $issue->body = 'My Insightful Comment'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/issues/523/comments', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->object->comments->create('joomla', 'joomla-platform', 523, 'My Insightful Comment'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::edit() + * + * @return void + */ + public function testEdit() + { + $issue = new \stdClass(); + $issue->title = 'My issue'; + $issue->body = 'These are my changes - please review them'; + $issue->state = 'Closed'; + $issue->assignee = 'JoeAssignee'; + $issue->milestone = '12.2'; + $issue->labels = ['Fixed']; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/issues/523', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit( + 'joomla', + 'joomla-platform', + 523, + 'Closed', + 'My issue', + 'These are my changes - please review them', + 'JoeAssignee', + '12.2', + ['Fixed'] + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::edit() + * + * Failure + * + * @return void + */ + public function testEditFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $issue = new \stdClass(); + $issue->title = 'My issue'; + $issue->body = 'These are my changes - please review them'; + $issue->state = 'Closed'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/issues/523', json_encode($issue)) + ->will($this->returnValue($this->response)); + + $this->object->edit('joomla', 'joomla-platform', 523, 'Closed', 'My issue', 'These are my changes - please review them'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/523') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::get() + * + * Failure + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/523') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 523); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/issues') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getList() + * + * @return void + */ + public function testGetListAll() + { + $since = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); + + $this->client->expects($this->once()) + ->method('get') + ->with('/issues?filter={filter}&state={state}&labels={labels}&sort={sort}&direction={direction}&since=2012-01-01T12:12:12+0000') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('{filter}', '{state}', '{labels}', '{sort}', '{direction}', $since), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getList() + * + * Failure + * + * @return void + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/issues') + ->will($this->returnValue($this->response)); + + $this->object->getList(); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getListByRepository() + * + * @return void + */ + public function testGetListByRepository() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListByRepository('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getListByRepository() + * + * With all parameters + * + * @return void + */ + public function testGetListByRepositoryAll() + { + $date = new \DateTime('January 1, 2012 12:12:12', new \DateTimeZone('UTC')); + + $this->client->expects($this->once()) + ->method('get') + ->with( + '/repos/joomla/joomla-platform/issues?milestone=25&state=closed&assignee=none&' . + 'mentioned=joomla-jenkins&labels=bug&sort=created&direction=asc&since=2012-01-01T12:12:12+00:00' + ) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListByRepository( + 'joomla', + 'joomla-platform', + '25', + 'closed', + 'none', + 'joomla-jenkins', + 'bug', + 'created', + 'asc', + $date + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::getListByRepository() + * + * Failure + * + * @return void + */ + public function testGetListByRepositoryFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues') + ->will($this->returnValue($this->response)); + + $this->object->getListByRepository('joomla', 'joomla-platform'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::lock() + * + * @return void + */ + public function testLock() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/issues/523/lock') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->lock('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::lock() + * + * Failure + * + * @return void + */ + public function testLockFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/issues/523/lock') + ->will($this->returnValue($this->response)); + + $this->object->lock('joomla', 'joomla-platform', 523); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::unlock() + * + * @return void + */ + public function testUnlock() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/issues/523/lock') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->unlock('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Issues::unlock() + * + * Failure + * + * @return void + */ + public function testUnlockFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/issues/523/lock') + ->will($this->returnValue($this->response)); + + $this->object->unlock('joomla', 'joomla-platform', 523); + } } diff --git a/Tests/Package/MarkdownTest.php b/Tests/Package/MarkdownTest.php index 95ca4689..c1442ba6 100644 --- a/Tests/Package/MarkdownTest.php +++ b/Tests/Package/MarkdownTest.php @@ -16,113 +16,117 @@ */ class MarkdownTest extends GitHubTestCase { - /** - * @var Markdown - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Markdown($this->options, $this->client); - } - - /** - * Tests the render method - * - * @return void - */ - public function testRender() - { - $this->response->code = 200; - $this->response->body = '

Hello world github/linguist#1 cool, ' - . 'and #1!

'; - - $text = 'Hello world github/linguist#1 **cool**, and #1!'; - $mode = 'gfm'; - $context = 'github/gollum'; - - $data = str_replace( - '\\/', '/', json_encode( - array( - 'text' => $text, - 'mode' => $mode, - 'context' => $context - ) - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/markdown', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->render($text, $mode, $context), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the renderInvalidMode method - * - * @return void - */ - public function testRenderInvalidMode() - { - $this->expectException(\InvalidArgumentException::class); - - $this->assertThat( - $this->object->render('', 'xxx', 'github/gollum'), - $this->equalTo('') - ); - } - - /** - * Tests the renderFailure method - * - * @return void - */ - public function testRenderFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 404; - $this->response->body = ''; - - $text = 'Hello world github/linguist#1 **cool**, and #1!'; - $mode = 'gfm'; - $context = 'github/gollum'; - - $data = str_replace( - '\\/', '/', json_encode( - array( - 'text' => $text, - 'mode' => $mode, - 'context' => $context - ) - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/markdown', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->render($text, $mode, $context), - $this->equalTo('') - ); - } + /** + * @var Markdown + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Markdown($this->options, $this->client); + } + + /** + * Tests the render method + * + * @return void + */ + public function testRender() + { + $this->response->code = 200; + $this->response->body = '

Hello world github/linguist#1 cool, ' + . 'and #1!

'; + + $text = 'Hello world github/linguist#1 **cool**, and #1!'; + $mode = 'gfm'; + $context = 'github/gollum'; + + $data = str_replace( + '\\/', + '/', + json_encode( + [ + 'text' => $text, + 'mode' => $mode, + 'context' => $context, + ] + ) + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/markdown', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->render($text, $mode, $context), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the renderInvalidMode method + * + * @return void + */ + public function testRenderInvalidMode() + { + $this->expectException(\InvalidArgumentException::class); + + $this->assertThat( + $this->object->render('', 'xxx', 'github/gollum'), + $this->equalTo('') + ); + } + + /** + * Tests the renderFailure method + * + * @return void + */ + public function testRenderFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 404; + $this->response->body = ''; + + $text = 'Hello world github/linguist#1 **cool**, and #1!'; + $mode = 'gfm'; + $context = 'github/gollum'; + + $data = str_replace( + '\\/', + '/', + json_encode( + [ + 'text' => $text, + 'mode' => $mode, + 'context' => $context, + ] + ) + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/markdown', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->render($text, $mode, $context), + $this->equalTo('') + ); + } } diff --git a/Tests/Package/MetaTest.php b/Tests/Package/MetaTest.php index f0964b4c..ddafbcee 100644 --- a/Tests/Package/MetaTest.php +++ b/Tests/Package/MetaTest.php @@ -16,76 +16,76 @@ */ class MetaTest extends GitHubTestCase { - /** - * @var Meta Object under test. - * @since 1.0 - */ - protected $object; + /** + * @var Meta Object under test. + * @since 1.0 + */ + protected $object; - /** - * @var string Sample JSON string. - * @since 1.0 - */ - protected $sampleString = '{"hooks":["127.0.0.1/32","192.168.1.1/32","10.10.1.1/27"],"git":["127.0.0.1/32"]}'; + /** + * @var string Sample JSON string. + * @since 1.0 + */ + protected $sampleString = '{"hooks":["127.0.0.1/32","192.168.1.1/32","10.10.1.1/27"],"git":["127.0.0.1/32"]}'; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @return void - * - * @since 1.0 - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Meta($this->options, $this->client); - } + $this->object = new Meta($this->options, $this->client); + } - /** - * Tests the getMeta method - * - * @return void - * - * @since 1.0 - */ - public function testGetMeta() - { - $decodedResponse = new \stdClass; - $decodedResponse->hooks = array('127.0.0.1/32', '192.168.1.1/32', '10.10.1.1/27'); - $decodedResponse->git = array('127.0.0.1/32'); + /** + * Tests the getMeta method + * + * @return void + * + * @since 1.0 + */ + public function testGetMeta() + { + $decodedResponse = new \stdClass(); + $decodedResponse->hooks = ['127.0.0.1/32', '192.168.1.1/32', '10.10.1.1/27']; + $decodedResponse->git = ['127.0.0.1/32']; - $this->client->expects($this->once()) - ->method('get') - ->with('/meta') - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('get') + ->with('/meta') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getMeta(), - $this->equalTo($decodedResponse) - ); - } + $this->assertThat( + $this->object->getMeta(), + $this->equalTo($decodedResponse) + ); + } - /** - * Tests the getMeta method - failure - * - * @return void - * - * @since 1.0 - */ - public function testGetMetaFailure() - { - $this->expectException(\DomainException::class); + /** + * Tests the getMeta method - failure + * + * @return void + * + * @since 1.0 + */ + public function testGetMetaFailure() + { + $this->expectException(\DomainException::class); - $this->response->code = 500; - $this->response->body = $this->errorString; + $this->response->code = 500; + $this->response->body = $this->errorString; - $this->client->expects($this->once()) - ->method('get') - ->with('/meta') - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('get') + ->with('/meta') + ->will($this->returnValue($this->response)); - $this->object->getMeta(); - } + $this->object->getMeta(); + } } diff --git a/Tests/Package/Orgs/HooksTest.php b/Tests/Package/Orgs/HooksTest.php index 6ad1b4ff..9066e1d5 100644 --- a/Tests/Package/Orgs/HooksTest.php +++ b/Tests/Package/Orgs/HooksTest.php @@ -18,209 +18,209 @@ */ class HooksTest extends GitHubTestCase { - /** - * @var Hooks - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Hooks($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/hooks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/hooks/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::create() - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/joomla/hooks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', '{url}', 'json', '{secret}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::create() - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Content type must be either "form" or "json"'); - - $this->object->create('joomla', '{url}', '{invalid}'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::create() - * - * @return void - */ - public function testCreateInvalidEvent() - { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('Your events array contains an unauthorized event.'); - - $this->object->create('{org}', '{url}', 'form', null, false, ['{invalid}']); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::edit() - * - * @return void - */ - public function testEdit() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/{org}/hooks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, array('create'), true), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::edit() - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->edit('{org}', '{url}', '{invalid}'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::edit() - * - * @return void - */ - public function testEditFailure2() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, array('{invalid}')); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::ping() - * - * @return void - */ - public function testPing() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/{org}/hooks/123/pings') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->ping('{org}', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Hooks::delete() - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/orgs/joomla/hooks/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Hooks + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Hooks($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/hooks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/hooks/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::create() + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/orgs/joomla/hooks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', '{url}', 'json', '{secret}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::create() + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Content type must be either "form" or "json"'); + + $this->object->create('joomla', '{url}', '{invalid}'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::create() + * + * @return void + */ + public function testCreateInvalidEvent() + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Your events array contains an unauthorized event.'); + + $this->object->create('{org}', '{url}', 'form', null, false, ['{invalid}']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::edit() + * + * @return void + */ + public function testEdit() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/orgs/{org}/hooks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, ['create'], true), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::edit() + * + * @return void + */ + public function testEditFailure() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->edit('{org}', '{url}', '{invalid}'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::edit() + * + * @return void + */ + public function testEditFailure2() + { + $this->expectException(\RuntimeException::class); + + $this->object->edit('{org}', '{url}', 'json', '{secret}', 1, ['{invalid}']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::ping() + * + * @return void + */ + public function testPing() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('post') + ->with('/orgs/{org}/hooks/123/pings') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->ping('{org}', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Hooks::delete() + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/orgs/joomla/hooks/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Orgs/MembersTest.php b/Tests/Package/Orgs/MembersTest.php index bed70da6..c508d802 100644 --- a/Tests/Package/Orgs/MembersTest.php +++ b/Tests/Package/Orgs/MembersTest.php @@ -18,485 +18,485 @@ */ class MembersTest extends GitHubTestCase { - /** - * @var Members - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Members($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::getList() - * - * @return void - */ - public function testGetListNotAMember() - { - $this->response->code = 302; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::getList() - * - * @return void - */ - public function testGetListUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::check() - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'elkuku'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::check() - * - * @return void - */ - public function testCheckNoMember() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'elkuku'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::check() - * - * @return void - */ - public function testCheckRequesterNoMember() - { - $this->response->code = 302; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'elkuku'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::check() - * - * @return void - */ - public function testCheckUnexpectedr() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla', 'elkuku'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::remove() - * - * @return void - */ - public function testRemove() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/orgs/joomla/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->remove('joomla', 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::getListPublic() - * - * @return void - */ - public function testGetListPublic() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/public_members') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListPublic('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() - * - * @return void - */ - public function testCheckPublic() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkPublic('joomla', 'elkuku'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() - * - * @return void - */ - public function testCheckPublicNo() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkPublic('joomla', 'elkuku'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() - * - * @return void - */ - public function testCheckPublicUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkPublic('joomla', 'elkuku'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::publicize() - * - * @return void - */ - public function testPublicize() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->publicize('joomla', 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::conceal() - * - * @return void - */ - public function testConceal() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/orgs/joomla/public_members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->conceal('joomla', 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::getMembership() - * - * @return void - */ - public function testGetMembership() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/{org}/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getMembership('{org}', '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() - * - * @return void - */ - public function testUpdateMembership() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/orgs/{org}/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->updateMembership('{org}', '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() - * - * @return void - */ - public function testUpdateMembershipInvalidRole() - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage("The user's role must be: member, admin"); - - $this->object->updateMembership('{org}', '{user}', 'INVALID'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::removeMembership() - * - * @return void - */ - public function testRemoveMembership() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/orgs/{org}/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeMembership('{org}', '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::listMemberships() - * - * @return void - */ - public function testListMemberships() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/memberships/orgs') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->listMemberships(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::listOrganizationMembership() - * - * @return void - */ - public function testListOrganizationMemberships() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/memberships/orgs/{org}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->listOrganizationMembership('{org}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() - * - * @return void - */ - public function testEditOrganizationMemberships() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/user/memberships/orgs/{org}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->editOrganizationMembership('{org}', 'active'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() - * - * @return void - */ - public function testEditOrganizationMembershipsInvalidState() - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('The state must be "active".'); - - $this->object->editOrganizationMembership('{org}', 'INVALID'); - } + /** + * @var Members + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Members($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getList() + * + * @return void + */ + public function testGetListNotAMember() + { + $this->response->code = 302; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getList() + * + * @return void + */ + public function testGetListUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() + * + * @return void + */ + public function testCheck() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'elkuku'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() + * + * @return void + */ + public function testCheckNoMember() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'elkuku'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() + * + * @return void + */ + public function testCheckRequesterNoMember() + { + $this->response->code = 302; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'elkuku'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::check() + * + * @return void + */ + public function testCheckUnexpectedr() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla', 'elkuku'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::remove() + * + * @return void + */ + public function testRemove() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/orgs/joomla/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->remove('joomla', 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getListPublic() + * + * @return void + */ + public function testGetListPublic() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/public_members') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListPublic('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() + * + * @return void + */ + public function testCheckPublic() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/public_members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkPublic('joomla', 'elkuku'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() + * + * @return void + */ + public function testCheckPublicNo() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/public_members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkPublic('joomla', 'elkuku'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::checkPublic() + * + * @return void + */ + public function testCheckPublicUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/public_members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkPublic('joomla', 'elkuku'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::publicize() + * + * @return void + */ + public function testPublicize() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/orgs/joomla/public_members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->publicize('joomla', 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::conceal() + * + * @return void + */ + public function testConceal() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/orgs/joomla/public_members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->conceal('joomla', 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::getMembership() + * + * @return void + */ + public function testGetMembership() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/{org}/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getMembership('{org}', '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() + * + * @return void + */ + public function testUpdateMembership() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/orgs/{org}/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->updateMembership('{org}', '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::updateMembership() + * + * @return void + */ + public function testUpdateMembershipInvalidRole() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage("The user's role must be: member, admin"); + + $this->object->updateMembership('{org}', '{user}', 'INVALID'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::removeMembership() + * + * @return void + */ + public function testRemoveMembership() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/orgs/{org}/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeMembership('{org}', '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::listMemberships() + * + * @return void + */ + public function testListMemberships() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/memberships/orgs') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->listMemberships(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::listOrganizationMembership() + * + * @return void + */ + public function testListOrganizationMemberships() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/memberships/orgs/{org}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->listOrganizationMembership('{org}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() + * + * @return void + */ + public function testEditOrganizationMemberships() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/user/memberships/orgs/{org}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->editOrganizationMembership('{org}', 'active'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Members::editOrganizationMembership() + * + * @return void + */ + public function testEditOrganizationMembershipsInvalidState() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The state must be "active".'); + + $this->object->editOrganizationMembership('{org}', 'INVALID'); + } } diff --git a/Tests/Package/Orgs/TeamsTest.php b/Tests/Package/Orgs/TeamsTest.php index 7ab71b99..ef2bf1ca 100644 --- a/Tests/Package/Orgs/TeamsTest.php +++ b/Tests/Package/Orgs/TeamsTest.php @@ -18,586 +18,586 @@ */ class TeamsTest extends GitHubTestCase { - /** - * @var Teams - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Teams($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/teams') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::create() - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/joomla/teams') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'TheTeam', array('joomla-platform'), 'admin'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::create() - * - * @return void - */ - public function testCreateWrongPermission() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 201; - - $this->object->create('joomla', 'TheTeam', array('joomla-platform'), 'invalid'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::edit() - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/teams/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit(123, 'TheTeam', 'admin'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::edit() - * - * @return void - */ - public function testEditWrongPermission() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->edit(123, 'TheTeam', 'invalid'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::delete() - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getListMembers() - * - * @return void - */ - public function testGetListMembers() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListMembers(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::isMember() - * - * @deprecated - * - * @return void - */ - public function testIsMember() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isMember(123, 'elkuku'), - $this->equalTo(json_decode(true)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::isMember() - * - * @deprecated - * - * @return void - */ - public function testIsMemberNo() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isMember(123, 'elkuku'), - $this->equalTo(json_decode(false)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::isMember() - * - * @deprecated - * - * @return void - */ - public function testIsMemberUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isMember(123, 'elkuku'), - $this->equalTo(json_decode(true)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addMember() - * - * @deprecated - * - * @return void - */ - public function testAddMember() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->addMember(123, 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::removeMember() - * - * @deprecated - * - * @return void - */ - public function testRemoveMember() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123/members/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeMember(123, 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getListRepos() - * - * @return void - */ - public function testGetListRepos() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListRepos(123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() - * - * @return void - */ - public function testCheckRepo() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos/joomla/cms') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkRepo(123, 'joomla', 'cms'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() - * - * @return void - */ - public function testCheckRepoNo() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos/joomla/cms') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkRepo(123, 'joomla', 'cms'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() - * - * @return void - */ - public function testCheckRepoUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/repos/joomla/cms') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkRepo(123, 'joomla', 'cms'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addRepo() - * - * @return void - */ - public function testAddRepo() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/teams/123/repos/joomla/joomla-platform') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->addRepo(123, 'joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::removeRepo() - * - * @return void - */ - public function testRemoveRepo() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123/repos/joomla/joomla-platform') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeRepo(123, 'joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() - * - * @return void - */ - public function testGetTeamMemberships() - { - $this->response->code = 200; - $this->response->body = '{"state":"TEST"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getTeamMembership(123, '{user}'), - $this->equalTo('TEST') - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() - * - * Response if user is not a member - * - * @return void - */ - public function testGetTeamMembershipsFailure1() - { - $this->response->code = 404; - $this->response->body = '{"state":"TEST"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getTeamMembership(123, '{user}'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() - * - * Unexpected Response - * - * @return void - */ - public function testGetTeamMembershipsFailure2() - { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Unexpected response code: 666'); - - $this->response->code = 666; - $this->response->body = '{"state":"TEST"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getTeamMembership(123, '{user}'), - $this->equalTo('TEST') - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() - * - * @return void - */ - public function testAddTeamMemberships() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->addTeamMembership(123, '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() - * - * Invalid role - * - * @return void - */ - public function testAddTeamMembershipsFailure() - { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Roles must be either "member" or "maintainer".'); - - $this->object->addTeamMembership(123, '{user}', 'INVALID'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::removeTeamMembership() - * - * @return void - */ - public function testRemoveTeamMemberships() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/teams/123/memberships/{user}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->removeTeamMembership(123, '{user}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Orgs\Teams::getUserTeams() - * - * @return void - */ - public function testGetUserTeams() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/teams') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getUserTeams(), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Teams + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Teams($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/teams') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get(123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::create() + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/orgs/joomla/teams') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'TheTeam', ['joomla-platform'], 'admin'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::create() + * + * @return void + */ + public function testCreateWrongPermission() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 201; + + $this->object->create('joomla', 'TheTeam', ['joomla-platform'], 'invalid'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::edit() + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/teams/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit(123, 'TheTeam', 'admin'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::edit() + * + * @return void + */ + public function testEditWrongPermission() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->edit(123, 'TheTeam', 'invalid'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::delete() + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/teams/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete(123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getListMembers() + * + * @return void + */ + public function testGetListMembers() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/members') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListMembers(123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::isMember() + * + * @deprecated + * + * @return void + */ + public function testIsMember() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isMember(123, 'elkuku'), + $this->equalTo(json_decode(true)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::isMember() + * + * @deprecated + * + * @return void + */ + public function testIsMemberNo() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isMember(123, 'elkuku'), + $this->equalTo(json_decode(false)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::isMember() + * + * @deprecated + * + * @return void + */ + public function testIsMemberUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isMember(123, 'elkuku'), + $this->equalTo(json_decode(true)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addMember() + * + * @deprecated + * + * @return void + */ + public function testAddMember() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/teams/123/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->addMember(123, 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::removeMember() + * + * @deprecated + * + * @return void + */ + public function testRemoveMember() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/teams/123/members/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeMember(123, 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getListRepos() + * + * @return void + */ + public function testGetListRepos() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/repos') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListRepos(123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() + * + * @return void + */ + public function testCheckRepo() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/repos/joomla/cms') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkRepo(123, 'joomla', 'cms'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() + * + * @return void + */ + public function testCheckRepoNo() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/repos/joomla/cms') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkRepo(123, 'joomla', 'cms'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::checkRepo() + * + * @return void + */ + public function testCheckRepoUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/repos/joomla/cms') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkRepo(123, 'joomla', 'cms'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addRepo() + * + * @return void + */ + public function testAddRepo() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/teams/123/repos/joomla/joomla-platform') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->addRepo(123, 'joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::removeRepo() + * + * @return void + */ + public function testRemoveRepo() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/teams/123/repos/joomla/joomla-platform') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeRepo(123, 'joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() + * + * @return void + */ + public function testGetTeamMemberships() + { + $this->response->code = 200; + $this->response->body = '{"state":"TEST"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getTeamMembership(123, '{user}'), + $this->equalTo('TEST') + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() + * + * Response if user is not a member + * + * @return void + */ + public function testGetTeamMembershipsFailure1() + { + $this->response->code = 404; + $this->response->body = '{"state":"TEST"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getTeamMembership(123, '{user}'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getTeamMembership() + * + * Unexpected Response + * + * @return void + */ + public function testGetTeamMembershipsFailure2() + { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Unexpected response code: 666'); + + $this->response->code = 666; + $this->response->body = '{"state":"TEST"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getTeamMembership(123, '{user}'), + $this->equalTo('TEST') + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() + * + * @return void + */ + public function testAddTeamMemberships() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->addTeamMembership(123, '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::addTeamMembership() + * + * Invalid role + * + * @return void + */ + public function testAddTeamMembershipsFailure() + { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Roles must be either "member" or "maintainer".'); + + $this->object->addTeamMembership(123, '{user}', 'INVALID'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::removeTeamMembership() + * + * @return void + */ + public function testRemoveTeamMemberships() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/teams/123/memberships/{user}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->removeTeamMembership(123, '{user}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Orgs\Teams::getUserTeams() + * + * @return void + */ + public function testGetUserTeams() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/teams') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getUserTeams(), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/OrgsTest.php b/Tests/Package/OrgsTest.php index 2c992e51..2af4d77d 100644 --- a/Tests/Package/OrgsTest.php +++ b/Tests/Package/OrgsTest.php @@ -16,77 +16,77 @@ */ class OrgsTest extends GitHubTestCase { - /** - * @var Orgs - */ - protected $object; + /** + * @var Orgs + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Orgs($this->options, $this->client); - } + $this->object = new Orgs($this->options, $this->client); + } - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/orgs') - ->will($this->returnValue($this->response)); + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/orgs') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla') - ->will($this->returnValue($this->response)); + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->get('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/orgs/joomla') - ->will($this->returnValue($this->response)); + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/orgs/joomla') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->edit('joomla', 'email@example.com'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->edit('joomla', 'email@example.com'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Pulls/CommentsTest.php b/Tests/Package/Pulls/CommentsTest.php index 0c0e96cf..21bb3ac7 100644 --- a/Tests/Package/Pulls/CommentsTest.php +++ b/Tests/Package/Pulls/CommentsTest.php @@ -18,174 +18,174 @@ */ class CommentsTest extends GitHubTestCase { - /** - * @var Comments - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Comments($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::create() - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - $data = '{"body":"The Body","commit_id":"123abc","path":"a\/b\/c","position":456}'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/1/comments', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 1, 'The Body', '123abc', 'a/b/c', 456), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::createReply() - * - * @return void - */ - public function testCreateReply() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls/1/comments', '{"body":"The Body","in_reply_to":456}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createReply('joomla', 'joomla-platform', 1, 'The Body', 456), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::delete() - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/pulls/comments/456', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 456), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::edit() - * - * @return void - */ - public function testEdit() - { - $this->response->code = 200; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/pulls/comments/456', '{"body":"Hello"}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 456, 'Hello'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/comments/456', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 456), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/456/comments', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', 456), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Pulls\Comments::getListForRepo() - * - * @return void - */ - public function testGetListForRepo() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{user}/{repo}/pulls/comments', [], 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListForRepo('{user}', '{repo}'), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Comments + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Comments($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::create() + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + $data = '{"body":"The Body","commit_id":"123abc","path":"a\/b\/c","position":456}'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/pulls/1/comments', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 1, 'The Body', '123abc', 'a/b/c', 456), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::createReply() + * + * @return void + */ + public function testCreateReply() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/pulls/1/comments', '{"body":"The Body","in_reply_to":456}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->createReply('joomla', 'joomla-platform', 1, 'The Body', 456), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::delete() + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/pulls/comments/456', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 456), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::edit() + * + * @return void + */ + public function testEdit() + { + $this->response->code = 200; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/pulls/comments/456', '{"body":"Hello"}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 456, 'Hello'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/comments/456', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 456), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/456/comments', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', 456), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Pulls\Comments::getListForRepo() + * + * @return void + */ + public function testGetListForRepo() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/pulls/comments', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListForRepo('{user}', '{repo}'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/PullsTest.php b/Tests/Package/PullsTest.php index 11d5bfe0..ed2ae28c 100755 --- a/Tests/Package/PullsTest.php +++ b/Tests/Package/PullsTest.php @@ -16,427 +16,437 @@ */ class JGithubPackagePullsTest extends GitHubTestCase { - /** - * @var Pulls - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Pulls($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $pull = new \stdClass; - $pull->title = 'My Pull Request'; - $pull->base = 'staging'; - $pull->head = 'joomla-jenkins:mychanges'; - $pull->body = 'These are my changes - please review them'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'My Pull Request', 'staging', 'joomla-jenkins:mychanges', - 'These are my changes - please review them' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method - failure - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->title = 'My Pull Request'; - $pull->base = 'staging'; - $pull->head = 'joomla-jenkins:mychanges'; - $pull->body = 'These are my changes - please review them'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->create('joomla', 'joomla-platform', 'My Pull Request', 'staging', 'joomla-jenkins:mychanges', - 'These are my changes - please review them' - ); - } - - /** - * Tests the createFromIssue method - * - * @return void - */ - public function testCreateFromIssue() - { - $this->response->code = 201; - - $pull = new \stdClass; - $pull->issue = 254; - $pull->base = 'staging'; - $pull->head = 'joomla-jenkins:mychanges'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the createFromIssue method - failure - * - * @return void - */ - public function testCreateFromIssueFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->issue = 254; - $pull->base = 'staging'; - $pull->head = 'joomla-jenkins:mychanges'; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $pull = new \stdClass; - $pull->title = 'My Pull Request'; - $pull->body = 'These are my changes - please review them'; - $pull->state = 'Closed'; - $pull->base = 'new'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/pulls/523', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them', 'Closed', 'new'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - failure - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $pull = new \stdClass; - $pull->title = 'My Pull Request'; - $pull->body = 'These are my changes - please review them'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/pulls/523', json_encode($pull)) - ->will($this->returnValue($this->response)); - - $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them'); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - failure - * - * @return void - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 523); - } - - /** - * Tests the getCommits method - * - * @return void - */ - public function testGetCommits() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/commits') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getCommits('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getCommits method - failure - * - * @return void - */ - public function testGetCommitsFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/commits') - ->will($this->returnValue($this->response)); - - $this->object->getCommits('joomla', 'joomla-platform', 523); - } - - /** - * Tests the getFiles method - * - * @return void - */ - public function testGetFiles() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/files') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getFiles('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getFiles method - failure - * - * @return void - */ - public function testGetFilesFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/files') - ->will($this->returnValue($this->response)); - - $this->object->getFiles('joomla', 'joomla-platform', 523); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls?state=closed') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', 'closed'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } - - /** - * Tests the isMerged method when the pull request has been merged - * - * @return void - */ - public function testIsMergedTrue() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isMerged('joomla', 'joomla-platform', 523), - $this->equalTo(true) - ); - } - - /** - * Tests the isMerged method when the pull request has not been merged - * - * @return void - */ - public function testIsMergedFalse() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->isMerged('joomla', 'joomla-platform', 523), - $this->equalTo(false) - ); - } - - /** - * Tests the isMerged method when the request fails - * - * @return void - */ - public function testIsMergedFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 504; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); - - $this->object->isMerged('joomla', 'joomla-platform', 523); - } - - /** - * Tests the merge method - * - * @return void - */ - public function testMerge() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->merge('joomla', 'joomla-platform', 523), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the merge method - failure - * - * @return void - */ - public function testMergeFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/pulls/523/merge') - ->will($this->returnValue($this->response)); - - $this->object->merge('joomla', 'joomla-platform', 523); - } + /** + * @var Pulls + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Pulls($this->options, $this->client); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $pull = new \stdClass(); + $pull->title = 'My Pull Request'; + $pull->base = 'staging'; + $pull->head = 'joomla-jenkins:mychanges'; + $pull->body = 'These are my changes - please review them'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + 'joomla', + 'joomla-platform', + 'My Pull Request', + 'staging', + 'joomla-jenkins:mychanges', + 'These are my changes - please review them' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method - failure + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $pull = new \stdClass(); + $pull->title = 'My Pull Request'; + $pull->base = 'staging'; + $pull->head = 'joomla-jenkins:mychanges'; + $pull->body = 'These are my changes - please review them'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->object->create( + 'joomla', + 'joomla-platform', + 'My Pull Request', + 'staging', + 'joomla-jenkins:mychanges', + 'These are my changes - please review them' + ); + } + + /** + * Tests the createFromIssue method + * + * @return void + */ + public function testCreateFromIssue() + { + $this->response->code = 201; + + $pull = new \stdClass(); + $pull->issue = 254; + $pull->base = 'staging'; + $pull->head = 'joomla-jenkins:mychanges'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the createFromIssue method - failure + * + * @return void + */ + public function testCreateFromIssueFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $pull = new \stdClass(); + $pull->issue = 254; + $pull->base = 'staging'; + $pull->head = 'joomla-jenkins:mychanges'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/pulls', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->object->createFromIssue('joomla', 'joomla-platform', 254, 'staging', 'joomla-jenkins:mychanges'); + } + + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + $pull = new \stdClass(); + $pull->title = 'My Pull Request'; + $pull->body = 'These are my changes - please review them'; + $pull->state = 'Closed'; + $pull->base = 'new'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/pulls/523', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them', 'Closed', 'new'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the edit method - failure + * + * @return void + */ + public function testEditFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $pull = new \stdClass(); + $pull->title = 'My Pull Request'; + $pull->body = 'These are my changes - please review them'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/pulls/523', json_encode($pull)) + ->will($this->returnValue($this->response)); + + $this->object->edit('joomla', 'joomla-platform', 523, 'My Pull Request', 'These are my changes - please review them'); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method - failure + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 523); + } + + /** + * Tests the getCommits method + * + * @return void + */ + public function testGetCommits() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/commits') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getCommits('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getCommits method - failure + * + * @return void + */ + public function testGetCommitsFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/commits') + ->will($this->returnValue($this->response)); + + $this->object->getCommits('joomla', 'joomla-platform', 523); + } + + /** + * Tests the getFiles method + * + * @return void + */ + public function testGetFiles() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/files') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getFiles('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getFiles method - failure + * + * @return void + */ + public function testGetFilesFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/files') + ->will($this->returnValue($this->response)); + + $this->object->getFiles('joomla', 'joomla-platform', 523); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls?state=closed') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', 'closed'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method - failure + * + * @return void + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } + + /** + * Tests the isMerged method when the pull request has been merged + * + * @return void + */ + public function testIsMergedTrue() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/merge') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isMerged('joomla', 'joomla-platform', 523), + $this->equalTo(true) + ); + } + + /** + * Tests the isMerged method when the pull request has not been merged + * + * @return void + */ + public function testIsMergedFalse() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/merge') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->isMerged('joomla', 'joomla-platform', 523), + $this->equalTo(false) + ); + } + + /** + * Tests the isMerged method when the request fails + * + * @return void + */ + public function testIsMergedFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 504; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/pulls/523/merge') + ->will($this->returnValue($this->response)); + + $this->object->isMerged('joomla', 'joomla-platform', 523); + } + + /** + * Tests the merge method + * + * @return void + */ + public function testMerge() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/pulls/523/merge') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->merge('joomla', 'joomla-platform', 523), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the merge method - failure + * + * @return void + */ + public function testMergeFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/pulls/523/merge') + ->will($this->returnValue($this->response)); + + $this->object->merge('joomla', 'joomla-platform', 523); + } } diff --git a/Tests/Package/Repositories/BranchesTest.php b/Tests/Package/Repositories/BranchesTest.php index 51ca67e5..36e36f20 100644 --- a/Tests/Package/Repositories/BranchesTest.php +++ b/Tests/Package/Repositories/BranchesTest.php @@ -18,63 +18,63 @@ */ class BranchesTest extends GitHubTestCase { - /** - * @var Branches - */ - protected $object; + /** + * @var Branches + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Branches($this->options, $this->client); - } + $this->object = new Branches($this->options, $this->client); + } - /** - * Tests the GetList method. - * - * @covers \Joomla\Github\Package\Repositories\Branches::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/branches') - ->will($this->returnValue($this->response)); + /** + * Tests the GetList method. + * + * @covers \Joomla\Github\Package\Repositories\Branches::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/branches') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList('{owner}', '{repo}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getList('{owner}', '{repo}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the Get method. - * - * @covers \Joomla\Github\Package\Repositories\Branches::get() - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/branches/{branch}') - ->will($this->returnValue($this->response)); + /** + * Tests the Get method. + * + * @covers \Joomla\Github\Package\Repositories\Branches::get() + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/branches/{branch}') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get('{owner}', '{repo}', '{branch}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->get('{owner}', '{repo}', '{branch}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/CollaboratorsTest.php b/Tests/Package/Repositories/CollaboratorsTest.php index 045572fb..ad95c77e 100644 --- a/Tests/Package/Repositories/CollaboratorsTest.php +++ b/Tests/Package/Repositories/CollaboratorsTest.php @@ -16,146 +16,146 @@ */ class CollaboratorsTest extends GitHubTestCase { - /** - * @var Collaborators - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Collaborators($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/collaborators') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->response->code = 204; - $this->response->body = true; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the GetNegative method. - * - * @return void - */ - public function testGetNegative() - { - $this->response->code = 404; - $this->response->body = false; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the GetUnexpected method. - * - * @return void - */ - public function testGetUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - $this->response->body = null; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo($this->response->body) - ); - } - - /** - * Tests the Add method. - * - * @return void - */ - public function testAdd() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->add('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Remove method. - * - * @return void - */ - public function testRemove() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-framework/collaborators/elkuku') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->remove('joomla', 'joomla-framework', 'elkuku'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Collaborators + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Collaborators($this->options, $this->client); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/collaborators') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->response->code = 204; + $this->response->body = true; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/collaborators/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-framework', 'elkuku'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the GetNegative method. + * + * @return void + */ + public function testGetNegative() + { + $this->response->code = 404; + $this->response->body = false; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/collaborators/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-framework', 'elkuku'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the GetUnexpected method. + * + * @return void + */ + public function testGetUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + $this->response->body = null; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/collaborators/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-framework', 'elkuku'), + $this->equalTo($this->response->body) + ); + } + + /** + * Tests the Add method. + * + * @return void + */ + public function testAdd() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-framework/collaborators/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->add('joomla', 'joomla-framework', 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Remove method. + * + * @return void + */ + public function testRemove() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-framework/collaborators/elkuku') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->remove('joomla', 'joomla-framework', 'elkuku'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/CommentsTest.php b/Tests/Package/Repositories/CommentsTest.php index ecfada10..72845484 100644 --- a/Tests/Package/Repositories/CommentsTest.php +++ b/Tests/Package/Repositories/CommentsTest.php @@ -16,135 +16,135 @@ */ class CommentsTest extends GitHubTestCase { - /** - * @var Comments - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Comments($this->options, $this->client); - } - - /** - * Tests the GetListRepository method. - * - * @return void - */ - public function testGetListRepository() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListRepository('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/commits/123/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-framework', '123'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/comments/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-framework', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Edit method. - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-framework/comments/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-framework', 123, 'My Comment'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Delete method. - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-framework/comments/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-framework', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-framework/commits/123abc/comments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-framework', '123abc', 'My Comment', 456, 'path/file.php', 789), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Comments + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Comments($this->options, $this->client); + } + + /** + * Tests the GetListRepository method. + * + * @return void + */ + public function testGetListRepository() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/comments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListRepository('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/commits/123/comments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-framework', '123'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/comments/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-framework', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Edit method. + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-framework/comments/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-framework', 123, 'My Comment'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Delete method. + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-framework/comments/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-framework', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-framework/commits/123abc/comments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-framework', '123abc', 'My Comment', 456, 'path/file.php', 789), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/CommitsTest.php b/Tests/Package/Repositories/CommitsTest.php index 50999a97..06caaeb4 100644 --- a/Tests/Package/Repositories/CommitsTest.php +++ b/Tests/Package/Repositories/CommitsTest.php @@ -19,189 +19,189 @@ */ class CommitsTest extends GitHubTestCase { - /** - * @var Commits Object under test. - * @since 12.1 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @return void - * - * @since 1.0 - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Commits($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::get() - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/commits/abc1234') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 'abc1234'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::get() - * - * @return void - * - * @since 1.0 - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - $this->expectExceptionMessage('Generic Error'); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/commits/abc1234') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 'abc1234'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::getList() - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/commits') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::getList() - * - * @return void - * - * @since 1.0 - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - $this->expectExceptionMessage('Generic Error'); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/commits') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::compare() - * - * @return void - * - * @since 1.0 - */ - public function testCompare() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/compare/123abc...456def') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->compare('joomla', 'joomla-platform', '123abc', '456def'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::getSha() - * - * @return void - * - * @since 1.0 - */ - public function testgetSha() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{user}/{repo}/commits/{ref}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getSha('{user}', '{repo}', '{ref}'), - $this->equalTo($this->sampleString) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Commits::getSha() - * - * @return void - * - * @since 1.0 - */ - public function testgetShaFailure() - { - $this->expectException(UnexpectedResponseException::class); - $this->expectExceptionMessage('Invalid response received from GitHub.'); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{user}/{repo}/commits/{ref}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getSha('{user}', '{repo}', '{ref}'), - $this->equalTo($this->sampleString) - ); - } + /** + * @var Commits Object under test. + * @since 12.1 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Commits($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::get() + * + * @return void + * + * @since 1.0 + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/commits/abc1234') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 'abc1234'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::get() + * + * @return void + * + * @since 1.0 + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + $this->expectExceptionMessage('Generic Error'); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/commits/abc1234') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 'abc1234'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getList() + * + * @return void + * + * @since 1.0 + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/commits') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getList() + * + * @return void + * + * @since 1.0 + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + $this->expectExceptionMessage('Generic Error'); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/commits') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::compare() + * + * @return void + * + * @since 1.0 + */ + public function testCompare() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/compare/123abc...456def') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->compare('joomla', 'joomla-platform', '123abc', '456def'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getSha() + * + * @return void + * + * @since 1.0 + */ + public function testgetSha() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/commits/{ref}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getSha('{user}', '{repo}', '{ref}'), + $this->equalTo($this->sampleString) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Commits::getSha() + * + * @return void + * + * @since 1.0 + */ + public function testgetShaFailure() + { + $this->expectException(UnexpectedResponseException::class); + $this->expectExceptionMessage('Invalid response received from GitHub.'); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/commits/{ref}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getSha('{user}', '{repo}', '{ref}'), + $this->equalTo($this->sampleString) + ); + } } diff --git a/Tests/Package/Repositories/ContentsTest.php b/Tests/Package/Repositories/ContentsTest.php index b95917b2..41f8259c 100644 --- a/Tests/Package/Repositories/ContentsTest.php +++ b/Tests/Package/Repositories/ContentsTest.php @@ -16,304 +16,379 @@ */ class ContentsTest extends GitHubTestCase { - /** - * @var Contents - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Contents($this->options, $this->client); - } - - /** - * Tests the GetReadme method. - * - * @return void - */ - public function testGetReadme() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/readme') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getReadme('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetReadmeRef method. - * - * @return void - */ - public function testGetReadmeRef() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/readme?ref=123abc') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getReadme('joomla', 'joomla-platform', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/contents/path/to/file.php') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 'path/to/file.php'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetRef method. - * - * @return void - */ - public function testGetRef() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/contents/path/to/file.php?ref=123abc') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 'path/to/file.php', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetArchiveLink method. - * - * @return void - */ - public function testGetArchiveLink() - { - $this->response->code = 302; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/zipball') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getArchiveLink('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetArchiveLinkRef method. - * - * @return void - */ - public function testGetArchiveLinkRef() - { - $this->response->code = 302; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/zipball?ref=123abc') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getArchiveLink('joomla', 'joomla-platform', 'zipball', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetArchiveLinkInvalidFormat method. - * - * @return void - */ - public function testGetArchiveLinkInvalidFormat() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 302; - - $this->object->getArchiveLink('joomla', 'joomla-platform', 'invalid'); - } - - /** - * Tests the create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/contents/src/foo') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method with missing author e-mail. - * - * @return void - */ - public function testCreateFail1() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->create( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', '', 'elkuku', 'elkuku@example.com' - ); - } - - /** - * Tests the create method with missing committer e-mail. - * - * @return void - */ - public function testCreateFail2() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->create( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', '' - ); - } - - /** - * Tests the update method. - * - * @return void - */ - public function testUpdate() - { - $this->client->expects($this->once()) - ->method('put') - ->with('/repos/joomla/joomla-platform/contents/src/foo') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->update( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the update method with missing author e-mail. - * - * @return void - */ - public function testUpdateFail1() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->update( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', - 'eddieajau', '', 'elkuku', 'elkuku@example.com' - ); - } - - /** - * Tests the update method with missing committer e-mail. - * - * @return void - */ - public function testUpdateFail2() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->update( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'abcd1234', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', '' - ); - } - - /** - * Tests the delete method. - * - * @return void - */ - public function testDelete() - { - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/contents/src/foo') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', 'elkuku@example.com' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the delete method with missing author e-mail. - * - * @return void - */ - public function testDeleteFail1() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->delete( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', '', 'elkuku', 'elkuku@example.com' - ); - } - - /** - * Tests the update method with missing committer e-mail. - * - * @return void - */ - public function testDeleteFail2() - { - $this->expectException(\UnexpectedValueException::class); - - $this->object->delete( - 'joomla', 'joomla-platform', 'src/foo', 'my Message', 'ABC123def', 'xxbranch', - 'eddieajau', 'eddieajau@example.com', 'elkuku', '' - ); - } + /** + * @var Contents + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Contents($this->options, $this->client); + } + + /** + * Tests the GetReadme method. + * + * @return void + */ + public function testGetReadme() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/readme') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getReadme('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetReadmeRef method. + * + * @return void + */ + public function testGetReadmeRef() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/readme?ref=123abc') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getReadme('joomla', 'joomla-platform', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/contents/path/to/file.php') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 'path/to/file.php'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetRef method. + * + * @return void + */ + public function testGetRef() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/contents/path/to/file.php?ref=123abc') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 'path/to/file.php', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetArchiveLink method. + * + * @return void + */ + public function testGetArchiveLink() + { + $this->response->code = 302; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/zipball') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getArchiveLink('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetArchiveLinkRef method. + * + * @return void + */ + public function testGetArchiveLinkRef() + { + $this->response->code = 302; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/zipball?ref=123abc') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getArchiveLink('joomla', 'joomla-platform', 'zipball', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetArchiveLinkInvalidFormat method. + * + * @return void + */ + public function testGetArchiveLinkInvalidFormat() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 302; + + $this->object->getArchiveLink('joomla', 'joomla-platform', 'invalid'); + } + + /** + * Tests the create method. + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/contents/src/foo') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + 'elkuku@example.com' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method with missing author e-mail. + * + * @return void + */ + public function testCreateFail1() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->create( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + '', + 'elkuku', + 'elkuku@example.com' + ); + } + + /** + * Tests the create method with missing committer e-mail. + * + * @return void + */ + public function testCreateFail2() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->create( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + '' + ); + } + + /** + * Tests the update method. + * + * @return void + */ + public function testUpdate() + { + $this->client->expects($this->once()) + ->method('put') + ->with('/repos/joomla/joomla-platform/contents/src/foo') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->update( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'abcd1234', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + 'elkuku@example.com' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the update method with missing author e-mail. + * + * @return void + */ + public function testUpdateFail1() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->update( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'abcd1234', + 'xxbranch', + 'eddieajau', + '', + 'elkuku', + 'elkuku@example.com' + ); + } + + /** + * Tests the update method with missing committer e-mail. + * + * @return void + */ + public function testUpdateFail2() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->update( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'abcd1234', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + '' + ); + } + + /** + * Tests the delete method. + * + * @return void + */ + public function testDelete() + { + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/contents/src/foo') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + 'elkuku@example.com' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the delete method with missing author e-mail. + * + * @return void + */ + public function testDeleteFail1() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->delete( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + '', + 'elkuku', + 'elkuku@example.com' + ); + } + + /** + * Tests the update method with missing committer e-mail. + * + * @return void + */ + public function testDeleteFail2() + { + $this->expectException(\UnexpectedValueException::class); + + $this->object->delete( + 'joomla', + 'joomla-platform', + 'src/foo', + 'my Message', + 'ABC123def', + 'xxbranch', + 'eddieajau', + 'eddieajau@example.com', + 'elkuku', + '' + ); + } } diff --git a/Tests/Package/Repositories/DeploymentsTest.php b/Tests/Package/Repositories/DeploymentsTest.php index eccf027f..9f384fa9 100644 --- a/Tests/Package/Repositories/DeploymentsTest.php +++ b/Tests/Package/Repositories/DeploymentsTest.php @@ -16,158 +16,165 @@ */ class DeploymentsTest extends GitHubTestCase { - /** - * @var Deployments - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Deployments($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/deployments?sha={sha}&ref={ref}&task={task}&environment={environment}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('{owner}', '{repo}', '{sha}', '{ref}', '{task}', '{environment}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{owner}/{repo}/deployments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create( - '{owner}', '{repo}', '{ref}', '{task}', '{automerge}', array('{requiredContexts}'), - '{payload}', '{environment}', '{description}' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreateMergeConflict() - { - $this->expectException(\RuntimeException::class); - - $this->response->code = 409; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{owner}/{repo}/deployments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('{owner}', '{repo}', '{ref}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{owner}/{repo}/deployments') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('{owner}', '{repo}', '{ref}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the GetDeploymentStatuses method. - * - * @return void - */ - public function testGetDeploymentStatuses() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/deployments/123/statuses') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getDeploymentStatuses('{owner}', '{repo}', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the CreateStatus method. - * - * @return void - */ - public function testCreateStatus() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{owner}/{repo}/deployments/123/statuses') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->createStatus('{owner}', '{repo}', 123, 'success', '{targetUrl}', '{description}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the CreateStatus method. - * - * @return void - */ - public function testCreateStatusFailure() - { - $this->expectException(\InvalidArgumentException::class); - - $this->object->createStatus('{owner}', '{repo}', 123, '{invalid}'); - } + /** + * @var Deployments + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Deployments($this->options, $this->client); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/deployments?sha={sha}&ref={ref}&task={task}&environment={environment}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('{owner}', '{repo}', '{sha}', '{ref}', '{task}', '{environment}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{owner}/{repo}/deployments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + '{owner}', + '{repo}', + '{ref}', + '{task}', + '{automerge}', + ['{requiredContexts}'], + '{payload}', + '{environment}', + '{description}' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreateMergeConflict() + { + $this->expectException(\RuntimeException::class); + + $this->response->code = 409; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{owner}/{repo}/deployments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('{owner}', '{repo}', '{ref}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{owner}/{repo}/deployments') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('{owner}', '{repo}', '{ref}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the GetDeploymentStatuses method. + * + * @return void + */ + public function testGetDeploymentStatuses() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/deployments/123/statuses') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getDeploymentStatuses('{owner}', '{repo}', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the CreateStatus method. + * + * @return void + */ + public function testCreateStatus() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{owner}/{repo}/deployments/123/statuses') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->createStatus('{owner}', '{repo}', 123, 'success', '{targetUrl}', '{description}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the CreateStatus method. + * + * @return void + */ + public function testCreateStatusFailure() + { + $this->expectException(\InvalidArgumentException::class); + + $this->object->createStatus('{owner}', '{repo}', 123, '{invalid}'); + } } diff --git a/Tests/Package/Repositories/DownloadsTest.php b/Tests/Package/Repositories/DownloadsTest.php index 953f8511..0495fe53 100644 --- a/Tests/Package/Repositories/DownloadsTest.php +++ b/Tests/Package/Repositories/DownloadsTest.php @@ -16,107 +16,118 @@ */ class DownloadsTest extends GitHubTestCase { - /** - * @var Downloads - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Downloads($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/downloads') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/downloads/123abc') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); - - $this->object->create('joomla', 'joomla-platform', 'aaa.zip', 1234, 'Description', 'content_type'); - } - - /** - * Tests the Upload method. - * - * @return void - */ - public function testUpload() - { - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); - - $this->object->upload( - 'joomla', 'joomla-platform', 123, 'a/b/aaa.zip', 'acl', 201, 'aaa.zip', '123abc', '123abc', '123abc', 'content_type', '@aaa.zip' - ); - } - - /** - * Tests the Delete method. - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/downloads/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 123), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Downloads + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Downloads($this->options, $this->client); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/downloads') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/downloads/123abc') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreate() + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); + + $this->object->create('joomla', 'joomla-platform', 'aaa.zip', 1234, 'Description', 'content_type'); + } + + /** + * Tests the Upload method. + * + * @return void + */ + public function testUpload() + { + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); + + $this->object->upload( + 'joomla', + 'joomla-platform', + 123, + 'a/b/aaa.zip', + 'acl', + 201, + 'aaa.zip', + '123abc', + '123abc', + '123abc', + 'content_type', + '@aaa.zip' + ); + } + + /** + * Tests the Delete method. + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/downloads/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 123), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/ForksTest.php b/Tests/Package/Repositories/ForksTest.php index 255c5ef1..72cb94a2 100755 --- a/Tests/Package/Repositories/ForksTest.php +++ b/Tests/Package/Repositories/ForksTest.php @@ -16,114 +16,114 @@ */ class ForksTest extends GitHubTestCase { - /** - * @var Forks Object under test. - * @since 11.4 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Forks($this->options, $this->client); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 202; - - // Build the request data. - $data = json_encode( - array( - 'org' => 'jenkins-jools' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/forks', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'jenkins-jools'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method - failure - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array() - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/forks', $data) - ->will($this->returnValue($this->response)); - - $this->object->create('joomla', 'joomla-platform', ''); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/forks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getList method - failure - * - * @return void - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/forks') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } + /** + * @var Forks Object under test. + * @since 11.4 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Forks($this->options, $this->client); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 202; + + // Build the request data. + $data = json_encode( + [ + 'org' => 'jenkins-jools', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/forks', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'jenkins-jools'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method - failure + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + [] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/forks', $data) + ->will($this->returnValue($this->response)); + + $this->object->create('joomla', 'joomla-platform', ''); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/forks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getList method - failure + * + * @return void + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/forks') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } } diff --git a/Tests/Package/Repositories/HooksTest.php b/Tests/Package/Repositories/HooksTest.php index 83f8b6af..a2257afd 100644 --- a/Tests/Package/Repositories/HooksTest.php +++ b/Tests/Package/Repositories/HooksTest.php @@ -18,482 +18,494 @@ */ class HooksTest extends GitHubTestCase { - /** - * @var Hooks Object under test. - * @since 12.3 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @return void - * - * @since 1.0 - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Hooks($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::create() - * - * @return void - * - * @since 1.0 - */ - public function testCreate() - { - $this->response->code = 201; - - $hook = new \stdClass; - $hook->name = 'acunote'; - $hook->config = array('token' => '123456789'); - $hook->events = array('push', 'public'); - $hook->active = true; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/hooks', json_encode($hook)) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'acunote', array('token' => '123456789'), array('push', 'public')), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::create() - * - * @return void - * - * @since 1.0 - */ - public function testCreateFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $hook = new \stdClass; - $hook->name = 'acunote'; - $hook->config = array('token' => '123456789'); - $hook->events = array('push', 'public'); - $hook->active = true; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/hooks', json_encode($hook)) - ->will($this->returnValue($this->response)); - - try - { - $this->object->create('joomla', 'joomla-platform', 'acunote', array('token' => '123456789'), array('push', 'public')); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::create() - * - * Unauthorised event - * - * @return void - * - * @since 1.0 - */ - public function testCreateUnauthorisedEvent() - { - $this->expectException(\RuntimeException::class); - - $this->object->create('joomla', 'joomla-platform', 'acunote', array('token' => '123456789'), array('push', 'faker')); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::delete() - * - * @return void - * - * @since 1.0 - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::delete() - * - * Simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testDeleteFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); - - try - { - $this->object->delete('joomla', 'joomla-platform', 42); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::edit() - * - * @return void - * - * @since 1.0 - */ - public function testEdit() - { - $hook = '{' - . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' - . '"add_events":["watch"],"remove_events":["watch"],"active":true' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/hooks/42', $hook) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), - array('push', 'public'), array('watch'), array('watch') - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::edit() - * - * Simulated failure - * - * @return void - * - * @since 1.0 - */ - public function testEditFailure() - { - $exception = false; - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $hook = '{' - . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' - . '"add_events":["watch"],"remove_events":["watch"],"active":true' - . '}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/hooks/42', $hook) - ->will($this->returnValue($this->response)); - - try - { - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), - array('push', 'public'), array('watch'), array('watch') - ); - } - catch (\DomainException $e) - { - $exception = true; - - $this->assertThat( - $e->getMessage(), - $this->equalTo(json_decode($this->errorString)->message) - ); - } - - $this->assertTrue($exception); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::edit() - * - * Unauthorised event - * - * @return void - * - * @since 1.0 - */ - public function testEditUnauthorisedEvent() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('invalid')); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::edit() - * - * Unauthorised event - * - * @return void - * - * @since 1.0 - */ - public function testEditUnauthorisedAddEvent() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('push'), array('invalid')); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::edit() - * - * Unauthorised event - * - * @return void - * - * @since 1.0 - */ - public function testEditUnauthorisedRemoveEvent() - { - $this->expectException(\RuntimeException::class); - - $this->object->edit( - 'joomla', 'joomla-platform', 42, 'acunote', array('token' => '123456789'), array('push'), array('push'), array('invalid') - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::get() - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::get() - * - * Failure - * - * @return void - * - * @since 1.0 - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/hooks/42') - ->will($this->returnValue($this->response)); - - $this->object->get('joomla', 'joomla-platform', 42); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::getList() - * - * @return void - * - * @since 1.0 - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/hooks') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::getList() - * - * Failure - * - * @return void - * - * @since 1.0 - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/hooks') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::test() - * - * @return void - * - * @since 1.0 - */ - public function testTest() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/hooks/42/test') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->test('joomla', 'joomla-platform', 42), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::test() - * - * Failure - * - * @return void - * - * @since 1.0 - */ - public function testTestFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/hooks/42/test') - ->will($this->returnValue($this->response)); - - $this->object->test('joomla', 'joomla-platform', 42); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Hooks::ping() - * - * @return void - * - * @since 1.0 - */ - public function testPing() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/{user}/{repo}/hooks/42/pings') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->ping('{user}', '{repo}', 42), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Hooks Object under test. + * @since 12.3 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Hooks($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::create() + * + * @return void + * + * @since 1.0 + */ + public function testCreate() + { + $this->response->code = 201; + + $hook = new \stdClass(); + $hook->name = 'acunote'; + $hook->config = ['token' => '123456789']; + $hook->events = ['push', 'public']; + $hook->active = true; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/hooks', json_encode($hook)) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'acunote', ['token' => '123456789'], ['push', 'public']), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::create() + * + * @return void + * + * @since 1.0 + */ + public function testCreateFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $hook = new \stdClass(); + $hook->name = 'acunote'; + $hook->config = ['token' => '123456789']; + $hook->events = ['push', 'public']; + $hook->active = true; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/hooks', json_encode($hook)) + ->will($this->returnValue($this->response)); + + try { + $this->object->create('joomla', 'joomla-platform', 'acunote', ['token' => '123456789'], ['push', 'public']); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::create() + * + * Unauthorised event + * + * @return void + * + * @since 1.0 + */ + public function testCreateUnauthorisedEvent() + { + $this->expectException(\RuntimeException::class); + + $this->object->create('joomla', 'joomla-platform', 'acunote', ['token' => '123456789'], ['push', 'faker']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::delete() + * + * @return void + * + * @since 1.0 + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/hooks/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::delete() + * + * Simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testDeleteFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/hooks/42') + ->will($this->returnValue($this->response)); + + try { + $this->object->delete('joomla', 'joomla-platform', 42); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * @return void + * + * @since 1.0 + */ + public function testEdit() + { + $hook = '{' + . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' + . '"add_events":["watch"],"remove_events":["watch"],"active":true' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/hooks/42', $hook) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit( + 'joomla', + 'joomla-platform', + 42, + 'acunote', + ['token' => '123456789'], + ['push', 'public'], + ['watch'], + ['watch'] + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Simulated failure + * + * @return void + * + * @since 1.0 + */ + public function testEditFailure() + { + $exception = false; + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $hook = '{' + . '"name":"acunote","config":{"token":"123456789"},"events":["push","public"],' + . '"add_events":["watch"],"remove_events":["watch"],"active":true' + . '}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/hooks/42', $hook) + ->will($this->returnValue($this->response)); + + try { + $this->object->edit( + 'joomla', + 'joomla-platform', + 42, + 'acunote', + ['token' => '123456789'], + ['push', 'public'], + ['watch'], + ['watch'] + ); + } catch (\DomainException $e) { + $exception = true; + + $this->assertThat( + $e->getMessage(), + $this->equalTo(json_decode($this->errorString)->message) + ); + } + + $this->assertTrue($exception); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Unauthorised event + * + * @return void + * + * @since 1.0 + */ + public function testEditUnauthorisedEvent() + { + $this->expectException(\RuntimeException::class); + + $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', ['token' => '123456789'], ['invalid']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Unauthorised event + * + * @return void + * + * @since 1.0 + */ + public function testEditUnauthorisedAddEvent() + { + $this->expectException(\RuntimeException::class); + + $this->object->edit('joomla', 'joomla-platform', 42, 'acunote', ['token' => '123456789'], ['push'], ['invalid']); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::edit() + * + * Unauthorised event + * + * @return void + * + * @since 1.0 + */ + public function testEditUnauthorisedRemoveEvent() + { + $this->expectException(\RuntimeException::class); + + $this->object->edit( + 'joomla', + 'joomla-platform', + 42, + 'acunote', + ['token' => '123456789'], + ['push'], + ['push'], + ['invalid'] + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::get() + * + * @return void + * + * @since 1.0 + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/hooks/42') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::get() + * + * Failure + * + * @return void + * + * @since 1.0 + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/hooks/42') + ->will($this->returnValue($this->response)); + + $this->object->get('joomla', 'joomla-platform', 42); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::getList() + * + * @return void + * + * @since 1.0 + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/hooks') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::getList() + * + * Failure + * + * @return void + * + * @since 1.0 + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/hooks') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::test() + * + * @return void + * + * @since 1.0 + */ + public function testTest() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/hooks/42/test') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->test('joomla', 'joomla-platform', 42), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::test() + * + * Failure + * + * @return void + * + * @since 1.0 + */ + public function testTestFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/hooks/42/test') + ->will($this->returnValue($this->response)); + + $this->object->test('joomla', 'joomla-platform', 42); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Hooks::ping() + * + * @return void + * + * @since 1.0 + */ + public function testPing() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/{user}/{repo}/hooks/42/pings') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->ping('{user}', '{repo}', 42), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/KeysTest.php b/Tests/Package/Repositories/KeysTest.php index eb3e5cba..f4303d49 100644 --- a/Tests/Package/Repositories/KeysTest.php +++ b/Tests/Package/Repositories/KeysTest.php @@ -16,118 +16,118 @@ */ class KeysTest extends GitHubTestCase { - /** - * @var Keys - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Keys($this->options, $this->client); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/keys') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', 1), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/keys') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', 'email@example.com', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Edit method. - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', 1, 'email@example.com', '123abc'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Delete method. - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - $this->response->body = true; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', 1), - $this->equalTo($this->response->body) - ); - } + /** + * @var Keys + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Keys($this->options, $this->client); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/keys') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', 1), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/keys') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', 'email@example.com', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Edit method. + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', 1, 'email@example.com', '123abc'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Delete method. + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + $this->response->body = true; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', 1), + $this->equalTo($this->response->body) + ); + } } diff --git a/Tests/Package/Repositories/MergingTest.php b/Tests/Package/Repositories/MergingTest.php index 128535da..282441d9 100644 --- a/Tests/Package/Repositories/MergingTest.php +++ b/Tests/Package/Repositories/MergingTest.php @@ -16,132 +16,132 @@ */ class MergingTest extends GitHubTestCase { - /** - * @var Merging - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Merging($this->options, $this->client); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerform() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerformNoOp() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerformMissing() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerformConflict() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 409; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the Perform method. - * - * @return void - */ - public function testPerformUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/merges') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Merging + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Merging($this->options, $this->client); + } + + /** + * Tests the Perform method. + * + * @return void + */ + public function testPerform() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/merges') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Perform method. + * + * @return void + */ + public function testPerformNoOp() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/merges') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Perform method. + * + * @return void + */ + public function testPerformMissing() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/merges') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Perform method. + * + * @return void + */ + public function testPerformConflict() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 409; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/merges') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the Perform method. + * + * @return void + */ + public function testPerformUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/merges') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->perform('joomla', 'joomla-platform', '123', '456', 'My Message'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/PagesTest.php b/Tests/Package/Repositories/PagesTest.php index 242de302..e723d41d 100644 --- a/Tests/Package/Repositories/PagesTest.php +++ b/Tests/Package/Repositories/PagesTest.php @@ -16,77 +16,77 @@ */ class PagesTest extends GitHubTestCase { - /** - * @var Pages - */ - protected $object; + /** + * @var Pages + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Pages($this->options, $this->client); - } + $this->object = new Pages($this->options, $this->client); + } - /** - * Tests the GetInfo method. - * - * @return void - */ - public function testGetInfo() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/pages') - ->will($this->returnValue($this->response)); + /** + * Tests the GetInfo method. + * + * @return void + */ + public function testGetInfo() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/pages') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getInfo('{owner}', '{repo}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getInfo('{owner}', '{repo}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/pages/builds') - ->will($this->returnValue($this->response)); + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/pages/builds') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList('{owner}', '{repo}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getList('{owner}', '{repo}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the GetLatest method. - * - * @return void - */ - public function testGetLatest() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{owner}/{repo}/pages/builds/latest') - ->will($this->returnValue($this->response)); + /** + * Tests the GetLatest method. + * + * @return void + */ + public function testGetLatest() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{owner}/{repo}/pages/builds/latest') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getLatest('{owner}', '{repo}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getLatest('{owner}', '{repo}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/ReleasesTest.php b/Tests/Package/Repositories/ReleasesTest.php index 9d4c27e7..ddd596c8 100644 --- a/Tests/Package/Repositories/ReleasesTest.php +++ b/Tests/Package/Repositories/ReleasesTest.php @@ -16,272 +16,271 @@ */ class ReleasesTest extends GitHubTestCase { - /** - * @var Releases Object under test. - * @since 1.0 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Releases($this->options, $this->client); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases/12345', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-platform', '12345'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $data = '{"tag_name":"0.1","target_commitish":"targetCommitish","name":"master","body":"New release","draft":false,"prerelease":false}'; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/releases', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the create method with failure. - * - * @return void - */ - public function testCreateFailure() - { - $this->response->code = 201; - - $data = '{"tag_name":"0.1","target_commitish":"targetCommitish","name":"master","body":"New release","draft":false,"prerelease":false}'; - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/releases', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the edit method. - * - * @return void - */ - public function testEdit() - { - $releaseId = 123; - - $data = '{"tag_name":"tagName","target_commitish":"targetCommitish","name":"name","body":"body","draft":"draft","prerelease":"preRelease"}'; - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/releases/' . $releaseId, $data, array(), 0) - - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-platform', $releaseId, 'tagName', 'targetCommitish', 'name', 'body', 'draft', 'preRelease'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getList method. - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = '[{"tag_name":"1"},{"tag_name":"2"}]'; - - $releases = array(); - - foreach (json_decode($this->response->body) as $i => $release) - { - $releases[$i + 1] = $release; - } - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform'), - $this->equalTo($releases) - ); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/releases/123') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-platform', '123'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getLatest method. - * - * @return void - */ - public function testGetLatest() - { - $this->response->code = 200; - $this->response->body = '[]'; - - $releases = array(); - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases/latest', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getLatest('joomla', 'joomla-platform'), - $this->equalTo($releases) - ); - } - - /** - * Tests the getByTag method - * - * @return void - */ - public function testGetByTag() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases/tags/{tag}', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getByTag('joomla', 'joomla-platform', '{tag}'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getListAssets method - * - * @return void - */ - public function testGetListAssets() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases/123/assets', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListAssets('joomla', 'joomla-platform', 123), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getAsset method - * - * @return void - */ - public function testGetAsset() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/releases/assets/123', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getAsset('joomla', 'joomla-platform', 123), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the editAsset method - * - * @return void - */ - public function testEditAsset() - { - $data = '{"name":"{name}","label":"{label}"}'; - - $this->client->expects($this->once()) - ->method('patch') - ->with('/repos/joomla/joomla-platform/releases/assets/123', $data, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->editAsset('joomla', 'joomla-platform', 123, '{name}', '{label}'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the deleteAsset method - * - * @return void - */ - public function testDeleteAsset() - { - $this->response->code = 204; - $this->response->body = true; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-platform/releases/assets/123', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->deleteAsset('joomla', 'joomla-platform', 123), - $this->equalTo($this->response->body) - ); - } + /** + * @var Releases Object under test. + * @since 1.0 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Releases($this->options, $this->client); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases/12345', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-platform', '12345'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $data = '{"tag_name":"0.1","target_commitish":"targetCommitish","name":"master","body":"New release","draft":false,"prerelease":false}'; + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/releases', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the create method with failure. + * + * @return void + */ + public function testCreateFailure() + { + $this->response->code = 201; + + $data = '{"tag_name":"0.1","target_commitish":"targetCommitish","name":"master","body":"New release","draft":false,"prerelease":false}'; + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/releases', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla', 'joomla-platform', '0.1', 'targetCommitish', 'master', 'New release', false, false), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the edit method. + * + * @return void + */ + public function testEdit() + { + $releaseId = 123; + + $data = '{"tag_name":"tagName","target_commitish":"targetCommitish","name":"name","body":"body","draft":"draft","prerelease":"preRelease"}'; + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/releases/' . $releaseId, $data, [], 0) + + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-platform', $releaseId, 'tagName', 'targetCommitish', 'name', 'body', 'draft', 'preRelease'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getList method. + * + * @return void + */ + public function testGetList() + { + $this->response->code = 200; + $this->response->body = '[{"tag_name":"1"},{"tag_name":"2"}]'; + + $releases = []; + + foreach (json_decode($this->response->body) as $i => $release) { + $releases[$i + 1] = $release; + } + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform'), + $this->equalTo($releases) + ); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/releases/123') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-platform', '123'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getLatest method. + * + * @return void + */ + public function testGetLatest() + { + $this->response->code = 200; + $this->response->body = '[]'; + + $releases = []; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases/latest', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getLatest('joomla', 'joomla-platform'), + $this->equalTo($releases) + ); + } + + /** + * Tests the getByTag method + * + * @return void + */ + public function testGetByTag() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases/tags/{tag}', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getByTag('joomla', 'joomla-platform', '{tag}'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getListAssets method + * + * @return void + */ + public function testGetListAssets() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases/123/assets', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListAssets('joomla', 'joomla-platform', 123), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getAsset method + * + * @return void + */ + public function testGetAsset() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/releases/assets/123', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getAsset('joomla', 'joomla-platform', 123), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the editAsset method + * + * @return void + */ + public function testEditAsset() + { + $data = '{"name":"{name}","label":"{label}"}'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/releases/assets/123', $data, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->editAsset('joomla', 'joomla-platform', 123, '{name}', '{label}'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the deleteAsset method + * + * @return void + */ + public function testDeleteAsset() + { + $this->response->code = 204; + $this->response->body = true; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/releases/assets/123', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->deleteAsset('joomla', 'joomla-platform', 123), + $this->equalTo($this->response->body) + ); + } } diff --git a/Tests/Package/Repositories/StatisticsTest.php b/Tests/Package/Repositories/StatisticsTest.php index c4baa718..4aefac24 100644 --- a/Tests/Package/Repositories/StatisticsTest.php +++ b/Tests/Package/Repositories/StatisticsTest.php @@ -16,136 +16,136 @@ */ class StatisticsTest extends GitHubTestCase { - /** - * @var Statistics Object under test. - * @since 11.4 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Statistics($this->options, $this->client); - } - - /** - * Tests the getListContributors method. - * - * @return void - */ - public function testContributors() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/contributors') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListContributors('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getActivityData method. - * - * @return void - */ - public function testActivity() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/commit_activity') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getActivityData('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getCodeFrequency method. - * - * @return void - */ - public function testFrequency() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/code_frequency') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getCodeFrequency('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getParticipation method. - * - * @return void - */ - public function testParticipation() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/participation') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getParticipation('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getPunchCard method. - * - * @return void - */ - public function testPunchCard() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/punch_card') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getPunchCard('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the ProcessResponse method with failure. - * - * @return void - */ - public function testProcessResponse202() - { - $this->expectException(\DomainException::class); - - $this->response->code = 202; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-framework/stats/punch_card') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getPunchCard('joomla', 'joomla-framework'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Statistics Object under test. + * @since 11.4 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Statistics($this->options, $this->client); + } + + /** + * Tests the getListContributors method. + * + * @return void + */ + public function testContributors() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/contributors') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListContributors('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getActivityData method. + * + * @return void + */ + public function testActivity() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/commit_activity') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getActivityData('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getCodeFrequency method. + * + * @return void + */ + public function testFrequency() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/code_frequency') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getCodeFrequency('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getParticipation method. + * + * @return void + */ + public function testParticipation() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/participation') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getParticipation('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getPunchCard method. + * + * @return void + */ + public function testPunchCard() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/punch_card') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getPunchCard('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the ProcessResponse method with failure. + * + * @return void + */ + public function testProcessResponse202() + { + $this->expectException(\DomainException::class); + + $this->response->code = 202; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-framework/stats/punch_card') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getPunchCard('joomla', 'joomla-framework'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Repositories/StatusesTest.php b/Tests/Package/Repositories/StatusesTest.php index 02e6d16d..d51a6b73 100755 --- a/Tests/Package/Repositories/StatusesTest.php +++ b/Tests/Package/Repositories/StatusesTest.php @@ -18,180 +18,180 @@ */ class StatusesTest extends GitHubTestCase { - /** - * @var Statuses Object under test. - * @since 11.4 - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Statuses($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::create() - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - // Build the request data. - $data = json_encode( - array( - 'state' => 'success', - 'target_url' => 'http://example.com/my_url', - 'description' => 'Success is the only option - failure is not.', - 'context' => 'Joomla/Test' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e', $data) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create( - 'joomla', - 'joomla-platform', - '6dcb09b5b57875f334f61aebed695e2e4193db5e', - 'success', - 'http://example.com/my_url', - 'Success is the only option - failure is not.', - 'Joomla/Test' - ), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::create() - * - * Failure - * - * @return void - */ - public function testCreateFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - // Build the request data. - $data = json_encode( - array( - 'state' => 'pending' - ) - ); - - $this->client->expects($this->once()) - ->method('post') - ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e', $data) - ->will($this->returnValue($this->response)); - - $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'pending'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::create() - * - * Failure - * - * @return void - */ - public function testCreateInvalidState() - { - $this->expectException(\InvalidArgumentException::class); - - $this->response->code = 501; - $this->response->body = $this->errorString; - - $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'INVALID'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::getList() - * - * Failure - * - * @return void - */ - public function testGetListFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 500; - $this->response->body = $this->errorString; - - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') - ->will($this->returnValue($this->response)); - - $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Repositories\Statuses::getCombinedStatus() - * - * @return void - * - * @since 1.0 - */ - public function testGetCombinedStatus() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/{user}/{repo}/commits/{sha}/status') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getCombinedStatus('{user}', '{repo}', '{sha}'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Statuses Object under test. + * @since 11.4 + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Statuses($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::create() + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + // Build the request data. + $data = json_encode( + [ + 'state' => 'success', + 'target_url' => 'http://example.com/my_url', + 'description' => 'Success is the only option - failure is not.', + 'context' => 'Joomla/Test', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e', $data) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create( + 'joomla', + 'joomla-platform', + '6dcb09b5b57875f334f61aebed695e2e4193db5e', + 'success', + 'http://example.com/my_url', + 'Success is the only option - failure is not.', + 'Joomla/Test' + ), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::create() + * + * Failure + * + * @return void + */ + public function testCreateFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + // Build the request data. + $data = json_encode( + [ + 'state' => 'pending', + ] + ); + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e', $data) + ->will($this->returnValue($this->response)); + + $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'pending'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::create() + * + * Failure + * + * @return void + */ + public function testCreateInvalidState() + { + $this->expectException(\InvalidArgumentException::class); + + $this->response->code = 501; + $this->response->body = $this->errorString; + + $this->object->create('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e', 'INVALID'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::getList() + * + * Failure + * + * @return void + */ + public function testGetListFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 500; + $this->response->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/statuses/6dcb09b5b57875f334f61aebed695e2e4193db5e') + ->will($this->returnValue($this->response)); + + $this->object->getList('joomla', 'joomla-platform', '6dcb09b5b57875f334f61aebed695e2e4193db5e'); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Repositories\Statuses::getCombinedStatus() + * + * @return void + * + * @since 1.0 + */ + public function testGetCombinedStatus() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/{user}/{repo}/commits/{sha}/status') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getCombinedStatus('{user}', '{repo}', '{sha}'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/RepositoriesTest.php b/Tests/Package/RepositoriesTest.php index a392afa4..667d5f0c 100644 --- a/Tests/Package/RepositoriesTest.php +++ b/Tests/Package/RepositoriesTest.php @@ -16,358 +16,362 @@ */ class RepositoriesTest extends GitHubTestCase { - /** - * @var Repositories - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Repositories($this->options, $this->client); - } - - /** - * Tests the GetListOwn method. - * - * @return void - */ - public function testGetListOwn() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/repos?type=all&sort=full_name&direction=asc', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListOwn(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListOwn method. - * - * @return void - */ - public function testGetListOwnInvalidType() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListOwn('INVALID'); - } - - /** - * Tests the GetListOwn method. - * - * @return void - */ - public function testGetListOwnInvalidSortField() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListOwn('all', 'INVALID'); - } - - /** - * Tests the GetListOwn method. - * - * @return void - */ - public function testGetListOwnInvalidSortOrder() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListOwn('all', 'full_name', 'INVALID'); - } - - /** - * Tests the GetListUser method. - * - * @return void - */ - public function testGetListUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/repos?type=all&sort=full_name&direction=asc', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListUser('joomla'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListUser method. - * - * @return void - */ - public function testGetListUserInvalidType() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListUser('joomla', 'INVALID'); - } - - /** - * Tests the GetListUser method. - * - * @return void - */ - public function testGetListUserInvalidSortField() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListUser('joomla', 'all', 'INVALID'); - } - - /** - * Tests the GetListUser method. - * - * @return void - */ - public function testGetListUserInvalidSortOrder() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListUser('joomla', 'all', 'full_name', 'INVALID'); - } - - /** - * Tests the GetListOrg method. - * - * @return void - */ - public function testGetListOrg() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/orgs/joomla/repos?type=all', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListOrg('joomla'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetList method. - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repositories', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/user/repos', - '{"name":"joomla-test","description":"","homepage":"","private":false,"has_issues":false,' - . '"has_wiki":false,"has_downloads":false,"team_id":0,"auto_init":false,"gitignore_template":""}', - array(), 0 - ) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla-test'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the Create method. - * - * @return void - */ - public function testCreateWithOrg() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/orgs/joomla.org/repos', - '{"name":"joomla-test","description":"","homepage":"","private":false,"has_issues":false,' - . '"has_wiki":false,"has_downloads":false,"team_id":0,"auto_init":false,"gitignore_template":""}', - array(), 0 - ) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('joomla-test', 'joomla.org'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListOrg method. - * - * @return void - */ - public function testGetListOrgInvalidType() - { - $this->expectException(\RuntimeException::class); - - $this->object->getListOrg('joomla', 'INVALID'); - } - - /** - * Tests the Edit method. - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with( - '/repos/joomla/joomla-test', - '{"name":"joomla-test-1","description":"","homepage":"","private":' - . 'false,"has_issues":false,"has_wiki":false,"has_downloads":false,"default_branch":""}', - array() - ) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit('joomla', 'joomla-test', 'joomla-test-1'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListContributors method. - * - * @return void - */ - public function testGetListContributors() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/contributors', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListContributors('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListLanguages method. - * - * @return void - */ - public function testGetListLanguages() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/languages', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListLanguages('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListTeams method. - * - * @return void - */ - public function testGetListTeams() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/teams', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListTeams('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetListTags method. - * - * @return void - */ - public function testGetListTags() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/repos/joomla/joomla-cms/tags', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListTags('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the Delete method. - * - * @return void - */ - public function testDelete() - { - $this->client->expects($this->once()) - ->method('delete') - ->with('/repos/joomla/joomla-cms', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete('joomla', 'joomla-cms'), - $this->equalTo(json_decode($this->response->body)) - ); - } + /** + * @var Repositories + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Repositories($this->options, $this->client); + } + + /** + * Tests the GetListOwn method. + * + * @return void + */ + public function testGetListOwn() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/repos?type=all&sort=full_name&direction=asc', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListOwn(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListOwn method. + * + * @return void + */ + public function testGetListOwnInvalidType() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListOwn('INVALID'); + } + + /** + * Tests the GetListOwn method. + * + * @return void + */ + public function testGetListOwnInvalidSortField() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListOwn('all', 'INVALID'); + } + + /** + * Tests the GetListOwn method. + * + * @return void + */ + public function testGetListOwnInvalidSortOrder() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListOwn('all', 'full_name', 'INVALID'); + } + + /** + * Tests the GetListUser method. + * + * @return void + */ + public function testGetListUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/repos?type=all&sort=full_name&direction=asc', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListUser('joomla'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListUser method. + * + * @return void + */ + public function testGetListUserInvalidType() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListUser('joomla', 'INVALID'); + } + + /** + * Tests the GetListUser method. + * + * @return void + */ + public function testGetListUserInvalidSortField() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListUser('joomla', 'all', 'INVALID'); + } + + /** + * Tests the GetListUser method. + * + * @return void + */ + public function testGetListUserInvalidSortOrder() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListUser('joomla', 'all', 'full_name', 'INVALID'); + } + + /** + * Tests the GetListOrg method. + * + * @return void + */ + public function testGetListOrg() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/orgs/joomla/repos?type=all', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListOrg('joomla'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetList method. + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repositories', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with( + '/user/repos', + '{"name":"joomla-test","description":"","homepage":"","private":false,"has_issues":false,' + . '"has_wiki":false,"has_downloads":false,"team_id":0,"auto_init":false,"gitignore_template":""}', + [], + 0 + ) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla-test'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the Create method. + * + * @return void + */ + public function testCreateWithOrg() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with( + '/orgs/joomla.org/repos', + '{"name":"joomla-test","description":"","homepage":"","private":false,"has_issues":false,' + . '"has_wiki":false,"has_downloads":false,"team_id":0,"auto_init":false,"gitignore_template":""}', + [], + 0 + ) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('joomla-test', 'joomla.org'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-cms', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListOrg method. + * + * @return void + */ + public function testGetListOrgInvalidType() + { + $this->expectException(\RuntimeException::class); + + $this->object->getListOrg('joomla', 'INVALID'); + } + + /** + * Tests the Edit method. + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with( + '/repos/joomla/joomla-test', + '{"name":"joomla-test-1","description":"","homepage":"","private":' + . 'false,"has_issues":false,"has_wiki":false,"has_downloads":false,"default_branch":""}', + [] + ) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit('joomla', 'joomla-test', 'joomla-test-1'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListContributors method. + * + * @return void + */ + public function testGetListContributors() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-cms/contributors', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListContributors('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListLanguages method. + * + * @return void + */ + public function testGetListLanguages() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-cms/languages', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListLanguages('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListTeams method. + * + * @return void + */ + public function testGetListTeams() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-cms/teams', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListTeams('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetListTags method. + * + * @return void + */ + public function testGetListTags() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-cms/tags', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListTags('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the Delete method. + * + * @return void + */ + public function testDelete() + { + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-cms', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete('joomla', 'joomla-cms'), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/SearchTest.php b/Tests/Package/SearchTest.php index 1a2d5954..ea8c758f 100644 --- a/Tests/Package/SearchTest.php +++ b/Tests/Package/SearchTest.php @@ -16,107 +16,107 @@ */ class SearchTest extends GitHubTestCase { - /** - * @var Search - */ - protected $object; + /** + * @var Search + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Search($this->options, $this->client); - } + $this->object = new Search($this->options, $this->client); + } - /** - * Tests the issues method - * - * @return void - */ - public function testIssues() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/issues/search/joomla/joomla-platform/open/github') - ->will($this->returnValue($this->response)); + /** + * Tests the issues method + * + * @return void + */ + public function testIssues() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/legacy/issues/search/joomla/joomla-platform/open/github') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->issues('joomla', 'joomla-platform', 'open', 'github'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->issues('joomla', 'joomla-platform', 'open', 'github'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the issuesInvalidState method - * - * @return void - */ - public function testIssuesInvalidState() - { - $this->expectException(\UnexpectedValueException::class); + /** + * Tests the issuesInvalidState method + * + * @return void + */ + public function testIssuesInvalidState() + { + $this->expectException(\UnexpectedValueException::class); - $this->object->issues('joomla', 'joomla-platform', 'invalid', 'github'); - } + $this->object->issues('joomla', 'joomla-platform', 'invalid', 'github'); + } - /** - * Tests the repositories method - * - * @return void - */ - public function testRepositories() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/repos/search/joomla') - ->will($this->returnValue($this->response)); + /** + * Tests the repositories method + * + * @return void + */ + public function testRepositories() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/legacy/repos/search/joomla') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->repositories('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->repositories('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the users method - * - * @return void - */ - public function testUsers() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/user/search/joomla') - ->will($this->returnValue($this->response)); + /** + * Tests the users method + * + * @return void + */ + public function testUsers() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/legacy/user/search/joomla') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->users('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->users('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the email method - * - * @return void - */ - public function testEmail() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/legacy/user/email/email@joomla') - ->will($this->returnValue($this->response)); + /** + * Tests the email method + * + * @return void + */ + public function testEmail() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/legacy/user/email/email@joomla') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->email('email@joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->email('email@joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Users/EmailsTest.php b/Tests/Package/Users/EmailsTest.php index c1d466e6..a08eda6b 100644 --- a/Tests/Package/Users/EmailsTest.php +++ b/Tests/Package/Users/EmailsTest.php @@ -16,81 +16,81 @@ */ class EmailsTest extends GitHubTestCase { - /** - * @var Emails - */ - protected $object; + /** + * @var Emails + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Emails($this->options, $this->client); - } + $this->object = new Emails($this->options, $this->client); + } - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/emails') - ->will($this->returnValue($this->response)); + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/emails') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the add method - * - * @return void - */ - public function testAdd() - { - $this->response->code = 201; + /** + * Tests the add method + * + * @return void + */ + public function testAdd() + { + $this->response->code = 201; - $this->client->expects($this->once()) - ->method('post') - ->with('/user/emails') - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('post') + ->with('/user/emails') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->add('email@example.com'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->add('email@example.com'), + $this->equalTo(json_decode($this->sampleString)) + ); + } - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; - $this->client->expects($this->once()) - ->method('delete') - ->with('/user/emails') - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('delete') + ->with('/user/emails') + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->delete('email@example.com'), - $this->equalTo(json_decode($this->sampleString)) - ); - } + $this->assertThat( + $this->object->delete('email@example.com'), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/Users/FollowersTest.php b/Tests/Package/Users/FollowersTest.php index 6bad291b..00a1c247 100644 --- a/Tests/Package/Users/FollowersTest.php +++ b/Tests/Package/Users/FollowersTest.php @@ -18,305 +18,305 @@ */ class FollowersTest extends GitHubTestCase { - /** - * @var Followers - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Followers($this->options, $this->client); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::getList() - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/followers') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::getList() - * - * @return void - */ - public function testGetListWithUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/followers') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::getListFollowedBy() - * - * @return void - */ - public function testGetListFollowedBy() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/user/following') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListFollowedBy(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::getListFollowedBy() - * - * @return void - */ - public function testGetListFollowedByWithUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/following') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListFollowedBy('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::check() - * - * You are following this user - * - * @return void - */ - public function testCheck() - { - $this->response->code = 204; - $this->response->body = true; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla'), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::check() - * - * You are not following this user - * - * @return void - */ - public function testCheckNo() - { - $this->response->code = 404; - $this->response->body = false; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla'), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::check() - * - * @return void - */ - public function testCheckUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - - $this->response->code = 666; - $this->response->body = false; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->check('joomla'), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::follow() - * - * @return void - */ - public function testFollow() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('put') - ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->follow('joomla'), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::unfollow() - * - * @return void - */ - public function testUnfollow() - { - $this->response->code = 204; - $this->response->body = ''; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/user/following/joomla') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->unfollow('joomla'), - $this->equalTo($this->response->body) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() - * - * User is following the target - * - * @return void - * - * @since 1.0 - */ - public function testCheckUserFollowing() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/{user}/following/{target}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkUserFollowing('{user}', '{target}'), - $this->equalTo(true) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() - * - * User is not following the target - * - * @return void - * - * @since 1.0 - */ - public function testCheckUserFollowingNot() - { - $this->response->code = 404; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/{user}/following/{target}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkUserFollowing('{user}', '{target}'), - $this->equalTo(false) - ); - } - - /** - * Test method. - * - * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() - * - * // Unexpected response - * - * @return void - * - * @since 1.0 - */ - public function testCheckUserFollowingUnexpected() - { - $this->expectException(\UnexpectedValueException::class); - $this->expectExceptionMessage('Unexpected response code: 666'); - - $this->response->code = 666; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user/{user}/following/{target}') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->checkUserFollowing('{user}', '{target}'), - $this->equalTo(true) - ); - } + /** + * @var Followers + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Followers($this->options, $this->client); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getList() + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/followers') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getList() + * + * @return void + */ + public function testGetListWithUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/followers') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getListFollowedBy() + * + * @return void + */ + public function testGetListFollowedBy() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/user/following') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListFollowedBy(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::getListFollowedBy() + * + * @return void + */ + public function testGetListFollowedByWithUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/following') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListFollowedBy('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::check() + * + * You are following this user + * + * @return void + */ + public function testCheck() + { + $this->response->code = 204; + $this->response->body = true; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/following/joomla') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla'), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::check() + * + * You are not following this user + * + * @return void + */ + public function testCheckNo() + { + $this->response->code = 404; + $this->response->body = false; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/following/joomla') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla'), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::check() + * + * @return void + */ + public function testCheckUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + + $this->response->code = 666; + $this->response->body = false; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/following/joomla') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->check('joomla'), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::follow() + * + * @return void + */ + public function testFollow() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('put') + ->with('/user/following/joomla') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->follow('joomla'), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::unfollow() + * + * @return void + */ + public function testUnfollow() + { + $this->response->code = 204; + $this->response->body = ''; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/user/following/joomla') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->unfollow('joomla'), + $this->equalTo($this->response->body) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() + * + * User is following the target + * + * @return void + * + * @since 1.0 + */ + public function testCheckUserFollowing() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/{user}/following/{target}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkUserFollowing('{user}', '{target}'), + $this->equalTo(true) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() + * + * User is not following the target + * + * @return void + * + * @since 1.0 + */ + public function testCheckUserFollowingNot() + { + $this->response->code = 404; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/{user}/following/{target}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkUserFollowing('{user}', '{target}'), + $this->equalTo(false) + ); + } + + /** + * Test method. + * + * @covers \Joomla\Github\Package\Users\Followers::checkUserFollowing() + * + * // Unexpected response + * + * @return void + * + * @since 1.0 + */ + public function testCheckUserFollowingUnexpected() + { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('Unexpected response code: 666'); + + $this->response->code = 666; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user/{user}/following/{target}') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->checkUserFollowing('{user}', '{target}'), + $this->equalTo(true) + ); + } } diff --git a/Tests/Package/Users/KeysTest.php b/Tests/Package/Users/KeysTest.php index a7548890..a5be5862 100644 --- a/Tests/Package/Users/KeysTest.php +++ b/Tests/Package/Users/KeysTest.php @@ -16,135 +16,135 @@ */ class KeysTest extends GitHubTestCase { - /** - * @var Keys - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Keys($this->options, $this->client); - } - - /** - * Tests the getListUser method - * - * @return void - */ - public function testGetListUser() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla/keys') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getListUser('joomla'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the getList method - * - * @return void - */ - public function testGetList() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/keys') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the get method - * - * @return void - */ - public function testGet() - { - $this->client->expects($this->once()) - ->method('get') - ->with('/users/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get(1), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the create method - * - * @return void - */ - public function testCreate() - { - $this->response->code = 201; - - $this->client->expects($this->once()) - ->method('post') - ->with('/users/keys') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->create('email@example.com', '12345'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the edit method - * - * @return void - */ - public function testEdit() - { - $this->client->expects($this->once()) - ->method('patch') - ->with('/users/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit(1, 'email@example.com', '12345'), - $this->equalTo(json_decode($this->sampleString)) - ); - } - - /** - * Tests the delete method - * - * @return void - */ - public function testDelete() - { - $this->response->code = 204; - - $this->client->expects($this->once()) - ->method('delete') - ->with('/users/keys/1') - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->delete(1), - $this->equalTo(json_decode($this->sampleString)) - ); - } + /** + * @var Keys + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Keys($this->options, $this->client); + } + + /** + * Tests the getListUser method + * + * @return void + */ + public function testGetListUser() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla/keys') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getListUser('joomla'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getList method + * + * @return void + */ + public function testGetList() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/keys') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the get method + * + * @return void + */ + public function testGet() + { + $this->client->expects($this->once()) + ->method('get') + ->with('/users/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get(1), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the create method + * + * @return void + */ + public function testCreate() + { + $this->response->code = 201; + + $this->client->expects($this->once()) + ->method('post') + ->with('/users/keys') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->create('email@example.com', '12345'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the edit method + * + * @return void + */ + public function testEdit() + { + $this->client->expects($this->once()) + ->method('patch') + ->with('/users/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit(1, 'email@example.com', '12345'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the delete method + * + * @return void + */ + public function testDelete() + { + $this->response->code = 204; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/users/keys/1') + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->delete(1), + $this->equalTo(json_decode($this->sampleString)) + ); + } } diff --git a/Tests/Package/UsersTest.php b/Tests/Package/UsersTest.php index 5b7f52c1..83845b1c 100755 --- a/Tests/Package/UsersTest.php +++ b/Tests/Package/UsersTest.php @@ -16,35 +16,35 @@ */ class UsersTest extends GitHubTestCase { - /** - * @var Users - */ - protected $object; - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @access protected - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); - - $this->object = new Users($this->options, $this->client); - } - - /** - * Tests the getUser method - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = '{ + /** + * @var Users + */ + protected $object; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @access protected + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); + + $this->object = new Users($this->options, $this->client); + } + + /** + * Tests the getUser method + * + * @return void + */ + public function testGet() + { + $this->response->code = 200; + $this->response->body = '{ "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", @@ -66,49 +66,49 @@ public function testGet() "type": "User" }'; - $this->client->expects($this->once()) - ->method('get') - ->with('/users/joomla', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('joomla'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUser method with failure - * - * @return void - */ - public function testGetFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 404; - $this->response->body = '{"message":"Not Found"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/users/nonexistentuser', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->get('nonexistentuser'), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getAuthenticatedUser method - * - * @return void - */ - public function testGetAuthenticatedUser() - { - $this->response->code = 200; - $this->response->body = '{ + $this->client->expects($this->once()) + ->method('get') + ->with('/users/joomla', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('joomla'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUser method with failure + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 404; + $this->response->body = '{"message":"Not Found"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/users/nonexistentuser', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->get('nonexistentuser'), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getAuthenticatedUser method + * + * @return void + */ + public function testGetAuthenticatedUser() + { + $this->response->code = 200; + $this->response->body = '{ "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", @@ -141,49 +141,49 @@ public function testGetAuthenticatedUser() } }'; - $this->client->expects($this->once()) - ->method('get') - ->with('/user', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getAuthenticatedUser(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the GetAuthenticatedUser method with failure - * - * @return void - */ - public function testGetAuthenticatedUserFailure() - { - $this->expectException(\DomainException::class); - - $this->response->code = 401; - $this->response->body = '{"message":"Requires authentication"}'; - - $this->client->expects($this->once()) - ->method('get') - ->with('/user', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getAuthenticatedUser(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUsers method - * - * @return void - */ - public function testGetList() - { - $this->response->code = 200; - $this->response->body = '[ + $this->client->expects($this->once()) + ->method('get') + ->with('/user', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getAuthenticatedUser(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the GetAuthenticatedUser method with failure + * + * @return void + */ + public function testGetAuthenticatedUserFailure() + { + $this->expectException(\DomainException::class); + + $this->response->code = 401; + $this->response->body = '{"message":"Requires authentication"}'; + + $this->client->expects($this->once()) + ->method('get') + ->with('/user', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getAuthenticatedUser(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUsers method + * + * @return void + */ + public function testGetList() + { + $this->response->code = 200; + $this->response->body = '[ { "login": "octocat", "id": 1, @@ -201,34 +201,34 @@ public function testGetList() } ]'; - $this->client->expects($this->once()) - ->method('get') - ->with('/users', array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->getList(), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUsers method - * - * @return void - */ - public function testEdit() - { - $name = 'monalisa octocat'; - $email = 'octocat@github.com'; - $blog = 'https =>//github.com/blog'; - $company = 'GitHub'; - $location = 'San Francisco'; - $hireable = true; - $bio = 'There once...'; - - $this->response->code = 200; - $this->response->body = '{ + $this->client->expects($this->once()) + ->method('get') + ->with('/users', [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->getList(), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUsers method + * + * @return void + */ + public function testEdit() + { + $name = 'monalisa octocat'; + $email = 'octocat@github.com'; + $blog = 'https =>//github.com/blog'; + $company = 'GitHub'; + $location = 'San Francisco'; + $hireable = true; + $bio = 'There once...'; + + $this->response->code = 200; + $this->response->body = '{ "login": "octocat", "id": 1, "avatar_url": "https://github.com/images/error/octocat_happy.gif", @@ -261,71 +261,71 @@ public function testEdit() } }'; - $input = json_encode( - array( - 'name' => $name, - 'email' => $email, - 'blog' => $blog, - 'company' => $company, - 'location' => $location, - 'hireable' => $hireable, - 'bio' => $bio - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/user', $input, array(), 0) - ->will($this->returnValue($this->response)); - - $this->assertThat( - $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio), - $this->equalTo(json_decode($this->response->body)) - ); - } - - /** - * Tests the getUsers method - * - * @return void - */ - public function testEditFailure() - { - $this->expectException(\DomainException::class); - - $name = 'monalisa octocat'; - $email = 'octocat@github.com'; - $blog = 'https =>//github.com/blog'; - $company = 'GitHub'; - $location = 'San Francisco'; - $hireable = true; - $bio = 'There once...'; - - $this->response->code = 404; - $this->response->body = $this->errorString; - - $input = json_encode( - array( - 'name' => $name, - 'email' => $email, - 'blog' => $blog, - 'company' => $company, - 'location' => $location, - 'hireable' => $hireable, - 'bio' => $bio - ) - ); - - $this->client->expects($this->once()) - ->method('patch') - ->with('/user', $input, array(), 0) - ->will($this->returnValue($this->response)); - - // $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio); - - $this->assertThat( - $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio), - $this->equalTo(json_decode($this->response->body)) - ); - } + $input = json_encode( + [ + 'name' => $name, + 'email' => $email, + 'blog' => $blog, + 'company' => $company, + 'location' => $location, + 'hireable' => $hireable, + 'bio' => $bio, + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/user', $input, [], 0) + ->will($this->returnValue($this->response)); + + $this->assertThat( + $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio), + $this->equalTo(json_decode($this->response->body)) + ); + } + + /** + * Tests the getUsers method + * + * @return void + */ + public function testEditFailure() + { + $this->expectException(\DomainException::class); + + $name = 'monalisa octocat'; + $email = 'octocat@github.com'; + $blog = 'https =>//github.com/blog'; + $company = 'GitHub'; + $location = 'San Francisco'; + $hireable = true; + $bio = 'There once...'; + + $this->response->code = 404; + $this->response->body = $this->errorString; + + $input = json_encode( + [ + 'name' => $name, + 'email' => $email, + 'blog' => $blog, + 'company' => $company, + 'location' => $location, + 'hireable' => $hireable, + 'bio' => $bio, + ] + ); + + $this->client->expects($this->once()) + ->method('patch') + ->with('/user', $input, [], 0) + ->will($this->returnValue($this->response)); + + // $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio); + + $this->assertThat( + $this->object->edit($name, $email, $blog, $company, $location, $hireable, $bio), + $this->equalTo(json_decode($this->response->body)) + ); + } } diff --git a/Tests/Package/ZenTest.php b/Tests/Package/ZenTest.php index a68cfeba..f7ab1943 100644 --- a/Tests/Package/ZenTest.php +++ b/Tests/Package/ZenTest.php @@ -16,67 +16,67 @@ */ class ZenTest extends GitHubTestCase { - /** - * @var Zen - */ - protected $object; + /** + * @var Zen + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Zen($this->options, $this->client); - } + $this->object = new Zen($this->options, $this->client); + } - /** - * Tests the Get method. - * - * @return void - */ - public function testGet() - { - $this->response->code = 200; - $this->response->body = 'My Zen'; + /** + * Tests the Get method. + * + * @return void + */ + public function testGet() + { + $this->response->code = 200; + $this->response->body = 'My Zen'; - $this->client->expects($this->once()) - ->method('get') - ->with('/zen', array(), 0) - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('get') + ->with('/zen', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get(), - $this->equalTo($this->response->body) - ); - } + $this->assertThat( + $this->object->get(), + $this->equalTo($this->response->body) + ); + } - /** - * Tests the Get method. - * - * @return void - */ - public function testGetFailure() - { - $this->expectException(\RuntimeException::class); + /** + * Tests the Get method. + * + * @return void + */ + public function testGetFailure() + { + $this->expectException(\RuntimeException::class); - $this->response->code = 400; - $this->response->body = 'My Zen'; + $this->response->code = 400; + $this->response->body = 'My Zen'; - $this->client->expects($this->once()) - ->method('get') - ->with('/zen', array(), 0) - ->will($this->returnValue($this->response)); + $this->client->expects($this->once()) + ->method('get') + ->with('/zen', [], 0) + ->will($this->returnValue($this->response)); - $this->assertThat( - $this->object->get(), - $this->equalTo($this->response->body) - ); - } + $this->assertThat( + $this->object->get(), + $this->equalTo($this->response->body) + ); + } } diff --git a/Tests/PackageTest.php b/Tests/PackageTest.php index 717375d1..c86e3c42 100755 --- a/Tests/PackageTest.php +++ b/Tests/PackageTest.php @@ -16,53 +16,53 @@ */ class PackageTest extends GitHubTestCase { - /** - * @var Github Object under test. - * @since 1.0 - */ - protected $object; + /** + * @var Github Object under test. + * @since 1.0 + */ + protected $object; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @return void - * - * @since 1.0 - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @return void + * + * @since 1.0 + */ + protected function setUp(): void + { + parent::setUp(); - $this->object = new Github($this->options, $this->client); - } + $this->object = new Github($this->options, $this->client); + } - /** - * Tests the magic __get method - * - * @return void - * - * @since 1.0 - */ - public function testGet() - { - $this->assertThat( - $this->object->repositories->forks, - $this->isInstanceOf('Joomla\Github\Package\Repositories\Forks') - ); - } + /** + * Tests the magic __get method + * + * @return void + * + * @since 1.0 + */ + public function testGet() + { + $this->assertThat( + $this->object->repositories->forks, + $this->isInstanceOf('Joomla\Github\Package\Repositories\Forks') + ); + } - /** - * Tests the magic __get method with an invalid parameter. - * - * @return void - * - * @since 1.0 - */ - public function testGetInvalid() - { - $this->expectException(\InvalidArgumentException::class); + /** + * Tests the magic __get method with an invalid parameter. + * + * @return void + * + * @since 1.0 + */ + public function testGetInvalid() + { + $this->expectException(\InvalidArgumentException::class); - $this->object->repositories->INVALID; - } + $this->object->repositories->INVALID; + } } diff --git a/Tests/Stub/GitHubTestCase.php b/Tests/Stub/GitHubTestCase.php index f6c4b1ae..c4c91664 100644 --- a/Tests/Stub/GitHubTestCase.php +++ b/Tests/Stub/GitHubTestCase.php @@ -16,59 +16,59 @@ */ abstract class GitHubTestCase extends TestCase { - /** - * @var Registry Options for the GitHub object. - * @since 1.0 - */ - protected $options; + /** + * @var Registry Options for the GitHub object. + * @since 1.0 + */ + protected $options; - /** - * @var \PHPUnit_Framework_MockObject_MockObject Mock client object. - * @since 1.0 - */ - protected $client; + /** + * @var \PHPUnit_Framework_MockObject_MockObject Mock client object. + * @since 1.0 + */ + protected $client; - /** - * @var \Joomla\Http\Response Mock response object. - * @since 1.0 - */ - protected $response; + /** + * @var \Joomla\Http\Response Mock response object. + * @since 1.0 + */ + protected $response; - /** - * @var string Sample JSON string. - * @since 12.3 - */ - protected $sampleString = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; + /** + * @var string Sample JSON string. + * @since 12.3 + */ + protected $sampleString = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; - /** - * @var string Sample JSON error message. - * @since 12.3 - */ - protected $errorString = '{"message": "Generic Error"}'; + /** + * @var string Sample JSON error message. + * @since 12.3 + */ + protected $errorString = '{"message": "Generic Error"}'; - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - * - * @since 1.0 - * - * @return void - */ - protected function setUp(): void - { - parent::setUp(); + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + * + * @since 1.0 + * + * @return void + */ + protected function setUp(): void + { + parent::setUp(); - $this->options = new Registry; + $this->options = new Registry(); - $this->client = $this->getMockBuilder('\\Joomla\\Http\\Http') - ->setMethods(array('get', 'post', 'delete', 'patch', 'put')) - ->getMock(); + $this->client = $this->getMockBuilder('\\Joomla\\Http\\Http') + ->setMethods(['get', 'post', 'delete', 'patch', 'put']) + ->getMock(); - $this->response = $this->getMockBuilder('\\Joomla\\Http\\Response') - ->getMock(); + $this->response = $this->getMockBuilder('\\Joomla\\Http\\Response') + ->getMock(); - // Set a default response - $this->response->code = 200; - $this->response->body = $this->sampleString; - } + // Set a default response + $this->response->code = 200; + $this->response->body = $this->sampleString; + } } diff --git a/Tests/Stub/ObjectMock.php b/Tests/Stub/ObjectMock.php index 8ddcb1cd..fe40373e 100644 --- a/Tests/Stub/ObjectMock.php +++ b/Tests/Stub/ObjectMock.php @@ -15,23 +15,23 @@ */ class ObjectMock extends AbstractGithubObject { - // @codingStandardsIgnoreStart - /** - * Method to build and return a full request URL for the request. This method will - * add appropriate pagination details if necessary and also prepend the API url - * to have a complete URL for the request. - * - * @param string $path URL to inflect - * @param integer $page Page to request - * @param integer $limit Number of results to return per page - * - * @return string The request URL. - * - * @since 1.0 - */ - public function fetchUrl($path, $page = 0, $limit = 0) - { - return parent::fetchUrl($path, $page, $limit); - } - // @codingStandardsIgnoreEnd + // @codingStandardsIgnoreStart + /** + * Method to build and return a full request URL for the request. This method will + * add appropriate pagination details if necessary and also prepend the API url + * to have a complete URL for the request. + * + * @param string $path URL to inflect + * @param integer $page Page to request + * @param integer $limit Number of results to return per page + * + * @return string The request URL. + * + * @since 1.0 + */ + public function fetchUrl($path, $page = 0, $limit = 0) + { + return parent::fetchUrl($path, $page, $limit); + } + // @codingStandardsIgnoreEnd } diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index ddfe6fa4..f87308fe 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -1,6 +1,7 @@ options = $options ?: new Registry; - $this->client = $client ?: (new HttpFactory)->getHttp($this->options); - - $this->package = \get_class($this); - $this->package = substr($this->package, strrpos($this->package, '\\') + 1); - } - - /** - * Method to build and return a full request URL for the request. This method will - * add appropriate pagination details if necessary and also prepend the API url - * to have a complete URL for the request. - * - * @param string $path URL to inflect - * @param integer $page Page to request - * @param integer $limit Number of results to return per page - * - * @return Uri - * - * @since 1.0 - */ - protected function fetchUrl($path, $page = 0, $limit = 0) - { - // Get a new Uri object focusing the api url and given path. - $uri = new Uri($this->options->get('api.url') . $path); - - if ($this->options->get('gh.token', false)) - { - // Use oAuth authentication - $headers = $this->client->getOption('headers', array()); - - if (!isset($headers['Authorization'])) - { - $headers['Authorization'] = 'token ' . $this->options->get('gh.token'); - $this->client->setOption('headers', $headers); - } - } - else - { - // Use basic authentication - if ($this->options->get('api.username', false)) - { - $uri->setUser($this->options->get('api.username')); - } - - if ($this->options->get('api.password', false)) - { - $uri->setPass($this->options->get('api.password')); - } - } - - // If we have a defined page number add it to the JUri object. - if ($page > 0) - { - $uri->setVar('page', (int) $page); - } - - // If we have a defined items per page add it to the JUri object. - if ($limit > 0) - { - $uri->setVar('per_page', (int) $limit); - } - - return $uri; - } - - /** - * Process the response and decode it. - * - * @param Response $response The response. - * @param integer $expectedCode The expected "good" code. - * - * @return mixed - * - * @since 1.0 - * @throws UnexpectedResponseException - */ - protected function processResponse(Response $response, $expectedCode = 200) - { - // Validate the response code. - if ($response->code != $expectedCode) - { - // Decode the error response and throw an exception. - $error = json_decode($response->body); - $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; - - throw new UnexpectedResponseException($response, $message, $response->code); - } - - return json_decode($response->body); - } + /** + * Options for the GitHub object. + * + * @var Registry + * @since 1.0 + */ + protected $options; + + /** + * The HTTP client object to use in sending HTTP requests. + * + * @var BaseHttp + * @since 1.0 + */ + protected $client; + + /** + * The package the object resides in + * + * @var string + * @since 1.0 + */ + protected $package = ''; + + /** + * Array containing the allowed hook events + * + * @var array + * @since 1.5.2 + * @link https://developer.github.com/webhooks/#events + * @note From 1.4.0 to 1.5.1 this was named $events, it was renamed due to naming conflicts with package subclasses + */ + protected $hookEvents = [ + '*', + 'commit_comment', + 'create', + 'delete', + 'deployment', + 'deployment_status', + 'fork', + 'gollum', + 'issue_comment', + 'issues', + 'member', + 'membership', + 'page_build', + 'public', + 'pull_request_review_comment', + 'pull_request', + 'push', + 'repository', + 'release', + 'status', + 'team_add', + 'watch', + ]; + + /** + * Constructor. + * + * @param Registry $options GitHub options object. + * @param BaseHttp $client The HTTP client object. + * + * @since 1.0 + */ + public function __construct(Registry $options = null, BaseHttp $client = null) + { + $this->options = $options ?: new Registry(); + $this->client = $client ?: (new HttpFactory())->getHttp($this->options); + + $this->package = \get_class($this); + $this->package = substr($this->package, strrpos($this->package, '\\') + 1); + } + + /** + * Method to build and return a full request URL for the request. This method will + * add appropriate pagination details if necessary and also prepend the API url + * to have a complete URL for the request. + * + * @param string $path URL to inflect + * @param integer $page Page to request + * @param integer $limit Number of results to return per page + * + * @return Uri + * + * @since 1.0 + */ + protected function fetchUrl($path, $page = 0, $limit = 0) + { + // Get a new Uri object focusing the api url and given path. + $uri = new Uri($this->options->get('api.url') . $path); + + if ($this->options->get('gh.token', false)) { + // Use oAuth authentication + $headers = $this->client->getOption('headers', []); + + if (!isset($headers['Authorization'])) { + $headers['Authorization'] = 'token ' . $this->options->get('gh.token'); + $this->client->setOption('headers', $headers); + } + } else { + // Use basic authentication + if ($this->options->get('api.username', false)) { + $uri->setUser($this->options->get('api.username')); + } + + if ($this->options->get('api.password', false)) { + $uri->setPass($this->options->get('api.password')); + } + } + + // If we have a defined page number add it to the JUri object. + if ($page > 0) { + $uri->setVar('page', (int) $page); + } + + // If we have a defined items per page add it to the JUri object. + if ($limit > 0) { + $uri->setVar('per_page', (int) $limit); + } + + return $uri; + } + + /** + * Process the response and decode it. + * + * @param Response $response The response. + * @param integer $expectedCode The expected "good" code. + * + * @return mixed + * + * @since 1.0 + * @throws UnexpectedResponseException + */ + protected function processResponse(Response $response, $expectedCode = 200) + { + // Validate the response code. + if ($response->code != $expectedCode) { + // Decode the error response and throw an exception. + $error = json_decode($response->body); + $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; + + throw new UnexpectedResponseException($response, $message, $response->code); + } + + return json_decode($response->body); + } } diff --git a/src/AbstractPackage.php b/src/AbstractPackage.php index 98ce329c..cf767157 100644 --- a/src/AbstractPackage.php +++ b/src/AbstractPackage.php @@ -18,51 +18,51 @@ */ abstract class AbstractPackage extends AbstractGithubObject { - /** - * Constructor. - * - * @param Registry $options GitHub options object. - * @param Http $client The HTTP client object. - * - * @since 1.0 - */ - public function __construct(Registry $options = null, Http $client = null) - { - parent::__construct($options, $client); + /** + * Constructor. + * + * @param Registry $options GitHub options object. + * @param Http $client The HTTP client object. + * + * @since 1.0 + */ + public function __construct(Registry $options = null, Http $client = null) + { + parent::__construct($options, $client); - $this->package = \get_class($this); - $this->package = substr($this->package, strrpos($this->package, '\\') + 1); - } + $this->package = \get_class($this); + $this->package = substr($this->package, strrpos($this->package, '\\') + 1); + } - /** - * Magic method to lazily create API objects - * - * @param string $name Name of property to retrieve - * - * @since 1.0 - * @throws \InvalidArgumentException - * - * @return AbstractPackage GitHub API package object. - */ - public function __get($name) - { - $class = '\\Joomla\\Github\\Package\\' . $this->package . '\\' . ucfirst($name); + /** + * Magic method to lazily create API objects + * + * @param string $name Name of property to retrieve + * + * @since 1.0 + * @throws \InvalidArgumentException + * + * @return AbstractPackage GitHub API package object. + */ + public function __get($name) + { + $class = '\\Joomla\\Github\\Package\\' . $this->package . '\\' . ucfirst($name); - if (class_exists($class) == false) - { - throw new \InvalidArgumentException( - sprintf( - 'Argument %1$s produced an invalid class name: %2$s in package %3$s', - $name, $class, $this->package - ) - ); - } + if (class_exists($class) == false) { + throw new \InvalidArgumentException( + sprintf( + 'Argument %1$s produced an invalid class name: %2$s in package %3$s', + $name, + $class, + $this->package + ) + ); + } - if (isset($this->$name) == false) - { - $this->$name = new $class($this->options, $this->client); - } + if (isset($this->$name) == false) { + $this->$name = new $class($this->options, $this->client); + } - return $this->$name; - } + return $this->$name; + } } diff --git a/src/Github.php b/src/Github.php index 636b1a9d..b30c4d37 100644 --- a/src/Github.php +++ b/src/Github.php @@ -36,104 +36,100 @@ */ class Github { - /** - * Options for the GitHub object. - * - * @var array - * @since 1.0 - */ - protected $options; + /** + * Options for the GitHub object. + * + * @var array + * @since 1.0 + */ + protected $options; - /** - * The HTTP client object to use in sending HTTP requests. - * - * @var Http - * @since 1.0 - */ - protected $client; + /** + * The HTTP client object to use in sending HTTP requests. + * + * @var Http + * @since 1.0 + */ + protected $client; - /** - * Constructor. - * - * @param Registry $options GitHub options object. - * @param Http $client The HTTP client object. - * - * @since 1.0 - */ - public function __construct(Registry $options = null, Http $client = null) - { - $this->options = $options ?: new Registry; + /** + * Constructor. + * + * @param Registry $options GitHub options object. + * @param Http $client The HTTP client object. + * + * @since 1.0 + */ + public function __construct(Registry $options = null, Http $client = null) + { + $this->options = $options ?: new Registry(); - // Setup the default user agent if not already set. - if (!$this->getOption('userAgent')) - { - $this->setOption('userAgent', 'JGitHub/2.0'); - } + // Setup the default user agent if not already set. + if (!$this->getOption('userAgent')) { + $this->setOption('userAgent', 'JGitHub/2.0'); + } - // Setup the default API url if not already set. - if (!$this->getOption('api.url')) - { - $this->setOption('api.url', 'https://api.github.com'); - } + // Setup the default API url if not already set. + if (!$this->getOption('api.url')) { + $this->setOption('api.url', 'https://api.github.com'); + } - $this->client = $client ?: (new HttpFactory)->getHttp($this->options); - } + $this->client = $client ?: (new HttpFactory())->getHttp($this->options); + } - /** - * Magic method to lazily create API objects - * - * @param string $name Name of property to retrieve - * - * @return AbstractGithubObject GitHub API object (gists, issues, pulls, etc). - * - * @since 1.0 - * @throws \InvalidArgumentException If $name is not a valid sub class. - */ - public function __get($name) - { - $class = 'Joomla\\Github\\Package\\' . ucfirst($name); + /** + * Magic method to lazily create API objects + * + * @param string $name Name of property to retrieve + * + * @return AbstractGithubObject GitHub API object (gists, issues, pulls, etc). + * + * @since 1.0 + * @throws \InvalidArgumentException If $name is not a valid sub class. + */ + public function __get($name) + { + $class = 'Joomla\\Github\\Package\\' . ucfirst($name); - if (class_exists($class)) - { - if (isset($this->$name) == false) - { - $this->$name = new $class($this->options, $this->client); - } + if (class_exists($class)) { + if (isset($this->$name) == false) { + $this->$name = new $class($this->options, $this->client); + } - return $this->$name; - } + return $this->$name; + } - throw new \InvalidArgumentException(sprintf('Argument %s produced an invalid class name: %s', $name, $class)); - } + throw new \InvalidArgumentException(sprintf('Argument %s produced an invalid class name: %s', $name, $class)); + } - /** - * Get an option from the GitHub instance. - * - * @param string $key The name of the option to get. - * - * @return mixed The option value. - * - * @since 1.0 - */ - public function getOption($key) - { - return isset($this->options[$key]) ? $this->options[$key] : null; - } + /** + * Get an option from the GitHub instance. + * + * @param string $key The name of the option to get. + * + * @return mixed The option value. + * + * @since 1.0 + */ + public function getOption($key) + { + return isset($this->options[$key]) ? $this->options[$key] : null; + } - /** - * Set an option for the GitHub instance. - * - * @param string $key The name of the option to set. - * @param mixed $value The option value to set. - * - * @return GitHub This object for method chaining. - * - * @since 1.0 - */ - public function setOption($key, $value) - { - $this->options[$key] = $value; + /** + * Set an option for the GitHub instance. + * + * @param string $key The name of the option to set. + * @param mixed $value The option value to set. + * + * @return GitHub This object for method chaining. + * + * @since 1.0 + */ + public function setOption($key, $value) + { + $this->options[$key] = $value; - return $this; - } + return $this; + } } diff --git a/src/Package/Activity/Events.php b/src/Package/Activity/Events.php index dc8f2b34..c1ea8e02 100644 --- a/src/Package/Activity/Events.php +++ b/src/Package/Activity/Events.php @@ -19,205 +19,205 @@ */ class Events extends AbstractPackage { - /** - * List public events. - * - * @return object - * - * @since 1.0 - */ - public function getPublic() - { - // Build the request path. - $path = '/events'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List repository events. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function getRepository($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/events'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List issue events for a repository. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function getIssue($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/events'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List public events for a network of repositories. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function getNetwork($owner, $repo) - { - // Build the request path. - $path = '/networks/' . $owner . '/' . $repo . '/events'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List public events for an organization. - * - * @param string $org Organization. - * - * @return object - * - * @since 1.0 - */ - public function getOrg($org) - { - // Build the request path. - $path = '/orgs/' . $org . '/events'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List events that a user has received. - * - * These are events that you’ve received by watching repos and following users. - * If you are authenticated as the given user, you will see private events. - * Otherwise, you’ll only see public events. - * - * @param string $user User name. - * - * @return object - * - * @since 1.0 - */ - public function getUser($user) - { - // Build the request path. - $path = '/users/' . $user . '/received_events'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List public events that a user has received. - * - * @param string $user User name. - * - * @return object - * - * @since 1.0 - */ - public function getUserPublic($user) - { - // Build the request path. - $path = '/users/' . $user . '/received_events/public'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List events performed by a user. - * - * If you are authenticated as the given user, you will see your private events. - * Otherwise, you’ll only see public events. - * - * @param string $user User name. - * - * @return object - * - * @since 1.0 - */ - public function getByUser($user) - { - // Build the request path. - $path = '/users/' . $user . '/events'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List public events performed by a user. - * - * @param string $user User name. - * - * @return object - * - * @since 1.0 - */ - public function getByUserPublic($user) - { - // Build the request path. - $path = '/users/' . $user . '/events/public'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List events for an organization. - * - * This is the user’s organization dashboard. - * You must be authenticated as the user to view this. - * - * @param string $user User name. - * @param string $org Organisation. - * - * @return object - * - * @since 1.0 - */ - public function getUserOrg($user, $org) - { - // Build the request path. - $path = '/users/' . $user . '/events/orgs/' . $org; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + /** + * List public events. + * + * @return object + * + * @since 1.0 + */ + public function getPublic() + { + // Build the request path. + $path = '/events'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List repository events. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function getRepository($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/events'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List issue events for a repository. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function getIssue($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/events'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List public events for a network of repositories. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function getNetwork($owner, $repo) + { + // Build the request path. + $path = '/networks/' . $owner . '/' . $repo . '/events'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List public events for an organization. + * + * @param string $org Organization. + * + * @return object + * + * @since 1.0 + */ + public function getOrg($org) + { + // Build the request path. + $path = '/orgs/' . $org . '/events'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List events that a user has received. + * + * These are events that you’ve received by watching repos and following users. + * If you are authenticated as the given user, you will see private events. + * Otherwise, you’ll only see public events. + * + * @param string $user User name. + * + * @return object + * + * @since 1.0 + */ + public function getUser($user) + { + // Build the request path. + $path = '/users/' . $user . '/received_events'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List public events that a user has received. + * + * @param string $user User name. + * + * @return object + * + * @since 1.0 + */ + public function getUserPublic($user) + { + // Build the request path. + $path = '/users/' . $user . '/received_events/public'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List events performed by a user. + * + * If you are authenticated as the given user, you will see your private events. + * Otherwise, you’ll only see public events. + * + * @param string $user User name. + * + * @return object + * + * @since 1.0 + */ + public function getByUser($user) + { + // Build the request path. + $path = '/users/' . $user . '/events'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List public events performed by a user. + * + * @param string $user User name. + * + * @return object + * + * @since 1.0 + */ + public function getByUserPublic($user) + { + // Build the request path. + $path = '/users/' . $user . '/events/public'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List events for an organization. + * + * This is the user’s organization dashboard. + * You must be authenticated as the user to view this. + * + * @param string $user User name. + * @param string $org Organisation. + * + * @return object + * + * @since 1.0 + */ + public function getUserOrg($user, $org) + { + // Build the request path. + $path = '/users/' . $user . '/events/orgs/' . $org; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } } diff --git a/src/Package/Activity/Feeds.php b/src/Package/Activity/Feeds.php index decdee49..db50032d 100644 --- a/src/Package/Activity/Feeds.php +++ b/src/Package/Activity/Feeds.php @@ -19,20 +19,20 @@ */ class Feeds extends AbstractPackage { - /** - * List Feeds. - * - * @return object - * - * @since 1.4.0 - */ - public function getFeeds() - { - // Build the request path. - $path = '/feeds'; + /** + * List Feeds. + * + * @return object + * + * @since 1.4.0 + */ + public function getFeeds() + { + // Build the request path. + $path = '/feeds'; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } } diff --git a/src/Package/Activity/Notifications.php b/src/Package/Activity/Notifications.php index dc8c6e99..1ccaffb4 100644 --- a/src/Package/Activity/Notifications.php +++ b/src/Package/Activity/Notifications.php @@ -19,285 +19,279 @@ */ class Notifications extends AbstractPackage { - /** - * List your notifications. - * - * List all notifications for the current user, grouped by repository. - * - * @param boolean $all True to show notifications marked as read. - * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. - * @param \DateTimeInterface $since Only show notifications updated after the given time. - * @param \DateTimeInterface $before Only show notifications updated before the given time. - * - * @return object - * - * @since 1.0 - */ - public function getList($all = true, $participating = true, \DateTimeInterface $since = null, \DateTimeInterface $before = null) - { - // Build the request path. - $path = '/notifications'; - - $uri = $this->fetchUrl($path); - - if ($all) - { - $uri->setVar('all', 1); - } - - if ($participating) - { - $uri->setVar('participating', 1); - } - - if ($since) - { - $uri->setVar('since', $since->format(\DateTime::RFC3339)); - } - - if ($before) - { - $uri->setVar('before', $before->format(\DateTime::RFC3339)); - } - - return $this->processResponse($this->client->get($uri)); - } - - /** - * List your notifications in a repository. - * - * List all notifications for the current user. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param boolean $all True to show notifications marked as read. - * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. - * @param \DateTimeInterface $since Only show notifications updated after the given time. - * @param \DateTimeInterface $before Only show notifications updated before the given time. - * - * @return object - * - * @since 1.0 - */ - public function getListRepository($owner, $repo, $all = true, $participating = true, \DateTimeInterface $since = null, - \DateTimeInterface $before = null - ) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/notifications'; - - $uri = $this->fetchUrl($path); - - if ($all) - { - $uri->setVar('all', 1); - } - - if ($participating) - { - $uri->setVar('participating', 1); - } - - if ($since) - { - $uri->setVar('since', $since->format(\DateTime::RFC3339)); - } - - if ($before) - { - $uri->setVar('before', $before->format(\DateTime::RFC3339)); - } - - return $this->processResponse($this->client->get($uri)); - } - - /** - * Mark as read. - * - * Marking a notification as “read” removes it from the default view on GitHub.com. - * - * @param boolean $unread Changes the unread status of the threads. - * @param boolean $read Inverse of “unread”. - * @param \DateTimeInterface $lastReadAt Describes the last point that notifications were checked. - * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. - * - * @return object - * - * @since 1.0 - */ - public function markRead($unread = true, $read = true, \DateTimeInterface $lastReadAt = null) - { - // Build the request path. - $path = '/notifications'; - - $data = [ - 'unread' => $unread, - 'read' => $read, - ]; - - if ($lastReadAt) - { - $data['last_read_at'] = $lastReadAt->format(\DateTime::RFC3339); - } - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), json_encode($data)), - 205 - ); - } - - /** - * Mark notifications as read in a repository. - * - * Marking all notifications in a repository as “read” removes them from the default view on GitHub.com. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param boolean $unread Changes the unread status of the threads. - * @param boolean $read Inverse of “unread”. - * @param \DateTimeInterface $lastReadAt Describes the last point that notifications were checked. - * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. - * - * @return object - * - * @since 1.0 - */ - public function markReadRepository($owner, $repo, $unread, $read, \DateTimeInterface $lastReadAt = null) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/notifications'; - - $data = [ - 'unread' => $unread, - 'read' => $read, - ]; - - if ($lastReadAt) - { - $data['last_read_at'] = $lastReadAt->format(\DateTime::RFC3339); - } - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), json_encode($data)), - 205 - ); - } - - /** - * View a single thread. - * - * @param integer $id The thread id. - * - * @return object - * - * @since 1.0 - */ - public function viewThread($id) - { - // Build the request path. - $path = '/notifications/threads/' . $id; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Mark a thread as read. - * - * @param integer $id The thread id. - * @param boolean $unread Changes the unread status of the threads. - * @param boolean $read Inverse of “unread”. - * - * @return object - * - * @since 1.0 - */ - public function markReadThread($id, $unread = true, $read = true) - { - // Build the request path. - $path = '/notifications/threads/' . $id; - - $data = [ - 'unread' => $unread, - 'read' => $read, - ]; - - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), json_encode($data)), - 205 - ); - } - - /** - * Get a Thread Subscription. - * - * This checks to see if the current user is subscribed to a thread. - * You can also get a Repository subscription. - * - * @param integer $id The thread id. - * - * @return object - * - * @since 1.0 - */ - public function getThreadSubscription($id) - { - // Build the request path. - $path = '/notifications/threads/' . $id . '/subscription'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Set a Thread Subscription. - * - * This lets you subscribe to a thread, or ignore it. Subscribing to a thread is unnecessary - * if the user is already subscribed to the repository. Ignoring a thread will mute all - * future notifications (until you comment or get @mentioned). - * - * @param integer $id The thread id. - * @param boolean $subscribed Determines if notifications should be received from this thread. - * @param boolean $ignored Determines if all notifications should be blocked from this thread. - * - * @return object - * - * @since 1.0 - */ - public function setThreadSubscription($id, $subscribed, $ignored) - { - // Build the request path. - $path = '/notifications/threads/' . $id . '/subscription'; - - $data = [ - 'subscribed' => $subscribed, - 'ignored' => $ignored, - ]; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), json_encode($data)) - ); - } - - /** - * Delete a Thread Subscription. - * - * @param integer $id The thread id. - * - * @return object - * - * @since 1.0 - */ - public function deleteThreadSubscription($id) - { - // Build the request path. - $path = '/notifications/threads/' . $id . '/subscription'; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + /** + * List your notifications. + * + * List all notifications for the current user, grouped by repository. + * + * @param boolean $all True to show notifications marked as read. + * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. + * @param \DateTimeInterface $since Only show notifications updated after the given time. + * @param \DateTimeInterface $before Only show notifications updated before the given time. + * + * @return object + * + * @since 1.0 + */ + public function getList($all = true, $participating = true, \DateTimeInterface $since = null, \DateTimeInterface $before = null) + { + // Build the request path. + $path = '/notifications'; + + $uri = $this->fetchUrl($path); + + if ($all) { + $uri->setVar('all', 1); + } + + if ($participating) { + $uri->setVar('participating', 1); + } + + if ($since) { + $uri->setVar('since', $since->format(\DateTime::RFC3339)); + } + + if ($before) { + $uri->setVar('before', $before->format(\DateTime::RFC3339)); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * List your notifications in a repository. + * + * List all notifications for the current user. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param boolean $all True to show notifications marked as read. + * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. + * @param \DateTimeInterface $since Only show notifications updated after the given time. + * @param \DateTimeInterface $before Only show notifications updated before the given time. + * + * @return object + * + * @since 1.0 + */ + public function getListRepository( + $owner, + $repo, + $all = true, + $participating = true, + \DateTimeInterface $since = null, + \DateTimeInterface $before = null + ) { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/notifications'; + + $uri = $this->fetchUrl($path); + + if ($all) { + $uri->setVar('all', 1); + } + + if ($participating) { + $uri->setVar('participating', 1); + } + + if ($since) { + $uri->setVar('since', $since->format(\DateTime::RFC3339)); + } + + if ($before) { + $uri->setVar('before', $before->format(\DateTime::RFC3339)); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * Mark as read. + * + * Marking a notification as “read” removes it from the default view on GitHub.com. + * + * @param boolean $unread Changes the unread status of the threads. + * @param boolean $read Inverse of “unread”. + * @param \DateTimeInterface $lastReadAt Describes the last point that notifications were checked. + * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. + * + * @return object + * + * @since 1.0 + */ + public function markRead($unread = true, $read = true, \DateTimeInterface $lastReadAt = null) + { + // Build the request path. + $path = '/notifications'; + + $data = [ + 'unread' => $unread, + 'read' => $read, + ]; + + if ($lastReadAt) { + $data['last_read_at'] = $lastReadAt->format(\DateTime::RFC3339); + } + + return $this->processResponse( + $this->client->put($this->fetchUrl($path), json_encode($data)), + 205 + ); + } + + /** + * Mark notifications as read in a repository. + * + * Marking all notifications in a repository as “read” removes them from the default view on GitHub.com. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param boolean $unread Changes the unread status of the threads. + * @param boolean $read Inverse of “unread”. + * @param \DateTimeInterface $lastReadAt Describes the last point that notifications were checked. + * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. + * + * @return object + * + * @since 1.0 + */ + public function markReadRepository($owner, $repo, $unread, $read, \DateTimeInterface $lastReadAt = null) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/notifications'; + + $data = [ + 'unread' => $unread, + 'read' => $read, + ]; + + if ($lastReadAt) { + $data['last_read_at'] = $lastReadAt->format(\DateTime::RFC3339); + } + + return $this->processResponse( + $this->client->put($this->fetchUrl($path), json_encode($data)), + 205 + ); + } + + /** + * View a single thread. + * + * @param integer $id The thread id. + * + * @return object + * + * @since 1.0 + */ + public function viewThread($id) + { + // Build the request path. + $path = '/notifications/threads/' . $id; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Mark a thread as read. + * + * @param integer $id The thread id. + * @param boolean $unread Changes the unread status of the threads. + * @param boolean $read Inverse of “unread”. + * + * @return object + * + * @since 1.0 + */ + public function markReadThread($id, $unread = true, $read = true) + { + // Build the request path. + $path = '/notifications/threads/' . $id; + + $data = [ + 'unread' => $unread, + 'read' => $read, + ]; + + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), json_encode($data)), + 205 + ); + } + + /** + * Get a Thread Subscription. + * + * This checks to see if the current user is subscribed to a thread. + * You can also get a Repository subscription. + * + * @param integer $id The thread id. + * + * @return object + * + * @since 1.0 + */ + public function getThreadSubscription($id) + { + // Build the request path. + $path = '/notifications/threads/' . $id . '/subscription'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Set a Thread Subscription. + * + * This lets you subscribe to a thread, or ignore it. Subscribing to a thread is unnecessary + * if the user is already subscribed to the repository. Ignoring a thread will mute all + * future notifications (until you comment or get @mentioned). + * + * @param integer $id The thread id. + * @param boolean $subscribed Determines if notifications should be received from this thread. + * @param boolean $ignored Determines if all notifications should be blocked from this thread. + * + * @return object + * + * @since 1.0 + */ + public function setThreadSubscription($id, $subscribed, $ignored) + { + // Build the request path. + $path = '/notifications/threads/' . $id . '/subscription'; + + $data = [ + 'subscribed' => $subscribed, + 'ignored' => $ignored, + ]; + + return $this->processResponse( + $this->client->put($this->fetchUrl($path), json_encode($data)) + ); + } + + /** + * Delete a Thread Subscription. + * + * @param integer $id The thread id. + * + * @return object + * + * @since 1.0 + */ + public function deleteThreadSubscription($id) + { + // Build the request path. + $path = '/notifications/threads/' . $id . '/subscription'; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } } diff --git a/src/Package/Activity/Starring.php b/src/Package/Activity/Starring.php index 286278ce..1d6cb62c 100644 --- a/src/Package/Activity/Starring.php +++ b/src/Package/Activity/Starring.php @@ -19,155 +19,152 @@ */ class Starring extends AbstractPackage { - /** - * List Stargazers. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return mixed - * - * @since 1.0 - */ - public function getList($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/stargazers'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List repositories being starred. - * - * List repositories being starred by a user. - * - * @param string $user User name. - * @param string $sort One of `created` (when the repository was starred) or `updated` (when it was last pushed to). - * @param string $direction One of `asc` (ascending) or `desc` (descending). - * - * @return object - * - * @since 1.0 - * @throws \InvalidArgumentException - */ - public function getRepositories($user = '', $sort = 'created', $direction = 'desc') - { - $allowedSort = ['created', 'updated']; - $allowedDir = ['asc', 'desc']; - - if (!\in_array($sort, $allowedSort)) - { - throw new \InvalidArgumentException( - sprintf( - 'The sorting value is invalid. Allowed values are: %s', - implode(', ', $allowedSort) - ) - ); - } - - if (!\in_array($direction, $allowedDir)) - { - throw new \InvalidArgumentException( - sprintf( - 'The direction value is invalid. Allowed values are: %s', - implode(', ', $allowedDir) - ) - ); - } - - // Build the request path. - $path = ($user) - ? '/users/' . $user . '/starred' - : '/user/starred'; - - $uri = $this->fetchUrl($path); - $uri->setVar('sort', $sort); - $uri->setVar('direction', $direction); - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Check if you are starring a repository. - * - * Requires for the user to be authenticated. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return boolean - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function check($owner, $repo) - { - // Build the request path. - $path = '/user/starred/' . $owner . '/' . $repo; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->code) - { - case '204' : - // This repository is watched by you. - return true; - - case '404' : - // This repository is not watched by you. - return false; - } - - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - - /** - * Star a repository. - * - * Requires for the user to be authenticated. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function star($owner, $repo) - { - // Build the request path. - $path = '/user/starred/' . $owner . '/' . $repo; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), ''), - 204 - ); - } - - /** - * Unstar a repository. - * - * Requires for the user to be authenticated. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function unstar($owner, $repo) - { - // Build the request path. - $path = '/user/starred/' . $owner . '/' . $repo; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + /** + * List Stargazers. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return mixed + * + * @since 1.0 + */ + public function getList($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/stargazers'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List repositories being starred. + * + * List repositories being starred by a user. + * + * @param string $user User name. + * @param string $sort One of `created` (when the repository was starred) or `updated` (when it was last pushed to). + * @param string $direction One of `asc` (ascending) or `desc` (descending). + * + * @return object + * + * @since 1.0 + * @throws \InvalidArgumentException + */ + public function getRepositories($user = '', $sort = 'created', $direction = 'desc') + { + $allowedSort = ['created', 'updated']; + $allowedDir = ['asc', 'desc']; + + if (!\in_array($sort, $allowedSort)) { + throw new \InvalidArgumentException( + sprintf( + 'The sorting value is invalid. Allowed values are: %s', + implode(', ', $allowedSort) + ) + ); + } + + if (!\in_array($direction, $allowedDir)) { + throw new \InvalidArgumentException( + sprintf( + 'The direction value is invalid. Allowed values are: %s', + implode(', ', $allowedDir) + ) + ); + } + + // Build the request path. + $path = ($user) + ? '/users/' . $user . '/starred' + : '/user/starred'; + + $uri = $this->fetchUrl($path); + $uri->setVar('sort', $sort); + $uri->setVar('direction', $direction); + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * Check if you are starring a repository. + * + * Requires for the user to be authenticated. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return boolean + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function check($owner, $repo) + { + // Build the request path. + $path = '/user/starred/' . $owner . '/' . $repo; + + $response = $this->client->get($this->fetchUrl($path)); + + switch ($response->code) { + case '204': + // This repository is watched by you. + return true; + + case '404': + // This repository is not watched by you. + return false; + } + + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + + /** + * Star a repository. + * + * Requires for the user to be authenticated. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function star($owner, $repo) + { + // Build the request path. + $path = '/user/starred/' . $owner . '/' . $repo; + + return $this->processResponse( + $this->client->put($this->fetchUrl($path), ''), + 204 + ); + } + + /** + * Unstar a repository. + * + * Requires for the user to be authenticated. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function unstar($owner, $repo) + { + // Build the request path. + $path = '/user/starred/' . $owner . '/' . $repo; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } } diff --git a/src/Package/Activity/Watching.php b/src/Package/Activity/Watching.php index 30e57543..32736ed7 100644 --- a/src/Package/Activity/Watching.php +++ b/src/Package/Activity/Watching.php @@ -19,194 +19,193 @@ */ class Watching extends AbstractPackage { - /** - * List watchers - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return mixed - * - * @since 1.0 - */ - public function getList($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/subscribers'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List repositories being watched. - * - * List repositories being watched by a user. - * - * @param string $user User name. - * - * @return mixed - * - * @since 1.0 - */ - public function getRepositories($user = '') - { - // Build the request path. - $path = ($user) - ? '/users/' . $user . '/subscriptions' - : '/user/subscriptions'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Get a Repository Subscription. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function getSubscription($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/subscription'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Set a Repository Subscription. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param boolean $subscribed Determines if notifications should be received from this thread. - * @param boolean $ignored Determines if all notifications should be blocked from this thread. - * - * @return object - * - * @since 1.0 - */ - public function setSubscription($owner, $repo, $subscribed, $ignored) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/subscription'; - - $data = [ - 'subscribed' => $subscribed, - 'ignored' => $ignored, - ]; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), json_encode($data)) - ); - } - - /** - * Delete a Repository Subscription. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function deleteSubscription($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/subscription'; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * Check if you are watching a repository (LEGACY). - * - * Requires for the user to be authenticated. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return boolean - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function check($owner, $repo) - { - // Build the request path. - $path = '/user/subscriptions/' . $owner . '/' . $repo; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->code) - { - case '204' : - // This repository is watched by you. - return true; - - case '404' : - // This repository is not watched by you. - return false; - } - - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - - /** - * Watch a repository (LEGACY). - * - * Requires for the user to be authenticated. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function watch($owner, $repo) - { - // Build the request path. - $path = '/user/subscriptions/' . $owner . '/' . $repo; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), ''), - 204 - ); - } - - /** - * Stop watching a repository (LEGACY). - * - * Requires for the user to be authenticated. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function unwatch($owner, $repo) - { - // Build the request path. - $path = '/user/subscriptions/' . $owner . '/' . $repo; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + /** + * List watchers + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return mixed + * + * @since 1.0 + */ + public function getList($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/subscribers'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List repositories being watched. + * + * List repositories being watched by a user. + * + * @param string $user User name. + * + * @return mixed + * + * @since 1.0 + */ + public function getRepositories($user = '') + { + // Build the request path. + $path = ($user) + ? '/users/' . $user . '/subscriptions' + : '/user/subscriptions'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Get a Repository Subscription. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function getSubscription($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/subscription'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Set a Repository Subscription. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param boolean $subscribed Determines if notifications should be received from this thread. + * @param boolean $ignored Determines if all notifications should be blocked from this thread. + * + * @return object + * + * @since 1.0 + */ + public function setSubscription($owner, $repo, $subscribed, $ignored) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/subscription'; + + $data = [ + 'subscribed' => $subscribed, + 'ignored' => $ignored, + ]; + + return $this->processResponse( + $this->client->put($this->fetchUrl($path), json_encode($data)) + ); + } + + /** + * Delete a Repository Subscription. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function deleteSubscription($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/subscription'; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * Check if you are watching a repository (LEGACY). + * + * Requires for the user to be authenticated. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return boolean + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function check($owner, $repo) + { + // Build the request path. + $path = '/user/subscriptions/' . $owner . '/' . $repo; + + $response = $this->client->get($this->fetchUrl($path)); + + switch ($response->code) { + case '204': + // This repository is watched by you. + return true; + + case '404': + // This repository is not watched by you. + return false; + } + + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + + /** + * Watch a repository (LEGACY). + * + * Requires for the user to be authenticated. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function watch($owner, $repo) + { + // Build the request path. + $path = '/user/subscriptions/' . $owner . '/' . $repo; + + return $this->processResponse( + $this->client->put($this->fetchUrl($path), ''), + 204 + ); + } + + /** + * Stop watching a repository (LEGACY). + * + * Requires for the user to be authenticated. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function unwatch($owner, $repo) + { + // Build the request path. + $path = '/user/subscriptions/' . $owner . '/' . $repo; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } } diff --git a/src/Package/Authorization.php b/src/Package/Authorization.php index d9b141eb..670e906c 100644 --- a/src/Package/Authorization.php +++ b/src/Package/Authorization.php @@ -23,359 +23,347 @@ */ class Authorization extends AbstractPackage { - /** - * Method to create an authorization. - * - * @param array $scopes A list of scopes that this authorization is in. - * @param string $note A note to remind you what the OAuth token is for. - * @param string $url A URL to remind you what app the OAuth token is for. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function create(array $scopes = [], $note = '', $url = '') - { - // Build the request path. - $path = '/authorizations'; - - $data = json_encode( - ['scopes' => $scopes, 'note' => $note, 'note_url' => $url] - ); - - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } - - /** - * Method to delete an authorization - * - * @param integer $id ID of the authorization to delete - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function delete($id) - { - // Build the request path. - $path = '/authorizations/' . $id; - - // Send the request. - return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } - - /** - * Delete a grant - * - * Deleting an OAuth application's grant will also delete all OAuth tokens associated with the application for your user. - * - * @param integer $id ID of the authorization to delete - * - * @return object - * - * @since 1.5.0 - * @throws \DomainException - */ - public function deleteGrant($id) - { - // Build the request path. - $path = '/authorizations/grants/' . $id; - - // Send the request. - return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } - - /** - * Method to edit an authorization. - * - * @param integer $id ID of the authorization to edit - * @param array $scopes Replaces the authorization scopes with these. - * @param array $addScopes A list of scopes to add to this authorization. - * @param array $removeScopes A list of scopes to remove from this authorization. - * @param string $note A note to remind you what the OAuth token is for. - * @param string $url A URL to remind you what app the OAuth token is for. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - * @throws \RuntimeException - */ - public function edit($id, array $scopes = [], array $addScopes = [], array $removeScopes = [], $note = '', $url = '') - { - // Check if more than one scopes array contains data - $scopesCount = 0; - $scope = ''; - $scopeData = ''; - - if (!empty($scopes)) - { - $scope = 'scopes'; - $scopeData = $scopes; - $scopesCount++; - } - - if (!empty($addScopes)) - { - $scope = 'add_scopes'; - $scopeData = $addScopes; - $scopesCount++; - } - - if (!empty($removeScopes)) - { - $scope = 'remove_scopes'; - $scopeData = $removeScopes; - $scopesCount++; - } - - // Only allowed to send data for one scope parameter - if ($scopesCount >= 2) - { - throw new \RuntimeException('You can only send one scope key in this request.'); - } - - // Build the request path. - $path = '/authorizations/' . $id; - - $data = json_encode( - [ - $scope => $scopeData, - 'note' => $note, - 'note_url' => $url, - ] - ); - - // Send the request. - return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); - } - - /** - * Method to get details about an authorised application for the authenticated user. - * - * @param integer $id ID of the authorization to retrieve - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($id) - { - // Build the request path. - $path = '/authorizations/' . $id; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Get a single grant - * - * @param integer $id ID of the authorization to retrieve - * - * @return object - * - * @since 1.5.0 - * @throws \DomainException - */ - public function getGrant($id) - { - // Build the request path. - $path = '/authorizations/grants/' . $id; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Method to get the authorised applications for the authenticated user. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getList() - { - // Build the request path. - $path = '/authorizations'; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * List your grants. - * - * You can use this API to list the set of OAuth applications that have been granted access to your account. - * - * @return object - * - * @since 1.5.0 - * @throws \DomainException - */ - public function getListGrants() - { - // Build the request path. - $path = '/authorizations/grants'; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Method to get the rate limit for the authenticated user. - * - * @return object Returns an object with the properties of `limit` and `remaining`. If there is no limit, the - * `limit` property will be false. - * - * @since 1.0 - * @throws UnexpectedResponseException - */ - public function getRateLimit() - { - // Build the request path. - $path = '/rate_limit'; - - // Send the request. - $response = $this->client->get($this->fetchUrl($path)); - - // Validate the response code. - if ($response->code != 200) - { - if ($response->code == 404) - { - // Unlimited rate for Github Enterprise sites and trusted users. - return (object) ['limit' => false, 'remaining' => null]; - } - - // Decode the error response and throw an exception. - $error = json_decode($response->body); - - throw new UnexpectedResponseException($response, $error->message, $response->code); - } - - return json_decode($response->body); - } - - /** - * 1. Request authorization on GitHub. - * - * @param string $clientId The client ID you received from GitHub when you registered. - * @param string $redirectUri URL in your app where users will be sent after authorization. - * @param string $scope Comma separated list of scopes. - * @param string $state An unguessable random string. It is used to protect against cross-site request forgery attacks. - * - * @return string - * - * @since 1.0 - */ - public function getAuthorizationLink($clientId, $redirectUri = '', $scope = '', $state = '') - { - $uri = new Uri('https://github.com/login/oauth/authorize'); - - $uri->setVar('client_id', $clientId); - - if ($redirectUri) - { - $uri->setVar('redirect_uri', urlencode($redirectUri)); - } - - if ($scope) - { - $uri->setVar('scope', $scope); - } - - if ($state) - { - $uri->setVar('state', $state); - } - - return (string) $uri; - } - - /** - * 2. Request the access token. - * - * @param string $clientId The client ID you received from GitHub when you registered. - * @param string $clientSecret The client secret you received from GitHub when you registered. - * @param string $code The code you received as a response to Step 1. - * @param string $redirectUri URL in your app where users will be sent after authorization. - * @param string $format The response format (json, xml, ). - * - * @return string - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function requestToken($clientId, $clientSecret, $code, $redirectUri = '', $format = '') - { - $uri = 'https://github.com/login/oauth/access_token'; - - $data = [ - 'client_id' => $clientId, - 'client_secret' => $clientSecret, - 'code' => $code, - ]; - - if ($redirectUri) - { - $data['redirect_uri'] = $redirectUri; - } - - $headers = []; - - switch ($format) - { - case 'json' : - $headers['Accept'] = 'application/json'; - - break; - - case 'xml' : - $headers['Accept'] = 'application/xml'; - - break; - - default : - if ($format) - { - throw new \UnexpectedValueException('Invalid format'); - } - - break; - } - - // Send the request. - return $this->processResponse( - $this->client->post($uri, $data, $headers), - 200 - ); - } - - /** - * Revoke a grant for an application - * - * OAuth application owners can revoke a grant for their OAuth application and a specific user. - * - * @param integer $clientId The application client ID - * @param integer $accessToken The access token to revoke - * - * @return object - * - * @since 1.5.0 - * @throws \DomainException - */ - public function revokeGrantForApplication($clientId, $accessToken) - { - // Build the request path. - $path = "/applications/$clientId/grants/$accessToken"; - - // Send the request. - return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } + /** + * Method to create an authorization. + * + * @param array $scopes A list of scopes that this authorization is in. + * @param string $note A note to remind you what the OAuth token is for. + * @param string $url A URL to remind you what app the OAuth token is for. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function create(array $scopes = [], $note = '', $url = '') + { + // Build the request path. + $path = '/authorizations'; + + $data = json_encode( + ['scopes' => $scopes, 'note' => $note, 'note_url' => $url] + ); + + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } + + /** + * Method to delete an authorization + * + * @param integer $id ID of the authorization to delete + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function delete($id) + { + // Build the request path. + $path = '/authorizations/' . $id; + + // Send the request. + return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); + } + + /** + * Delete a grant + * + * Deleting an OAuth application's grant will also delete all OAuth tokens associated with the application for your user. + * + * @param integer $id ID of the authorization to delete + * + * @return object + * + * @since 1.5.0 + * @throws \DomainException + */ + public function deleteGrant($id) + { + // Build the request path. + $path = '/authorizations/grants/' . $id; + + // Send the request. + return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); + } + + /** + * Method to edit an authorization. + * + * @param integer $id ID of the authorization to edit + * @param array $scopes Replaces the authorization scopes with these. + * @param array $addScopes A list of scopes to add to this authorization. + * @param array $removeScopes A list of scopes to remove from this authorization. + * @param string $note A note to remind you what the OAuth token is for. + * @param string $url A URL to remind you what app the OAuth token is for. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + * @throws \RuntimeException + */ + public function edit($id, array $scopes = [], array $addScopes = [], array $removeScopes = [], $note = '', $url = '') + { + // Check if more than one scopes array contains data + $scopesCount = 0; + $scope = ''; + $scopeData = ''; + + if (!empty($scopes)) { + $scope = 'scopes'; + $scopeData = $scopes; + $scopesCount++; + } + + if (!empty($addScopes)) { + $scope = 'add_scopes'; + $scopeData = $addScopes; + $scopesCount++; + } + + if (!empty($removeScopes)) { + $scope = 'remove_scopes'; + $scopeData = $removeScopes; + $scopesCount++; + } + + // Only allowed to send data for one scope parameter + if ($scopesCount >= 2) { + throw new \RuntimeException('You can only send one scope key in this request.'); + } + + // Build the request path. + $path = '/authorizations/' . $id; + + $data = json_encode( + [ + $scope => $scopeData, + 'note' => $note, + 'note_url' => $url, + ] + ); + + // Send the request. + return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); + } + + /** + * Method to get details about an authorised application for the authenticated user. + * + * @param integer $id ID of the authorization to retrieve + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($id) + { + // Build the request path. + $path = '/authorizations/' . $id; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Get a single grant + * + * @param integer $id ID of the authorization to retrieve + * + * @return object + * + * @since 1.5.0 + * @throws \DomainException + */ + public function getGrant($id) + { + // Build the request path. + $path = '/authorizations/grants/' . $id; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Method to get the authorised applications for the authenticated user. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getList() + { + // Build the request path. + $path = '/authorizations'; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * List your grants. + * + * You can use this API to list the set of OAuth applications that have been granted access to your account. + * + * @return object + * + * @since 1.5.0 + * @throws \DomainException + */ + public function getListGrants() + { + // Build the request path. + $path = '/authorizations/grants'; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Method to get the rate limit for the authenticated user. + * + * @return object Returns an object with the properties of `limit` and `remaining`. If there is no limit, the + * `limit` property will be false. + * + * @since 1.0 + * @throws UnexpectedResponseException + */ + public function getRateLimit() + { + // Build the request path. + $path = '/rate_limit'; + + // Send the request. + $response = $this->client->get($this->fetchUrl($path)); + + // Validate the response code. + if ($response->code != 200) { + if ($response->code == 404) { + // Unlimited rate for Github Enterprise sites and trusted users. + return (object) ['limit' => false, 'remaining' => null]; + } + + // Decode the error response and throw an exception. + $error = json_decode($response->body); + + throw new UnexpectedResponseException($response, $error->message, $response->code); + } + + return json_decode($response->body); + } + + /** + * 1. Request authorization on GitHub. + * + * @param string $clientId The client ID you received from GitHub when you registered. + * @param string $redirectUri URL in your app where users will be sent after authorization. + * @param string $scope Comma separated list of scopes. + * @param string $state An unguessable random string. It is used to protect against cross-site request forgery attacks. + * + * @return string + * + * @since 1.0 + */ + public function getAuthorizationLink($clientId, $redirectUri = '', $scope = '', $state = '') + { + $uri = new Uri('https://github.com/login/oauth/authorize'); + + $uri->setVar('client_id', $clientId); + + if ($redirectUri) { + $uri->setVar('redirect_uri', urlencode($redirectUri)); + } + + if ($scope) { + $uri->setVar('scope', $scope); + } + + if ($state) { + $uri->setVar('state', $state); + } + + return (string) $uri; + } + + /** + * 2. Request the access token. + * + * @param string $clientId The client ID you received from GitHub when you registered. + * @param string $clientSecret The client secret you received from GitHub when you registered. + * @param string $code The code you received as a response to Step 1. + * @param string $redirectUri URL in your app where users will be sent after authorization. + * @param string $format The response format (json, xml, ). + * + * @return string + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function requestToken($clientId, $clientSecret, $code, $redirectUri = '', $format = '') + { + $uri = 'https://github.com/login/oauth/access_token'; + + $data = [ + 'client_id' => $clientId, + 'client_secret' => $clientSecret, + 'code' => $code, + ]; + + if ($redirectUri) { + $data['redirect_uri'] = $redirectUri; + } + + $headers = []; + + switch ($format) { + case 'json': + $headers['Accept'] = 'application/json'; + + break; + + case 'xml': + $headers['Accept'] = 'application/xml'; + + break; + + default: + if ($format) { + throw new \UnexpectedValueException('Invalid format'); + } + + break; + } + + // Send the request. + return $this->processResponse( + $this->client->post($uri, $data, $headers), + 200 + ); + } + + /** + * Revoke a grant for an application + * + * OAuth application owners can revoke a grant for their OAuth application and a specific user. + * + * @param integer $clientId The application client ID + * @param integer $accessToken The access token to revoke + * + * @return object + * + * @since 1.5.0 + * @throws \DomainException + */ + public function revokeGrantForApplication($clientId, $accessToken) + { + // Build the request path. + $path = "/applications/$clientId/grants/$accessToken"; + + // Send the request. + return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); + } } diff --git a/src/Package/Data/Blobs.php b/src/Package/Data/Blobs.php index d34a020d..aa986277 100644 --- a/src/Package/Data/Blobs.php +++ b/src/Package/Data/Blobs.php @@ -23,52 +23,52 @@ */ class Blobs extends AbstractPackage { - /** - * Get a Blob. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param string $sha The commit SHA. - * - * @return object - * - * @since 1.0 - */ - public function get($owner, $repo, $sha) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/git/blobs/' . $sha; + /** + * Get a Blob. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param string $sha The commit SHA. + * + * @return object + * + * @since 1.0 + */ + public function get($owner, $repo, $sha) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/git/blobs/' . $sha; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Create a Blob. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param string $content The content of the blob. - * @param string $encoding The encoding to use. - * - * @return object - * - * @since 1.0 - */ - public function create($owner, $repo, $content, $encoding = 'utf-8') - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/git/blobs'; + /** + * Create a Blob. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param string $content The content of the blob. + * @param string $encoding The encoding to use. + * + * @return object + * + * @since 1.0 + */ + public function create($owner, $repo, $content, $encoding = 'utf-8') + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/git/blobs'; - $data = [ - 'content' => $content, - 'encoding' => $encoding, - ]; + $data = [ + 'content' => $content, + 'encoding' => $encoding, + ]; - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($data)), - 201 - ); - } + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($data)), + 201 + ); + } } diff --git a/src/Package/Data/Commits.php b/src/Package/Data/Commits.php index a3cb2725..2f481327 100644 --- a/src/Package/Data/Commits.php +++ b/src/Package/Data/Commits.php @@ -19,54 +19,54 @@ */ class Commits extends AbstractPackage { - /** - * Get a Commit. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha The commit SHA. - * - * @return object - */ - public function get($owner, $repo, $sha) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/git/commits/' . $sha; + /** + * Get a Commit. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha The commit SHA. + * + * @return object + */ + public function get($owner, $repo, $sha) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/git/commits/' . $sha; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Create a Commit. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $message The commit message. - * @param string $tree SHA of the tree object this commit points to. - * @param array $parents Array of the SHAs of the commits that were the parents of this commit. - * If omitted or empty, the commit will be written as a root commit. - * For a single parent, an array of one SHA should be provided. - * For a merge commit, an array of more than one should be provided. - * - * @since 1.0 - * - * @return object - */ - public function create($owner, $repo, $message, $tree, array $parents = []) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/git/commits'; + /** + * Create a Commit. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $message The commit message. + * @param string $tree SHA of the tree object this commit points to. + * @param array $parents Array of the SHAs of the commits that were the parents of this commit. + * If omitted or empty, the commit will be written as a root commit. + * For a single parent, an array of one SHA should be provided. + * For a merge commit, an array of more than one should be provided. + * + * @since 1.0 + * + * @return object + */ + public function create($owner, $repo, $message, $tree, array $parents = []) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/git/commits'; - $data = json_encode( - ['message' => $message, 'tree' => $tree, 'parents' => $parents] - ); + $data = json_encode( + ['message' => $message, 'tree' => $tree, 'parents' => $parents] + ); - // Send the request. - return $this->processResponse( - $response = $this->client->post($this->fetchUrl($path), $data), - 201 - ); - } + // Send the request. + return $this->processResponse( + $response = $this->client->post($this->fetchUrl($path), $data), + 201 + ); + } } diff --git a/src/Package/Data/Refs.php b/src/Package/Data/Refs.php index 18cf6333..03724086 100644 --- a/src/Package/Data/Refs.php +++ b/src/Package/Data/Refs.php @@ -19,141 +19,139 @@ */ class Refs extends AbstractPackage { - /** - * Get a Reference. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $ref The reference to get. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($user, $repo, $ref) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Get all References. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $namespace Optional sub-namespace to limit the returned references. - * @param integer $page Page to request - * @param integer $limit Number of results to return per page - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getList($user, $repo, $namespace = '', $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/git/refs'; - - if (!empty($namespace)) - { - $path .= '/' . $namespace; - } - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - } - - /** - * Create a Reference. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $ref The name of the fully qualified reference. - * @param string $sha The SHA1 value to set this reference to. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function create($user, $repo, $ref, $sha) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/git/refs'; - - // Build the request data. - $data = json_encode( - [ - 'ref' => $ref, - 'sha' => $sha, - ] - ); - - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } - - /** - * Update a Reference. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $ref The reference to update. - * @param string $sha The SHA1 value to set the reference to. - * @param boolean $force Whether the update should be forced. Default to false. - * - * @return object - * - * @since 1.0 - * @throws DomainException - */ - public function edit($user, $repo, $ref, $sha, $force = false) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref; - - // Create the data object. - $data = new \stdClass; - - // If a title is set add it to the data object. - if ($force) - { - $data->force = true; - } - - $data->sha = $sha; - - // Encode the request data. - $data = json_encode($data); - - // Send the request. - return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); - } - - /** - * Delete a Reference - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $ref The reference to update. - * - * @return object - * - * @since 1.0 - */ - public function delete($owner, $repo, $ref) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/git/refs/' . $ref; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + /** + * Get a Reference. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $ref The reference to get. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($user, $repo, $ref) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Get all References. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $namespace Optional sub-namespace to limit the returned references. + * @param integer $page Page to request + * @param integer $limit Number of results to return per page + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getList($user, $repo, $namespace = '', $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/git/refs'; + + if (!empty($namespace)) { + $path .= '/' . $namespace; + } + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); + } + + /** + * Create a Reference. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $ref The name of the fully qualified reference. + * @param string $sha The SHA1 value to set this reference to. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function create($user, $repo, $ref, $sha) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/git/refs'; + + // Build the request data. + $data = json_encode( + [ + 'ref' => $ref, + 'sha' => $sha, + ] + ); + + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } + + /** + * Update a Reference. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $ref The reference to update. + * @param string $sha The SHA1 value to set the reference to. + * @param boolean $force Whether the update should be forced. Default to false. + * + * @return object + * + * @since 1.0 + * @throws DomainException + */ + public function edit($user, $repo, $ref, $sha, $force = false) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref; + + // Create the data object. + $data = new \stdClass(); + + // If a title is set add it to the data object. + if ($force) { + $data->force = true; + } + + $data->sha = $sha; + + // Encode the request data. + $data = json_encode($data); + + // Send the request. + return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); + } + + /** + * Delete a Reference + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $ref The reference to update. + * + * @return object + * + * @since 1.0 + */ + public function delete($owner, $repo, $ref) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/git/refs/' . $ref; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } } diff --git a/src/Package/Data/Tags.php b/src/Package/Data/Tags.php index 76287210..415ec3e9 100644 --- a/src/Package/Data/Tags.php +++ b/src/Package/Data/Tags.php @@ -21,69 +21,69 @@ */ class Tags extends AbstractPackage { - /** - * Get a Tag. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha The SHA1 value to set the reference to. - * - * @since 1.0 - * - * @return object - */ - public function get($owner, $repo, $sha) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/git/tags/' . $sha; + /** + * Get a Tag. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha The SHA1 value to set the reference to. + * + * @since 1.0 + * + * @return object + */ + public function get($owner, $repo, $sha) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/git/tags/' . $sha; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Create a Tag Object - * - * Note that creating a tag object does not create the reference that makes a tag in Git. - * If you want to create an annotated tag in Git, you have to do this call to create the tag object, - * and then create the refs/tags/[tag] reference. If you want to create a lightweight tag, - * you simply have to create the reference - this call would be unnecessary. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $tag The tag string. - * @param string $message The tag message. - * @param string $object The SHA of the git object this is tagging. - * @param string $type The type of the object we’re tagging. Normally this is a commit but it can also be a tree or a blob. - * @param string $taggerName The name of the author of the tag. - * @param string $taggerEmail The email of the author of the tag. - * @param string $taggerDate Timestamp of when this object was tagged. - * - * @return object - * - * @since 1.0 - */ - public function create($owner, $repo, $tag, $message, $object, $type, $taggerName, $taggerEmail, $taggerDate) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/git/tags'; + /** + * Create a Tag Object + * + * Note that creating a tag object does not create the reference that makes a tag in Git. + * If you want to create an annotated tag in Git, you have to do this call to create the tag object, + * and then create the refs/tags/[tag] reference. If you want to create a lightweight tag, + * you simply have to create the reference - this call would be unnecessary. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $tag The tag string. + * @param string $message The tag message. + * @param string $object The SHA of the git object this is tagging. + * @param string $type The type of the object we’re tagging. Normally this is a commit but it can also be a tree or a blob. + * @param string $taggerName The name of the author of the tag. + * @param string $taggerEmail The email of the author of the tag. + * @param string $taggerDate Timestamp of when this object was tagged. + * + * @return object + * + * @since 1.0 + */ + public function create($owner, $repo, $tag, $message, $object, $type, $taggerName, $taggerEmail, $taggerDate) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/git/tags'; - $data = [ - 'tag' => $tag, - 'message' => $message, - 'object' => $object, - 'type' => $type, - 'tagger' => [ - 'name' => $taggerName, - 'email' => $taggerEmail, - 'date' => $taggerDate, - ], - ]; + $data = [ + 'tag' => $tag, + 'message' => $message, + 'object' => $object, + 'type' => $type, + 'tagger' => [ + 'name' => $taggerName, + 'email' => $taggerEmail, + 'date' => $taggerDate, + ], + ]; - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($data)), - 201 - ); - } + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($data)), + 201 + ); + } } diff --git a/src/Package/Data/Trees.php b/src/Package/Data/Trees.php index f94e0488..04d8f769 100644 --- a/src/Package/Data/Trees.php +++ b/src/Package/Data/Trees.php @@ -19,97 +19,96 @@ */ class Trees extends AbstractPackage { - /** - * Get a Tree - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha The SHA1 value to set the reference to. - * - * @since 1.0 - * - * @return object - */ - public function get($owner, $repo, $sha) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/git/trees/' . $sha; + /** + * Get a Tree + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha The SHA1 value to set the reference to. + * + * @since 1.0 + * + * @return object + */ + public function get($owner, $repo, $sha) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/git/trees/' . $sha; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Get a Tree Recursively - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha The SHA1 value to set the reference to. - * - * @since 1.0 - * - * @return object - */ - public function getRecursively($owner, $repo, $sha) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/git/trees/' . $sha . '?recursive=1'; + /** + * Get a Tree Recursively + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha The SHA1 value to set the reference to. + * + * @since 1.0 + * + * @return object + */ + public function getRecursively($owner, $repo, $sha) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/git/trees/' . $sha . '?recursive=1'; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Create a Tree. - * - * The tree creation API will take nested entries as well. If both a tree and a nested path - * modifying that tree are specified, it will overwrite the contents of that tree with the - * new path contents and write a new tree out. - * - * Parameters for the tree: - * - * tree.path - * String of the file referenced in the tree - * tree.mode - * String of the file mode - one of 100644 for file (blob), 100755 for executable (blob), - * 040000 for subdirectory (tree), 160000 for submodule (commit) or 120000 for a blob - * that specifies the path of a symlink - * tree.type - * String of blob, tree, commit - * tree.sha - * String of SHA1 checksum ID of the object in the tree - * tree.content - * String of content you want this file to have - GitHub will write this blob out and use - * that SHA for this entry. Use either this or tree.sha - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param array $tree Array of Hash objects (of path, mode, type and sha) specifying a tree structure - * @param string $baseTree The SHA1 of the tree you want to update with new data. - * - * @return object - * - * @since 1.0 - */ - public function create($owner, $repo, $tree, $baseTree = '') - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/git/trees'; + /** + * Create a Tree. + * + * The tree creation API will take nested entries as well. If both a tree and a nested path + * modifying that tree are specified, it will overwrite the contents of that tree with the + * new path contents and write a new tree out. + * + * Parameters for the tree: + * + * tree.path + * String of the file referenced in the tree + * tree.mode + * String of the file mode - one of 100644 for file (blob), 100755 for executable (blob), + * 040000 for subdirectory (tree), 160000 for submodule (commit) or 120000 for a blob + * that specifies the path of a symlink + * tree.type + * String of blob, tree, commit + * tree.sha + * String of SHA1 checksum ID of the object in the tree + * tree.content + * String of content you want this file to have - GitHub will write this blob out and use + * that SHA for this entry. Use either this or tree.sha + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param array $tree Array of Hash objects (of path, mode, type and sha) specifying a tree structure + * @param string $baseTree The SHA1 of the tree you want to update with new data. + * + * @return object + * + * @since 1.0 + */ + public function create($owner, $repo, $tree, $baseTree = '') + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/git/trees'; - $data = []; + $data = []; - $data['tree'] = $tree; + $data['tree'] = $tree; - if ($baseTree) - { - $data['base_tree'] = $baseTree; - } + if ($baseTree) { + $data['base_tree'] = $baseTree; + } - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($data)), - 201 - ); - } + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($data)), + 201 + ); + } } diff --git a/src/Package/Emojis.php b/src/Package/Emojis.php index c5139e59..846331c4 100644 --- a/src/Package/Emojis.php +++ b/src/Package/Emojis.php @@ -19,20 +19,20 @@ */ class Emojis extends AbstractPackage { - /** - * Lists all the emojis available to use on GitHub. - * - * @return array - * - * @since 1.1 - * @throws \DomainException - */ - public function getList() - { - // Build the request path. - $path = '/emojis'; + /** + * Lists all the emojis available to use on GitHub. + * + * @return array + * + * @since 1.1 + * @throws \DomainException + */ + public function getList() + { + // Build the request path. + $path = '/emojis'; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } } diff --git a/src/Package/Gists.php b/src/Package/Gists.php index 5f1ad4f3..240a4ff1 100644 --- a/src/Package/Gists.php +++ b/src/Package/Gists.php @@ -22,411 +22,397 @@ */ class Gists extends AbstractPackage { - /** - * Create a gist. - * - * @param mixed $files Either an array of file paths or a single file path as a string. - * @param boolean $public True if the gist should be public. - * @param string $description The optional description of the gist. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function create($files, $public = false, $description = null) - { - // Build the request path. - $path = '/gists'; - - // Build the request data. - $data = json_encode( - [ - 'files' => $this->buildFileData((array) $files), - 'public' => (bool) $public, - 'description' => $description, - ] - ); - - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } - - /** - * Delete a gist. - * - * @param integer $gistId The gist number. - * - * @return void - * - * @since 1.0 - * @throws \DomainException - */ - public function delete($gistId) - { - // Build the request path. - $path = '/gists/' . (int) $gistId; - - // Send the request. - $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } - - /** - * Edit a gist. - * - * @param integer $gistId The gist number. - * @param mixed $files Either an array of file paths or a single file path as a string. - * @param boolean $public True if the gist should be public. - * @param string $description The description of the gist. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function edit($gistId, $files = null, $public = null, $description = null) - { - // Build the request path. - $path = '/gists/' . (int) $gistId; - - // Create the data object. - $data = new \stdClass; - - // If a description is set add it to the data object. - if (isset($description)) - { - $data->description = $description; - } - - // If the public flag is set add it to the data object. - if (isset($public)) - { - $data->public = $public; - } - - // If a state is set add it to the data object. - if (isset($files)) - { - $data->files = $this->buildFileData((array) $files); - } - - // Encode the request data. - $data = json_encode($data); - - // Send the request. - return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); - } - - /** - * Fork a gist. - * - * @param integer $gistId The gist number. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function fork($gistId) - { - // Build the request path. - $path = '/gists/' . (int) $gistId . '/forks'; - - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), ''), 201); - } - - /** - * Get a single gist. - * - * @param integer $gistId The gist number. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($gistId) - { - // Build the request path. - $path = '/gists/' . (int) $gistId; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * List gist commits. - * - * @param integer $gistId The gist number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return array - * - * @since 1.4.0 - * @throws \DomainException - */ - public function getCommitList($gistId, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/gists/' . (int) $gistId . '/commits'; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - } - - /** - * List gist forks. - * - * @param integer $gistId The gist number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return array - * - * @since 1.4.0 - * @throws \DomainException - */ - public function getForkList($gistId, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/gists/' . (int) $gistId . '/forks'; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - } - - /** - * List gists. - * - * If a user is authenticated it will return the user's gists, otherwise - * it will return all public gists. - * - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return array - * - * @since 1.0 - * @throws \DomainException - */ - public function getList($page = 0, $limit = 0) - { - // Build the request path. - $path = '/gists'; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - } - - /** - * List a user’s gists. - * - * @param string $user The name of the GitHub user from which to list gists. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * @param \DateTime $since Only gists updated at or after this time are returned. - * - * @return array - * - * @since 1.0 - * @throws \DomainException - */ - public function getListByUser($user, $page = 0, $limit = 0, \DateTime $since = null) - { - // Build the request path. - $uri = $this->fetchUrl('/users/' . $user . '/gists', $page, $limit); - - if ($since) - { - $uri->setVar('since', $since->format(\DateTime::RFC3339)); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * List all public gists. - * - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * @param \DateTime $since Only gists updated at or after this time are returned. - * - * @return array - * - * @since 1.0 - * @throws \DomainException - */ - public function getListPublic($page = 0, $limit = 0, \DateTime $since = null) - { - // Build the request path. - $uri = $this->fetchUrl('/gists/public', $page, $limit); - - if ($since) - { - $uri->setVar('since', $since->format(\DateTime::RFC3339)); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * List starred gists. - * - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * @param \DateTime $since Only gists updated at or after this time are returned. - * - * @return array - * - * @since 1.0 - * @throws \DomainException - */ - public function getListStarred($page = 0, $limit = 0, \DateTime $since = null) - { - // Build the request path. - $uri = $this->fetchUrl('/gists/starred', $page, $limit); - - if ($since) - { - $uri->setVar('since', $since->format(\DateTime::RFC3339)); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Get a specific revision of a gist. - * - * @param integer $gistId The gist number. - * @param string $sha The SHA for the revision to get. - * - * @return object - * - * @since 1.4.0 - * @throws \DomainException - */ - public function getRevision($gistId, $sha) - { - // Build the request path. - $path = '/gists/' . (int) $gistId . '/' . $sha; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Check if a gist is starred. - * - * @param integer $gistId The gist number. - * - * @return boolean True if gist is starred - * - * @since 1.0 - * @throws UnexpectedResponseException - */ - public function isStarred($gistId) - { - // Build the request path. - $path = '/gists/' . (int) $gistId . '/star'; - - // Send the request. - $response = $this->client->get($this->fetchUrl($path)); - - // Validate the response code. - if ($response->code == 204) - { - return true; - } - - if ($response->code == 404) - { - return false; - } - - // Decode the error response and throw an exception. - $error = json_decode($response->body); - $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; - - throw new UnexpectedResponseException($response, $message, $response->code); - } - - /** - * Star a gist. - * - * @param integer $gistId The gist number. - * - * @return void - * - * @since 1.0 - * @throws \DomainException - */ - public function star($gistId) - { - // Build the request path. - $path = '/gists/' . (int) $gistId . '/star'; - - // Send the request. - $this->processResponse($this->client->put($this->fetchUrl($path), ''), 204); - } - - /** - * Unstar a gist. - * - * @param integer $gistId The gist number. - * - * @return void - * - * @since 1.0 - * @throws \DomainException - */ - public function unstar($gistId) - { - // Build the request path. - $path = '/gists/' . (int) $gistId . '/star'; - - // Send the request. - $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } - - /** - * Method to fetch a data array for transmitting to the GitHub API for a list of files based on - * an input array of file paths or filename and content pairs. - * - * @param array $files The list of file paths or filenames and content. - * - * @return array - * - * @since 1.0 - * @throws \InvalidArgumentException - */ - protected function buildFileData(array $files) - { - $data = []; - - foreach ($files as $key => $file) - { - if (!is_numeric($key)) - { - // If the key isn't numeric, then we are dealing with a file whose content has been supplied - $data[$key] = ['content' => $file]; - } - elseif (!file_exists($file)) - { - // Otherwise, we have been given a path and we have to load the content - // Verify that the each file exists. - throw new \InvalidArgumentException('The file ' . $file . ' does not exist.'); - } - else - { - $data[basename($file)] = ['content' => file_get_contents($file)]; - } - } - - return $data; - } + /** + * Create a gist. + * + * @param mixed $files Either an array of file paths or a single file path as a string. + * @param boolean $public True if the gist should be public. + * @param string $description The optional description of the gist. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function create($files, $public = false, $description = null) + { + // Build the request path. + $path = '/gists'; + + // Build the request data. + $data = json_encode( + [ + 'files' => $this->buildFileData((array) $files), + 'public' => (bool) $public, + 'description' => $description, + ] + ); + + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } + + /** + * Delete a gist. + * + * @param integer $gistId The gist number. + * + * @return void + * + * @since 1.0 + * @throws \DomainException + */ + public function delete($gistId) + { + // Build the request path. + $path = '/gists/' . (int) $gistId; + + // Send the request. + $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); + } + + /** + * Edit a gist. + * + * @param integer $gistId The gist number. + * @param mixed $files Either an array of file paths or a single file path as a string. + * @param boolean $public True if the gist should be public. + * @param string $description The description of the gist. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function edit($gistId, $files = null, $public = null, $description = null) + { + // Build the request path. + $path = '/gists/' . (int) $gistId; + + // Create the data object. + $data = new \stdClass(); + + // If a description is set add it to the data object. + if (isset($description)) { + $data->description = $description; + } + + // If the public flag is set add it to the data object. + if (isset($public)) { + $data->public = $public; + } + + // If a state is set add it to the data object. + if (isset($files)) { + $data->files = $this->buildFileData((array) $files); + } + + // Encode the request data. + $data = json_encode($data); + + // Send the request. + return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); + } + + /** + * Fork a gist. + * + * @param integer $gistId The gist number. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function fork($gistId) + { + // Build the request path. + $path = '/gists/' . (int) $gistId . '/forks'; + + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), ''), 201); + } + + /** + * Get a single gist. + * + * @param integer $gistId The gist number. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($gistId) + { + // Build the request path. + $path = '/gists/' . (int) $gistId; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * List gist commits. + * + * @param integer $gistId The gist number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return array + * + * @since 1.4.0 + * @throws \DomainException + */ + public function getCommitList($gistId, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/gists/' . (int) $gistId . '/commits'; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); + } + + /** + * List gist forks. + * + * @param integer $gistId The gist number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return array + * + * @since 1.4.0 + * @throws \DomainException + */ + public function getForkList($gistId, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/gists/' . (int) $gistId . '/forks'; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); + } + + /** + * List gists. + * + * If a user is authenticated it will return the user's gists, otherwise + * it will return all public gists. + * + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return array + * + * @since 1.0 + * @throws \DomainException + */ + public function getList($page = 0, $limit = 0) + { + // Build the request path. + $path = '/gists'; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); + } + + /** + * List a user’s gists. + * + * @param string $user The name of the GitHub user from which to list gists. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * @param \DateTime $since Only gists updated at or after this time are returned. + * + * @return array + * + * @since 1.0 + * @throws \DomainException + */ + public function getListByUser($user, $page = 0, $limit = 0, \DateTime $since = null) + { + // Build the request path. + $uri = $this->fetchUrl('/users/' . $user . '/gists', $page, $limit); + + if ($since) { + $uri->setVar('since', $since->format(\DateTime::RFC3339)); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * List all public gists. + * + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * @param \DateTime $since Only gists updated at or after this time are returned. + * + * @return array + * + * @since 1.0 + * @throws \DomainException + */ + public function getListPublic($page = 0, $limit = 0, \DateTime $since = null) + { + // Build the request path. + $uri = $this->fetchUrl('/gists/public', $page, $limit); + + if ($since) { + $uri->setVar('since', $since->format(\DateTime::RFC3339)); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * List starred gists. + * + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * @param \DateTime $since Only gists updated at or after this time are returned. + * + * @return array + * + * @since 1.0 + * @throws \DomainException + */ + public function getListStarred($page = 0, $limit = 0, \DateTime $since = null) + { + // Build the request path. + $uri = $this->fetchUrl('/gists/starred', $page, $limit); + + if ($since) { + $uri->setVar('since', $since->format(\DateTime::RFC3339)); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get a specific revision of a gist. + * + * @param integer $gistId The gist number. + * @param string $sha The SHA for the revision to get. + * + * @return object + * + * @since 1.4.0 + * @throws \DomainException + */ + public function getRevision($gistId, $sha) + { + // Build the request path. + $path = '/gists/' . (int) $gistId . '/' . $sha; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Check if a gist is starred. + * + * @param integer $gistId The gist number. + * + * @return boolean True if gist is starred + * + * @since 1.0 + * @throws UnexpectedResponseException + */ + public function isStarred($gistId) + { + // Build the request path. + $path = '/gists/' . (int) $gistId . '/star'; + + // Send the request. + $response = $this->client->get($this->fetchUrl($path)); + + // Validate the response code. + if ($response->code == 204) { + return true; + } + + if ($response->code == 404) { + return false; + } + + // Decode the error response and throw an exception. + $error = json_decode($response->body); + $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; + + throw new UnexpectedResponseException($response, $message, $response->code); + } + + /** + * Star a gist. + * + * @param integer $gistId The gist number. + * + * @return void + * + * @since 1.0 + * @throws \DomainException + */ + public function star($gistId) + { + // Build the request path. + $path = '/gists/' . (int) $gistId . '/star'; + + // Send the request. + $this->processResponse($this->client->put($this->fetchUrl($path), ''), 204); + } + + /** + * Unstar a gist. + * + * @param integer $gistId The gist number. + * + * @return void + * + * @since 1.0 + * @throws \DomainException + */ + public function unstar($gistId) + { + // Build the request path. + $path = '/gists/' . (int) $gistId . '/star'; + + // Send the request. + $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); + } + + /** + * Method to fetch a data array for transmitting to the GitHub API for a list of files based on + * an input array of file paths or filename and content pairs. + * + * @param array $files The list of file paths or filenames and content. + * + * @return array + * + * @since 1.0 + * @throws \InvalidArgumentException + */ + protected function buildFileData(array $files) + { + $data = []; + + foreach ($files as $key => $file) { + if (!is_numeric($key)) { + // If the key isn't numeric, then we are dealing with a file whose content has been supplied + $data[$key] = ['content' => $file]; + } elseif (!file_exists($file)) { + // Otherwise, we have been given a path and we have to load the content + // Verify that the each file exists. + throw new \InvalidArgumentException('The file ' . $file . ' does not exist.'); + } else { + $data[basename($file)] = ['content' => file_get_contents($file)]; + } + } + + return $data; + } } diff --git a/src/Package/Gists/Comments.php b/src/Package/Gists/Comments.php index be012ae8..9cfa3cee 100644 --- a/src/Package/Gists/Comments.php +++ b/src/Package/Gists/Comments.php @@ -19,116 +19,116 @@ */ class Comments extends AbstractPackage { - /** - * Create a comment. - * - * @param integer $gistId The gist number. - * @param string $body The comment body text. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function create($gistId, $body) - { - // Build the request path. - $path = '/gists/' . (int) $gistId . '/comments'; + /** + * Create a comment. + * + * @param integer $gistId The gist number. + * @param string $body The comment body text. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function create($gistId, $body) + { + // Build the request path. + $path = '/gists/' . (int) $gistId . '/comments'; - // Build the request data. - $data = json_encode( - [ - 'body' => $body, - ] - ); + // Build the request data. + $data = json_encode( + [ + 'body' => $body, + ] + ); - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } - /** - * Delete a comment. - * - * @param integer $commentId The id of the comment to delete. - * - * @return void - * - * @since 1.0 - * @throws \DomainException - */ - public function delete($commentId) - { - // Build the request path. - $path = '/gists/comments/' . (int) $commentId; + /** + * Delete a comment. + * + * @param integer $commentId The id of the comment to delete. + * + * @return void + * + * @since 1.0 + * @throws \DomainException + */ + public function delete($commentId) + { + // Build the request path. + $path = '/gists/comments/' . (int) $commentId; - // Send the request. - $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } + // Send the request. + $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); + } - /** - * Edit a comment. - * - * @param integer $commentId The id of the comment to update. - * @param string $body The new body text for the comment. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function edit($commentId, $body) - { - // Build the request path. - $path = '/gists/comments/' . (int) $commentId; + /** + * Edit a comment. + * + * @param integer $commentId The id of the comment to update. + * @param string $body The new body text for the comment. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function edit($commentId, $body) + { + // Build the request path. + $path = '/gists/comments/' . (int) $commentId; - // Build the request data. - $data = json_encode( - [ - 'body' => $body, - ] - ); + // Build the request data. + $data = json_encode( + [ + 'body' => $body, + ] + ); - // Send the request. - return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); - } + // Send the request. + return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); + } - /** - * Get a single comment. - * - * @param integer $commentId The comment id to get. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($commentId) - { - // Build the request path. - $path = '/gists/comments/' . (int) $commentId; + /** + * Get a single comment. + * + * @param integer $commentId The comment id to get. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($commentId) + { + // Build the request path. + $path = '/gists/comments/' . (int) $commentId; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } - /** - * List comments on a gist. - * - * @param integer $gistId The gist number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getList($gistId, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/gists/' . (int) $gistId . '/comments'; + /** + * List comments on a gist. + * + * @param integer $gistId The gist number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getList($gistId, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/gists/' . (int) $gistId . '/comments'; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); + } } diff --git a/src/Package/Gitignore.php b/src/Package/Gitignore.php index 587c8a4c..74fe110f 100644 --- a/src/Package/Gitignore.php +++ b/src/Package/Gitignore.php @@ -23,60 +23,58 @@ */ class Gitignore extends AbstractPackage { - /** - * Listing available templates - * - * List all templates available to pass as an option when creating a repository. - * - * @return object - * - * @since 1.0 - */ - public function getList() - { - // Build the request path. - $path = '/gitignore/templates'; + /** + * Listing available templates + * + * List all templates available to pass as an option when creating a repository. + * + * @return object + * + * @since 1.0 + */ + public function getList() + { + // Build the request path. + $path = '/gitignore/templates'; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Get a single template - * - * @param string $name The name of the template - * @param boolean $raw Raw output - * - * @return mixed|string - * - * @since 1.0 - * @throws UnexpectedResponseException - */ - public function get($name, $raw = false) - { - // Build the request path. - $path = '/gitignore/templates/' . $name; + /** + * Get a single template + * + * @param string $name The name of the template + * @param boolean $raw Raw output + * + * @return mixed|string + * + * @since 1.0 + * @throws UnexpectedResponseException + */ + public function get($name, $raw = false) + { + // Build the request path. + $path = '/gitignore/templates/' . $name; - $headers = []; + $headers = []; - if ($raw) - { - $headers['Accept'] = 'application/vnd.github.raw+json'; - } + if ($raw) { + $headers['Accept'] = 'application/vnd.github.raw+json'; + } - $response = $this->client->get($this->fetchUrl($path), $headers); + $response = $this->client->get($this->fetchUrl($path), $headers); - // Validate the response code. - if ($response->code != 200) - { - // Decode the error response and throw an exception. - $error = json_decode($response->body); - $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; + // Validate the response code. + if ($response->code != 200) { + // Decode the error response and throw an exception. + $error = json_decode($response->body); + $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; - throw new UnexpectedResponseException($response, $message, $response->code); - } + throw new UnexpectedResponseException($response, $message, $response->code); + } - return ($raw) ? $response->body : json_decode($response->body); - } + return ($raw) ? $response->body : json_decode($response->body); + } } diff --git a/src/Package/Graphql.php b/src/Package/Graphql.php index b840c45e..6e7a8898 100644 --- a/src/Package/Graphql.php +++ b/src/Package/Graphql.php @@ -19,38 +19,37 @@ */ class Graphql extends AbstractPackage { - /** - * Execute a query against the GraphQL API. - * - * @param string $query The query to perform. - * @param array $variables An optional array of variables to include in the request. - * - * @return string - * - * @since 1.6.0 - */ - public function execute($query, array $variables = []) - { - // Build the request path. - $path = '/graphql'; + /** + * Execute a query against the GraphQL API. + * + * @param string $query The query to perform. + * @param array $variables An optional array of variables to include in the request. + * + * @return string + * + * @since 1.6.0 + */ + public function execute($query, array $variables = []) + { + // Build the request path. + $path = '/graphql'; - $headers = [ - 'Accept' => 'application/vnd.github.v4+json', - 'Content-Type' => 'application/json', - ]; + $headers = [ + 'Accept' => 'application/vnd.github.v4+json', + 'Content-Type' => 'application/json', + ]; - $data = [ - 'query' => $query, - ]; + $data = [ + 'query' => $query, + ]; - if (!empty($variables)) - { - $data['variables'] = $variables; - } + if (!empty($variables)) { + $data['variables'] = $variables; + } - // Send the request. - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($data), $headers) - ); - } + // Send the request. + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($data), $headers) + ); + } } diff --git a/src/Package/Issues.php b/src/Package/Issues.php index d20f1ee0..4793471c 100644 --- a/src/Package/Issues.php +++ b/src/Package/Issues.php @@ -25,346 +25,318 @@ */ class Issues extends AbstractPackage { - /** - * Create an issue. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $title The title of the new issue. - * @param string $body The body text for the new issue. - * @param string $assignee The login for the GitHub user that this issue should be assigned to. - * @param integer $milestone The milestone to associate this issue with. - * @param string[] $labels The labels to associate with this issue. - * @param string[] $assignees The logins for GitHub users to assign to this issue. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function create($user, $repo, $title, $body = null, $assignee = null, $milestone = null, array $labels = [], array $assignees = []) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/issues'; - - // Ensure that we have a non-associative array. - if (!empty($labels)) - { - $labels = array_values($labels); - } - - // Build the request data. - $data = [ - 'title' => $title, - 'milestone' => $milestone, - 'labels' => $labels, - 'body' => $body, - ]; - - if (\is_string($assignee) && !empty($assignees)) - { - throw new \UnexpectedValueException('You cannot pass both assignee and assignees. Only one may be provided.'); - } - - if (!empty($assignees)) - { - $data['assignees'] = array_values($assignees); - } - elseif (\is_string($assignee)) - { - $data['assignee'] = $assignee; - } - - // Encode the request data. - $data = json_encode($data); - - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } - - /** - * Edit an issue. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueId The issue number. - * @param string $state The optional new state for the issue. [open, closed] - * @param string $title The title of the new issue. - * @param string $body The body text for the new issue. - * @param string $assignee The login for the GitHub user that this issue should be assigned to. - * @param integer $milestone The milestone to associate this issue with. - * @param array $labels The labels to associate with this issue. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function edit($user, $repo, $issueId, $state = null, $title = null, $body = null, $assignee = null, $milestone = null, array $labels = []) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; - - // Create the data object. - $data = new \stdClass; - - // If a title is set add it to the data object. - if (isset($title)) - { - $data->title = $title; - } - - // If a body is set add it to the data object. - if (isset($body)) - { - $data->body = $body; - } - - // If a state is set add it to the data object. - if (isset($state)) - { - $data->state = $state; - } - - // If an assignee is set add it to the data object. - if (isset($assignee)) - { - $data->assignee = $assignee; - } - - // If a milestone is set add it to the data object. - if (isset($milestone)) - { - $data->milestone = $milestone; - } - - // If labels are set add them to the data object. - if (!empty($labels)) - { - // Ensure that we have a non-associative array. - if (isset($labels)) - { - $labels = array_values($labels); - } - - $data->labels = $labels; - } - - // Encode the request data. - $data = json_encode($data); - - // Send the request. - return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); - } - - /** - * Get a single issue. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueId The issue number. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($user, $repo, $issueId) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * List issues. - * - * @param string $filter The filter type: assigned, created, mentioned, subscribed. - * @param string $state The optional state to filter requests by. [open, closed] - * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. - * @param string $sort The sort order: created, updated, comments, default: created. - * @param string $direction The list direction: asc or desc, default: desc. - * @param \DateTimeInterface $since Only issues updated at or after this time are returned. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getList( - $filter = null, - $state = null, - $labels = null, - $sort = null, - $direction = null, - \DateTimeInterface $since = null, - $page = 0, - $limit = 0 - ) - { - // Build the request path. - $uri = $this->fetchUrl('/issues', $page, $limit); - - if ($filter) - { - $uri->setVar('filter', $filter); - } - - if ($state) - { - $uri->setVar('state', $state); - } - - if ($labels) - { - $uri->setVar('labels', $labels); - } - - if ($sort) - { - $uri->setVar('sort', $sort); - } - - if ($direction) - { - $uri->setVar('direction', $direction); - } - - if ($since) - { - $uri->setVar('since', $since->format(\DateTime::ISO8601)); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * List issues for a repository. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $milestone The milestone number, 'none', or *. - * @param string $state The optional state to filter requests by. [open, closed] - * @param string $assignee The assignee name, 'none', or *. - * @param string $mentioned The GitHub user name. - * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. - * @param string $sort The sort order: created, updated, comments, default: created. - * @param string $direction The list direction: asc or desc, default: desc. - * @param \DateTimeInterface $since Only issues updated at or after this time are returned. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getListByRepository( - $user, - $repo, - $milestone = null, - $state = null, - $assignee = null, - $mentioned = null, - $labels = null, - $sort = null, - $direction = null, - \DateTimeInterface $since = null, - $page = 0, - $limit = 0 - ) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/issues'; - - $uri = $this->fetchUrl($path, $page, $limit); - - if ($milestone) - { - $uri->setVar('milestone', $milestone); - } - - if ($state) - { - $uri->setVar('state', $state); - } - - if ($assignee) - { - $uri->setVar('assignee', $assignee); - } - - if ($mentioned) - { - $uri->setVar('mentioned', $mentioned); - } - - if ($labels) - { - $uri->setVar('labels', $labels); - } - - if ($sort) - { - $uri->setVar('sort', $sort); - } - - if ($direction) - { - $uri->setVar('direction', $direction); - } - - if ($since) - { - $uri->setVar('since', $since->format(\DateTime::RFC3339)); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Lock an issue. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueId The issue number. - * - * @return object - * - * @since 1.4.0 - * @throws \DomainException - */ - public function lock($user, $repo, $issueId) - { - // Build the request path. - $path = "/repos/$user/$repo/issues/" . (int) $issueId . '/lock'; - - return $this->processResponse($this->client->put($this->fetchUrl($path), []), 204); - } - - /** - * Unlock an issue. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueId The issue number. - * - * @return object - * - * @since 1.4.0 - * @throws \DomainException - */ - public function unlock($user, $repo, $issueId) - { - // Build the request path. - $path = "/repos/$user/$repo/issues/" . (int) $issueId . '/lock'; - - return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } + /** + * Create an issue. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $title The title of the new issue. + * @param string $body The body text for the new issue. + * @param string $assignee The login for the GitHub user that this issue should be assigned to. + * @param integer $milestone The milestone to associate this issue with. + * @param string[] $labels The labels to associate with this issue. + * @param string[] $assignees The logins for GitHub users to assign to this issue. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function create($user, $repo, $title, $body = null, $assignee = null, $milestone = null, array $labels = [], array $assignees = []) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/issues'; + + // Ensure that we have a non-associative array. + if (!empty($labels)) { + $labels = array_values($labels); + } + + // Build the request data. + $data = [ + 'title' => $title, + 'milestone' => $milestone, + 'labels' => $labels, + 'body' => $body, + ]; + + if (\is_string($assignee) && !empty($assignees)) { + throw new \UnexpectedValueException('You cannot pass both assignee and assignees. Only one may be provided.'); + } + + if (!empty($assignees)) { + $data['assignees'] = array_values($assignees); + } elseif (\is_string($assignee)) { + $data['assignee'] = $assignee; + } + + // Encode the request data. + $data = json_encode($data); + + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } + + /** + * Edit an issue. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueId The issue number. + * @param string $state The optional new state for the issue. [open, closed] + * @param string $title The title of the new issue. + * @param string $body The body text for the new issue. + * @param string $assignee The login for the GitHub user that this issue should be assigned to. + * @param integer $milestone The milestone to associate this issue with. + * @param array $labels The labels to associate with this issue. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function edit($user, $repo, $issueId, $state = null, $title = null, $body = null, $assignee = null, $milestone = null, array $labels = []) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; + + // Create the data object. + $data = new \stdClass(); + + // If a title is set add it to the data object. + if (isset($title)) { + $data->title = $title; + } + + // If a body is set add it to the data object. + if (isset($body)) { + $data->body = $body; + } + + // If a state is set add it to the data object. + if (isset($state)) { + $data->state = $state; + } + + // If an assignee is set add it to the data object. + if (isset($assignee)) { + $data->assignee = $assignee; + } + + // If a milestone is set add it to the data object. + if (isset($milestone)) { + $data->milestone = $milestone; + } + + // If labels are set add them to the data object. + if (!empty($labels)) { + // Ensure that we have a non-associative array. + if (isset($labels)) { + $labels = array_values($labels); + } + + $data->labels = $labels; + } + + // Encode the request data. + $data = json_encode($data); + + // Send the request. + return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); + } + + /** + * Get a single issue. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueId The issue number. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($user, $repo, $issueId) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * List issues. + * + * @param string $filter The filter type: assigned, created, mentioned, subscribed. + * @param string $state The optional state to filter requests by. [open, closed] + * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. + * @param string $sort The sort order: created, updated, comments, default: created. + * @param string $direction The list direction: asc or desc, default: desc. + * @param \DateTimeInterface $since Only issues updated at or after this time are returned. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getList( + $filter = null, + $state = null, + $labels = null, + $sort = null, + $direction = null, + \DateTimeInterface $since = null, + $page = 0, + $limit = 0 + ) { + // Build the request path. + $uri = $this->fetchUrl('/issues', $page, $limit); + + if ($filter) { + $uri->setVar('filter', $filter); + } + + if ($state) { + $uri->setVar('state', $state); + } + + if ($labels) { + $uri->setVar('labels', $labels); + } + + if ($sort) { + $uri->setVar('sort', $sort); + } + + if ($direction) { + $uri->setVar('direction', $direction); + } + + if ($since) { + $uri->setVar('since', $since->format(\DateTime::ISO8601)); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * List issues for a repository. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $milestone The milestone number, 'none', or *. + * @param string $state The optional state to filter requests by. [open, closed] + * @param string $assignee The assignee name, 'none', or *. + * @param string $mentioned The GitHub user name. + * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. + * @param string $sort The sort order: created, updated, comments, default: created. + * @param string $direction The list direction: asc or desc, default: desc. + * @param \DateTimeInterface $since Only issues updated at or after this time are returned. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getListByRepository( + $user, + $repo, + $milestone = null, + $state = null, + $assignee = null, + $mentioned = null, + $labels = null, + $sort = null, + $direction = null, + \DateTimeInterface $since = null, + $page = 0, + $limit = 0 + ) { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/issues'; + + $uri = $this->fetchUrl($path, $page, $limit); + + if ($milestone) { + $uri->setVar('milestone', $milestone); + } + + if ($state) { + $uri->setVar('state', $state); + } + + if ($assignee) { + $uri->setVar('assignee', $assignee); + } + + if ($mentioned) { + $uri->setVar('mentioned', $mentioned); + } + + if ($labels) { + $uri->setVar('labels', $labels); + } + + if ($sort) { + $uri->setVar('sort', $sort); + } + + if ($direction) { + $uri->setVar('direction', $direction); + } + + if ($since) { + $uri->setVar('since', $since->format(\DateTime::RFC3339)); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * Lock an issue. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueId The issue number. + * + * @return object + * + * @since 1.4.0 + * @throws \DomainException + */ + public function lock($user, $repo, $issueId) + { + // Build the request path. + $path = "/repos/$user/$repo/issues/" . (int) $issueId . '/lock'; + + return $this->processResponse($this->client->put($this->fetchUrl($path), []), 204); + } + + /** + * Unlock an issue. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueId The issue number. + * + * @return object + * + * @since 1.4.0 + * @throws \DomainException + */ + public function unlock($user, $repo, $issueId) + { + // Build the request path. + $path = "/repos/$user/$repo/issues/" . (int) $issueId . '/lock'; + + return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); + } } diff --git a/src/Package/Issues/Assignees.php b/src/Package/Issues/Assignees.php index c189702d..4103746d 100644 --- a/src/Package/Issues/Assignees.php +++ b/src/Package/Issues/Assignees.php @@ -20,127 +20,122 @@ */ class Assignees extends AbstractPackage { - /** - * List assignees. - * - * This call lists all the available assignees (owner + collaborators) to which issues may be assigned. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return object - * - * @since 1.0 - */ - public function getList($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/assignees'; + /** + * List assignees. + * + * This call lists all the available assignees (owner + collaborators) to which issues may be assigned. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return object + * + * @since 1.0 + */ + public function getList($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/assignees'; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Check assignee. - * - * You may check to see if a particular user is an assignee for a repository. - * If the given assignee login belongs to an assignee for the repository, a 204 header - * with no content is returned. - * Otherwise a 404 status code is returned. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $assignee The assignees login name. - * - * @return boolean - * - * @since 1.0 - * @throws \DomainException - */ - public function check($owner, $repo, $assignee) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/assignees/' . $assignee; + /** + * Check assignee. + * + * You may check to see if a particular user is an assignee for a repository. + * If the given assignee login belongs to an assignee for the repository, a 204 header + * with no content is returned. + * Otherwise a 404 status code is returned. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $assignee The assignees login name. + * + * @return boolean + * + * @since 1.0 + * @throws \DomainException + */ + public function check($owner, $repo, $assignee) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/assignees/' . $assignee; - try - { - $response = $this->client->get($this->fetchUrl($path)); + try { + $response = $this->client->get($this->fetchUrl($path)); - if ($response->code == 204) - { - return true; - } + if ($response->code == 204) { + return true; + } - throw new UnexpectedResponseException($response, 'Invalid response: ' . $response->code); - } - catch (\DomainException $e) - { - if (isset($response->code) && $response->code == 404) - { - return false; - } + throw new UnexpectedResponseException($response, 'Invalid response: ' . $response->code); + } catch (\DomainException $e) { + if (isset($response->code) && $response->code == 404) { + return false; + } - throw $e; - } - } + throw $e; + } + } - /** - * Add assignees to an Issue - * - * This call adds the users passed in the assignees key (as their logins) to the issue. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $number The issue number to add assignees to. - * @param string[] $assignees The logins for GitHub users to assign to this issue. - * - * @return object - * - * @since 1.4.0 - * @throws \DomainException - */ - public function add($owner, $repo, $number, array $assignees) - { - // Build the request path. - $path = "/repos/$owner/$repo/issues/$number/assignees"; + /** + * Add assignees to an Issue + * + * This call adds the users passed in the assignees key (as their logins) to the issue. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $number The issue number to add assignees to. + * @param string[] $assignees The logins for GitHub users to assign to this issue. + * + * @return object + * + * @since 1.4.0 + * @throws \DomainException + */ + public function add($owner, $repo, $number, array $assignees) + { + // Build the request path. + $path = "/repos/$owner/$repo/issues/$number/assignees"; - $data = json_encode( - [ - 'assignees' => $assignees, - ] - ); + $data = json_encode( + [ + 'assignees' => $assignees, + ] + ); - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } - /** - * Remove assignees from an Issue - * - * This call removes the users passed in the assignees key (as their logins) from the issue. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $number The issue number to add assignees to. - * @param string[] $assignees The logins for GitHub users to assign to this issue. - * - * @return object - * - * @since 1.4.0 - * @throws \DomainException - */ - public function remove($owner, $repo, $number, array $assignees) - { - // Build the request path. - $path = "/repos/$owner/$repo/issues/$number/assignees"; + /** + * Remove assignees from an Issue + * + * This call removes the users passed in the assignees key (as their logins) from the issue. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $number The issue number to add assignees to. + * @param string[] $assignees The logins for GitHub users to assign to this issue. + * + * @return object + * + * @since 1.4.0 + * @throws \DomainException + */ + public function remove($owner, $repo, $number, array $assignees) + { + // Build the request path. + $path = "/repos/$owner/$repo/issues/$number/assignees"; - $data = json_encode( - [ - 'assignees' => $assignees, - ] - ); + $data = json_encode( + [ + 'assignees' => $assignees, + ] + ); - return $this->processResponse($this->client->delete($this->fetchUrl($path), [], null, $data)); - } + return $this->processResponse($this->client->delete($this->fetchUrl($path), [], null, $data)); + } } diff --git a/src/Package/Issues/Comments.php b/src/Package/Issues/Comments.php index a61005ea..e09af9e5 100644 --- a/src/Package/Issues/Comments.php +++ b/src/Package/Issues/Comments.php @@ -22,197 +22,195 @@ */ class Comments extends AbstractPackage { - /** - * List comments on an issue. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueId The issue number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * @param \DateTimeInterface $since Only comments updated at or after this time are returned. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getList($owner, $repo, $issueId, $page = 0, $limit = 0, \DateTimeInterface $since = null) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; - - $uri = $this->fetchUrl($path, $page, $limit); - - if ($since) - { - $uri->setVar('since', $since->format(\DateTime::RFC3339)); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * List comments in a repository. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sort The sort field - created or updated. - * @param string $direction The sort order- asc or desc. Ignored without sort parameter. - * @param \DateTimeInterface $since Only comments updated at or after this time are returned. - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - * @throws \DomainException - */ - public function getRepositoryList($owner, $repo, $sort = 'created', $direction = 'asc', \DateTimeInterface $since = null) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/comments'; - - if (\in_array($sort, ['created', 'updated']) == false) - { - throw new \UnexpectedValueException( - sprintf( - '%1$s - sort field must be "created" or "updated"', __METHOD__ - ) - ); - } - - if (\in_array($direction, ['asc', 'desc']) == false) - { - throw new \UnexpectedValueException( - sprintf( - '%1$s - direction field must be "asc" or "desc"', __METHOD__ - ) - ); - } - - $uri = $this->fetchUrl($path); - $uri->setVar('sort', $sort); - $uri->setVar('direction', $direction); - - if ($since) - { - $uri->setVar('since', $since->format(\DateTime::RFC3339)); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Get a single comment. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The comment id. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($owner, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/comments/' . (int) $id; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Edit a comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $commentId The id of the comment to update. - * @param string $body The new body text for the comment. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function edit($user, $repo, $commentId, $body) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; - - // Build the request data. - $data = json_encode( - [ - 'body' => $body, - ] - ); - - // Send the request. - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), $data) - ); - } - - /** - * Create a comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueId The issue number. - * @param string $body The comment body text. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function create($user, $repo, $issueId, $body) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; - - // Build the request data. - $data = json_encode( - [ - 'body' => $body, - ] - ); - - // Send the request. - return $this->processResponse( - $this->client->post($this->fetchUrl($path), $data), - 201 - ); - } - - /** - * Delete a comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $commentId The id of the comment to delete. - * - * @return boolean - * - * @since 1.0 - * @throws \DomainException - */ - public function delete($user, $repo, $commentId) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; - - // Send the request. - $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - - return true; - } + /** + * List comments on an issue. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueId The issue number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * @param \DateTimeInterface $since Only comments updated at or after this time are returned. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getList($owner, $repo, $issueId, $page = 0, $limit = 0, \DateTimeInterface $since = null) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; + + $uri = $this->fetchUrl($path, $page, $limit); + + if ($since) { + $uri->setVar('since', $since->format(\DateTime::RFC3339)); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * List comments in a repository. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sort The sort field - created or updated. + * @param string $direction The sort order- asc or desc. Ignored without sort parameter. + * @param \DateTimeInterface $since Only comments updated at or after this time are returned. + * + * @return object + * + * @since 1.0 + * @throws \UnexpectedValueException + * @throws \DomainException + */ + public function getRepositoryList($owner, $repo, $sort = 'created', $direction = 'asc', \DateTimeInterface $since = null) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/comments'; + + if (\in_array($sort, ['created', 'updated']) == false) { + throw new \UnexpectedValueException( + sprintf( + '%1$s - sort field must be "created" or "updated"', + __METHOD__ + ) + ); + } + + if (\in_array($direction, ['asc', 'desc']) == false) { + throw new \UnexpectedValueException( + sprintf( + '%1$s - direction field must be "asc" or "desc"', + __METHOD__ + ) + ); + } + + $uri = $this->fetchUrl($path); + $uri->setVar('sort', $sort); + $uri->setVar('direction', $direction); + + if ($since) { + $uri->setVar('since', $since->format(\DateTime::RFC3339)); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get a single comment. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id The comment id. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($owner, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/comments/' . (int) $id; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Edit a comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $commentId The id of the comment to update. + * @param string $body The new body text for the comment. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function edit($user, $repo, $commentId, $body) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; + + // Build the request data. + $data = json_encode( + [ + 'body' => $body, + ] + ); + + // Send the request. + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), $data) + ); + } + + /** + * Create a comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueId The issue number. + * @param string $body The comment body text. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function create($user, $repo, $issueId, $body) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; + + // Build the request data. + $data = json_encode( + [ + 'body' => $body, + ] + ); + + // Send the request. + return $this->processResponse( + $this->client->post($this->fetchUrl($path), $data), + 201 + ); + } + + /** + * Delete a comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $commentId The id of the comment to delete. + * + * @return boolean + * + * @since 1.0 + * @throws \DomainException + */ + public function delete($user, $repo, $commentId) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; + + // Send the request. + $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + + return true; + } } diff --git a/src/Package/Issues/Events.php b/src/Package/Issues/Events.php index 204f3c38..be4e3b08 100644 --- a/src/Package/Issues/Events.php +++ b/src/Package/Issues/Events.php @@ -23,67 +23,67 @@ */ class Events extends AbstractPackage { - /** - * List events for an issue. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueNumber The issue number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - */ - public function getList($owner, $repo, $issueNumber, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueNumber . '/events'; + /** + * List events for an issue. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueNumber The issue number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + */ + public function getList($owner, $repo, $issueNumber, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueNumber . '/events'; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path, $page, $limit)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path, $page, $limit)) + ); + } - /** - * List events for a repository. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueId The issue number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - */ - public function getListRepository($owner, $repo, $issueId, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; + /** + * List events for a repository. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueId The issue number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + */ + public function getListRepository($owner, $repo, $issueId, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path, $page, $limit)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path, $page, $limit)) + ); + } - /** - * Get a single event. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The event number. - * - * @return object - */ - public function get($owner, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/events/' . (int) $id; + /** + * Get a single event. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id The event number. + * + * @return object + */ + public function get($owner, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/events/' . (int) $id; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } } diff --git a/src/Package/Issues/Labels.php b/src/Package/Issues/Labels.php index e2f2187b..cd7e4ec5 100644 --- a/src/Package/Issues/Labels.php +++ b/src/Package/Issues/Labels.php @@ -19,269 +19,269 @@ */ class Labels extends AbstractPackage { - /** - * List all labels for this repository. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return array - * - * @since 1.0 - */ - public function getList($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/labels'; + /** + * List all labels for this repository. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return array + * + * @since 1.0 + */ + public function getList($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/labels'; - // Send the request. - return $this->processResponse( - $response = $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $response = $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Get a single label. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $name The label name to get. - * - * @return object - * - * @since 1.0 - */ - public function get($user, $repo, $name) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/labels/' . rawurlencode($name); + /** + * Get a single label. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $name The label name to get. + * + * @return object + * + * @since 1.0 + */ + public function get($user, $repo, $name) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/labels/' . rawurlencode($name); - // Send the request. - return $this->processResponse( - $response = $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $response = $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Create a label. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $name The label name. - * @param string $color The label color. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function create($owner, $repo, $name, $color) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/labels'; + /** + * Create a label. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $name The label name. + * @param string $color The label color. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function create($owner, $repo, $name, $color) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/labels'; - // Build the request data. - $data = json_encode( - [ - 'name' => $name, - 'color' => $color, - ] - ); + // Build the request data. + $data = json_encode( + [ + 'name' => $name, + 'color' => $color, + ] + ); - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } - /** - * Delete a label. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $name The label name. - * - * @return object - * - * @since 1.0 - */ - public function delete($owner, $repo, $name) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/labels/' . rawurlencode($name); + /** + * Delete a label. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $name The label name. + * + * @return object + * + * @since 1.0 + */ + public function delete($owner, $repo, $name) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/labels/' . rawurlencode($name); - // Send the request. - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + // Send the request. + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } - /** - * Update a label. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $label The label name. - * @param string $name The new label name. - * @param string $color The new label color. - * - * @return object - * - * @since 1.0 - */ - public function update($user, $repo, $label, $name, $color) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/labels/' . $label; + /** + * Update a label. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $label The label name. + * @param string $name The new label name. + * @param string $color The new label color. + * + * @return object + * + * @since 1.0 + */ + public function update($user, $repo, $label, $name, $color) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/labels/' . $label; - // Build the request data. - $data = json_encode( - [ - 'name' => $name, - 'color' => $color, - ] - ); + // Build the request data. + $data = json_encode( + [ + 'name' => $name, + 'color' => $color, + ] + ); - // Send the request. - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), $data) - ); - } + // Send the request. + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), $data) + ); + } - /** - * List labels on an issue. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $number The issue number. - * - * @return object - * - * @since 1.0 - */ - public function getListByIssue($owner, $repo, $number) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; + /** + * List labels on an issue. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $number The issue number. + * + * @return object + * + * @since 1.0 + */ + public function getListByIssue($owner, $repo, $number) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Add labels to an issue. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $number The issue number. - * @param array $labels An array of labels to add. - * - * @return object - * - * @since 1.0 - */ - public function add($owner, $repo, $number, array $labels) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; + /** + * Add labels to an issue. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $number The issue number. + * @param array $labels An array of labels to add. + * + * @return object + * + * @since 1.0 + */ + public function add($owner, $repo, $number, array $labels) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; - // Send the request. - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($labels)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($labels)) + ); + } - /** - * Remove a label from an issue. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $number The issue number. - * @param string $name The name of the label to remove. - * - * @return object - * - * @since 1.0 - */ - public function removeFromIssue($owner, $repo, $number, $name) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels/' . rawurlencode($name); + /** + * Remove a label from an issue. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $number The issue number. + * @param string $name The name of the label to remove. + * + * @return object + * + * @since 1.0 + */ + public function removeFromIssue($owner, $repo, $number, $name) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels/' . rawurlencode($name); - // Send the request. - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)) + ); + } - /** - * Replace all labels for an issue. - * - * Sending an empty array ([]) will remove all Labels from the Issue. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $number The issue number. - * @param array $labels New labels - * - * @return object - * - * @since 1.0 - */ - public function replace($owner, $repo, $number, array $labels) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; + /** + * Replace all labels for an issue. + * + * Sending an empty array ([]) will remove all Labels from the Issue. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $number The issue number. + * @param array $labels New labels + * + * @return object + * + * @since 1.0 + */ + public function replace($owner, $repo, $number, array $labels) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; - // Send the request. - return $this->processResponse( - $this->client->put($this->fetchUrl($path), json_encode($labels)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->put($this->fetchUrl($path), json_encode($labels)) + ); + } - /** - * Remove all labels from an issue. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $number The issue number. - * - * @return object - * - * @since 1.0 - */ - public function removeAllFromIssue($owner, $repo, $number) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; + /** + * Remove all labels from an issue. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $number The issue number. + * + * @return object + * + * @since 1.0 + */ + public function removeAllFromIssue($owner, $repo, $number) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/issues/' . $number . '/labels'; - // Send the request. - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + // Send the request. + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } - /** - * Get labels for every issue in a milestone. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $number The issue number. - * - * @return object - * - * @since 1.0 - */ - public function getListByMilestone($owner, $repo, $number) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/milestones/' . $number . '/labels'; + /** + * Get labels for every issue in a milestone. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $number The issue number. + * + * @return object + * + * @since 1.0 + */ + public function getListByMilestone($owner, $repo, $number) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/milestones/' . $number . '/labels'; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } } diff --git a/src/Package/Issues/Milestones.php b/src/Package/Issues/Milestones.php index 675c7b35..96ee547f 100644 --- a/src/Package/Issues/Milestones.php +++ b/src/Package/Issues/Milestones.php @@ -19,173 +19,166 @@ */ class Milestones extends AbstractPackage { - /** - * List milestones for a repository. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $state The milestone state to retrieved. Open (default) or closed. - * @param string $sort Sort can be due_date (default) or completeness. - * @param string $direction Direction is asc or desc (default). - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getList($user, $repo, $state = 'open', $sort = 'due_date', $direction = 'desc', $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/milestones'; - - $uri = $this->fetchUrl($path, $page, $limit); - $uri->setVar('state', $state); - $uri->setVar('sort', $sort); - $uri->setVar('direction', $direction); - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Get a single milestone. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $milestoneId The milestone id to get. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($user, $repo, $milestoneId) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Create a milestone. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $title The title of the milestone. - * @param string $state Can be open (default) or closed. - * @param string $description Optional description for milestone. - * @param string $dueOn The milestone due date. This is a timestamp in ISO 8601 format. - * - * @return object - * - * @note As of 2.0 the $dueOn parameter will be typehinted to a \DateTime object - * @since 1.0 - * @throws \DomainException - */ - public function create($user, $repo, $title, $state = null, $description = null, $dueOn = null) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/milestones'; - - // Build the request data. - $data = [ - 'title' => $title, - ]; - - if ($state !== null) - { - $data['state'] = $state; - } - - if ($description !== null) - { - $data['description'] = $description; - } - - if ($dueOn !== null) - { - $data['due_on'] = $dueOn; - } - - $data = json_encode($data); - - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } - - /** - * Update a milestone. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $milestoneId The id of the comment to update. - * @param integer $title Optional title of the milestone. - * @param string $state Can be open (default) or closed. - * @param string $description Optional description for milestone. - * @param string $dueOn The milestone due date. This is a timestamp in ISO 8601 format. - * - * @return object - * - * @note As of 2.0 the $dueOn parameter will be typehinted to a \DateTime object - * @since 1.0 - * @throws \DomainException - */ - public function edit($user, $repo, $milestoneId, $title = null, $state = null, $description = null, $dueOn = null) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId; - - // Build the request data. - $data = []; - - if ($title !== null) - { - $data['title'] = $title; - } - - if ($state !== null) - { - $data['state'] = $state; - } - - if ($description !== null) - { - $data['description'] = $description; - } - - if ($dueOn !== null) - { - $data['due_on'] = $dueOn; - } - - $data = json_encode($data); - - // Send the request. - return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); - } - - /** - * Delete a milestone. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $milestoneId The id of the milestone to delete. - * - * @return void - * - * @since 1.0 - * @throws \DomainException - */ - public function delete($user, $repo, $milestoneId) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId; - - // Send the request. - $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } + /** + * List milestones for a repository. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $state The milestone state to retrieved. Open (default) or closed. + * @param string $sort Sort can be due_date (default) or completeness. + * @param string $direction Direction is asc or desc (default). + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getList($user, $repo, $state = 'open', $sort = 'due_date', $direction = 'desc', $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/milestones'; + + $uri = $this->fetchUrl($path, $page, $limit); + $uri->setVar('state', $state); + $uri->setVar('sort', $sort); + $uri->setVar('direction', $direction); + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get a single milestone. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $milestoneId The milestone id to get. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($user, $repo, $milestoneId) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Create a milestone. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $title The title of the milestone. + * @param string $state Can be open (default) or closed. + * @param string $description Optional description for milestone. + * @param string $dueOn The milestone due date. This is a timestamp in ISO 8601 format. + * + * @return object + * + * @note As of 2.0 the $dueOn parameter will be typehinted to a \DateTime object + * @since 1.0 + * @throws \DomainException + */ + public function create($user, $repo, $title, $state = null, $description = null, $dueOn = null) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/milestones'; + + // Build the request data. + $data = [ + 'title' => $title, + ]; + + if ($state !== null) { + $data['state'] = $state; + } + + if ($description !== null) { + $data['description'] = $description; + } + + if ($dueOn !== null) { + $data['due_on'] = $dueOn; + } + + $data = json_encode($data); + + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } + + /** + * Update a milestone. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $milestoneId The id of the comment to update. + * @param integer $title Optional title of the milestone. + * @param string $state Can be open (default) or closed. + * @param string $description Optional description for milestone. + * @param string $dueOn The milestone due date. This is a timestamp in ISO 8601 format. + * + * @return object + * + * @note As of 2.0 the $dueOn parameter will be typehinted to a \DateTime object + * @since 1.0 + * @throws \DomainException + */ + public function edit($user, $repo, $milestoneId, $title = null, $state = null, $description = null, $dueOn = null) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId; + + // Build the request data. + $data = []; + + if ($title !== null) { + $data['title'] = $title; + } + + if ($state !== null) { + $data['state'] = $state; + } + + if ($description !== null) { + $data['description'] = $description; + } + + if ($dueOn !== null) { + $data['due_on'] = $dueOn; + } + + $data = json_encode($data); + + // Send the request. + return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); + } + + /** + * Delete a milestone. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $milestoneId The id of the milestone to delete. + * + * @return void + * + * @since 1.0 + * @throws \DomainException + */ + public function delete($user, $repo, $milestoneId) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId; + + // Send the request. + $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); + } } diff --git a/src/Package/Markdown.php b/src/Package/Markdown.php index dddc7bd6..43b8ba3b 100644 --- a/src/Package/Markdown.php +++ b/src/Package/Markdown.php @@ -20,59 +20,57 @@ */ class Markdown extends AbstractPackage { - /** - * Render an arbitrary Markdown document. - * - * @param string $text The text object being parsed. - * @param string $mode The parsing mode; valid options are 'markdown' or 'gfm'. - * @param string $context An optional repository context, only used in 'gfm' mode. - * - * @return string Formatted HTML - * - * @since 1.0 - * @throws UnexpectedResponseException - * @throws \InvalidArgumentException - */ - public function render($text, $mode = 'gfm', $context = null) - { - // The valid modes - $validModes = ['gfm', 'markdown']; + /** + * Render an arbitrary Markdown document. + * + * @param string $text The text object being parsed. + * @param string $mode The parsing mode; valid options are 'markdown' or 'gfm'. + * @param string $context An optional repository context, only used in 'gfm' mode. + * + * @return string Formatted HTML + * + * @since 1.0 + * @throws UnexpectedResponseException + * @throws \InvalidArgumentException + */ + public function render($text, $mode = 'gfm', $context = null) + { + // The valid modes + $validModes = ['gfm', 'markdown']; - // Make sure the scope is valid - if (!\in_array($mode, $validModes)) - { - throw new \InvalidArgumentException(sprintf('The %s mode is not valid. Valid modes are "gfm" or "markdown".', $mode)); - } + // Make sure the scope is valid + if (!\in_array($mode, $validModes)) { + throw new \InvalidArgumentException(sprintf('The %s mode is not valid. Valid modes are "gfm" or "markdown".', $mode)); + } - // Build the request path. - $path = '/markdown'; + // Build the request path. + $path = '/markdown'; - // Build the request data. - $data = str_replace( - '\\/', - '/', - json_encode( - [ - 'text' => $text, - 'mode' => $mode, - 'context' => $context, - ] - ) - ); + // Build the request data. + $data = str_replace( + '\\/', + '/', + json_encode( + [ + 'text' => $text, + 'mode' => $mode, + 'context' => $context, + ] + ) + ); - // Send the request. - $response = $this->client->post($this->fetchUrl($path), $data); + // Send the request. + $response = $this->client->post($this->fetchUrl($path), $data); - // Validate the response code. - if ($response->code != 200) - { - // Decode the error response and throw an exception. - $error = json_decode($response->body); - $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; + // Validate the response code. + if ($response->code != 200) { + // Decode the error response and throw an exception. + $error = json_decode($response->body); + $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; - throw new UnexpectedResponseException($response, $message, $response->code); - } + throw new UnexpectedResponseException($response, $message, $response->code); + } - return $response->body; - } + return $response->body; + } } diff --git a/src/Package/Meta.php b/src/Package/Meta.php index c4a2c083..bf41c153 100644 --- a/src/Package/Meta.php +++ b/src/Package/Meta.php @@ -17,18 +17,18 @@ */ class Meta extends AbstractPackage { - /** - * Method to get the authorized IP addresses for services - * - * @return array Authorized IP addresses in CIDR format - * - * @since 1.0 - */ - public function getMeta() - { - // Build the request path. - $path = '/meta'; + /** + * Method to get the authorized IP addresses for services + * + * @return array Authorized IP addresses in CIDR format + * + * @since 1.0 + */ + public function getMeta() + { + // Build the request path. + $path = '/meta'; - return $this->processResponse($this->client->get($this->fetchUrl($path)), 200); - } + return $this->processResponse($this->client->get($this->fetchUrl($path)), 200); + } } diff --git a/src/Package/Orgs.php b/src/Package/Orgs.php index fa7d6aac..7adf1d7f 100644 --- a/src/Package/Orgs.php +++ b/src/Package/Orgs.php @@ -23,86 +23,84 @@ */ class Orgs extends AbstractPackage { - /** - * List user organizations. - * - * If a user name is given, public and private organizations for the authenticated user will be listed. - * - * @param string $user The user name. - * - * @return object - * - * @since 1.0 - */ - public function getList($user = '') - { - // Build the request path. - $path = ($user) - ? '/users/' . $user . '/orgs' - : '/user/orgs'; + /** + * List user organizations. + * + * If a user name is given, public and private organizations for the authenticated user will be listed. + * + * @param string $user The user name. + * + * @return object + * + * @since 1.0 + */ + public function getList($user = '') + { + // Build the request path. + $path = ($user) + ? '/users/' . $user . '/orgs' + : '/user/orgs'; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Get an organization. - * - * @param string $org The organization name. - * - * @return object - * - * @since 1.0 - */ - public function get($org) - { - // Build the request path. - $path = '/orgs/' . $org; + /** + * Get an organization. + * + * @param string $org The organization name. + * + * @return object + * + * @since 1.0 + */ + public function get($org) + { + // Build the request path. + $path = '/orgs/' . $org; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Edit an organization. - * - * @param string $org The organization name. - * @param string $billingEmail Billing email address. This address is not publicized. - * @param string $company The company name. - * @param string $email The email address. - * @param string $location The location name. - * @param string $name The name. - * - * @return object - * - * @since 1.0 - */ - public function edit($org, $billingEmail = '', $company = '', $email = '', $location = '', $name = '') - { - // Build the request path. - $path = '/orgs/' . $org; + /** + * Edit an organization. + * + * @param string $org The organization name. + * @param string $billingEmail Billing email address. This address is not publicized. + * @param string $company The company name. + * @param string $email The email address. + * @param string $location The location name. + * @param string $name The name. + * + * @return object + * + * @since 1.0 + */ + public function edit($org, $billingEmail = '', $company = '', $email = '', $location = '', $name = '') + { + // Build the request path. + $path = '/orgs/' . $org; - $args = ['billing_email', 'company', 'email', 'location', 'name']; + $args = ['billing_email', 'company', 'email', 'location', 'name']; - $data = []; + $data = []; - $fArgs = \func_get_args(); + $fArgs = \func_get_args(); - foreach ($args as $i => $arg) - { - if (array_key_exists($i + 1, $fArgs) && $fArgs[$i + 1]) - { - $data[$arg] = $fArgs[$i + 1]; - } - } + foreach ($args as $i => $arg) { + if (array_key_exists($i + 1, $fArgs) && $fArgs[$i + 1]) { + $data[$arg] = $fArgs[$i + 1]; + } + } - // Send the request. - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), $data) - ); - } + // Send the request. + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), $data) + ); + } } diff --git a/src/Package/Orgs/Hooks.php b/src/Package/Orgs/Hooks.php index 77491347..7a1bf077 100644 --- a/src/Package/Orgs/Hooks.php +++ b/src/Package/Orgs/Hooks.php @@ -22,228 +22,215 @@ */ class Hooks extends AbstractPackage { - /** - * List hooks. - * - * @param string $org The name of the organization. - * - * @return object - * - * @since 1.4.0 - */ - public function getList($org) - { - // Build the request path. - $path = "/orgs/$org/hooks"; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Get single hook. - * - * @param string $org The name of the organization. - * @param integer $id The hook id. - * - * @return object - * - * @since 1.4.0 - */ - public function get($org, $id) - { - // Build the request path. - $path = "/orgs/$org/hooks/" . (int) $id; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Create a hook. - * - * @param string $org The name of the organization. - * @param string $url The URL to which the payloads will be delivered. - * @param string $contentType The media type used to serialize the payloads. Supported values include "json" and "form". - * @param string $secret If provided, payloads will be delivered with an X-Hub-Signature header. - * The value of this header is computed as the - * [HMAC hex digest of the body, using the secret as the key][hub-signature]. - * @param boolean $insecureSsl Determines whether the SSL certificate of the host for url will be verified when delivering payloads. - * If false, verification is performed. If true, verification is not performed. - * @param array $events Determines what events the hook is triggered for. - * @param boolean $active Determines whether the hook is actually triggered on pushes. - * - * @return object - * - * @since 1.4.0 - * @throws \UnexpectedValueException - */ - public function create($org, $url, $contentType = 'form', $secret = null, $insecureSsl = false, array $events = ['push'], $active = true) - { - // Build the request path. - $path = "/orgs/$org/hooks"; - - if (\in_array($contentType, ['form', 'json']) == false) - { - throw new \UnexpectedValueException('Content type must be either "form" or "json".'); - } - - $config = [ - 'url' => $url, - 'content_type' => $contentType, - 'insecure_ssl' => (int) $insecureSsl, - ]; - - if ($secret) - { - $config['secret'] = $secret; - } - - $data = [ - 'name' => 'web', - 'active' => $active, - 'config' => (object) $config, - ]; - - if (!empty($events)) - { - // Check to ensure all events are in the allowed list - foreach ($events as $event) - { - if (!\in_array($event, $this->hookEvents)) - { - throw new \RuntimeException('Your events array contains an unauthorized event.'); - } - } - - $data['events'] = $events; - } - - return $this->processResponse( - $this->client->post($this->fetchUrl($path), $data), - 201 - ); - } - - /** - * Edit a hook. - * - * @param string $org The name of the organization. - * @param string $url The URL to which the payloads will be delivered. - * @param string $contentType The media type used to serialize the payloads. Supported values include "json" and "form". - * @param string $secret If provided, payloads will be delivered with an X-Hub-Signature header. - * The value of this header is computed as the - * [HMAC hex digest of the body, using the secret as the key][hub-signature]. - * @param boolean $insecureSsl Determines whether the SSL certificate of the host for url will be verified when delivering payloads. - * If false, verification is performed. If true, verification is not performed. - * @param array $events Determines what events the hook is triggered for. - * @param boolean $active Determines whether the hook is actually triggered on pushes. - * - * @return object - * - * @since 1.4.0 - * @throws \UnexpectedValueException - */ - public function edit($org, $url, $contentType = null, $secret = null, $insecureSsl = null, array $events = [], $active = null) - { - // Build the request path. - $path = "/orgs/$org/hooks"; - - $config = [ - 'url' => $url, - ]; - - if ($contentType) - { - if (\in_array($contentType, ['form', 'json']) == false) - { - throw new \UnexpectedValueException('Content type must be either "form" or "json".'); - } - - $config['content_type'] = $contentType; - } - - if ($insecureSsl !== null) - { - $config['insecure_ssl'] = (int) $insecureSsl; - } - - if ($secret) - { - $config['secret'] = $secret; - } - - $data = [ - 'config' => (object) $config, - ]; - - if ($active !== null) - { - $data['active'] = (bool) $active; - } - - if (!empty($events)) - { - // Check to ensure all events are in the allowed list - foreach ($events as $event) - { - if (!\in_array($event, $this->hookEvents)) - { - throw new \RuntimeException('Your events array contains an unauthorized event.'); - } - } - - $data['events'] = $events; - } - - return $this->processResponse( - $this->client->post($this->fetchUrl($path), $data), - 201 - ); - } - - /** - * Ping a hook. - * - * @param string $org The name of the organization - * @param integer $id ID of the hook to ping - * - * @return object - * - * @since 1.4.0 - * @throws \DomainException - */ - public function ping($org, $id) - { - // Build the request path. - $path = "/orgs/$org/hooks/$id/pings"; - - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode('')), - 204 - ); - } - - /** - * Delete a hook. - * - * @param string $org The name of the organization - * @param integer $id ID of the hook to delete - * - * @return object - * - * @since 1.4.0 - */ - public function delete($org, $id) - { - // Build the request path. - $path = "/orgs/$org/hooks/$id"; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + /** + * List hooks. + * + * @param string $org The name of the organization. + * + * @return object + * + * @since 1.4.0 + */ + public function getList($org) + { + // Build the request path. + $path = "/orgs/$org/hooks"; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Get single hook. + * + * @param string $org The name of the organization. + * @param integer $id The hook id. + * + * @return object + * + * @since 1.4.0 + */ + public function get($org, $id) + { + // Build the request path. + $path = "/orgs/$org/hooks/" . (int) $id; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Create a hook. + * + * @param string $org The name of the organization. + * @param string $url The URL to which the payloads will be delivered. + * @param string $contentType The media type used to serialize the payloads. Supported values include "json" and "form". + * @param string $secret If provided, payloads will be delivered with an X-Hub-Signature header. + * The value of this header is computed as the + * [HMAC hex digest of the body, using the secret as the key][hub-signature]. + * @param boolean $insecureSsl Determines whether the SSL certificate of the host for url will be verified when delivering payloads. + * If false, verification is performed. If true, verification is not performed. + * @param array $events Determines what events the hook is triggered for. + * @param boolean $active Determines whether the hook is actually triggered on pushes. + * + * @return object + * + * @since 1.4.0 + * @throws \UnexpectedValueException + */ + public function create($org, $url, $contentType = 'form', $secret = null, $insecureSsl = false, array $events = ['push'], $active = true) + { + // Build the request path. + $path = "/orgs/$org/hooks"; + + if (\in_array($contentType, ['form', 'json']) == false) { + throw new \UnexpectedValueException('Content type must be either "form" or "json".'); + } + + $config = [ + 'url' => $url, + 'content_type' => $contentType, + 'insecure_ssl' => (int) $insecureSsl, + ]; + + if ($secret) { + $config['secret'] = $secret; + } + + $data = [ + 'name' => 'web', + 'active' => $active, + 'config' => (object) $config, + ]; + + if (!empty($events)) { + // Check to ensure all events are in the allowed list + foreach ($events as $event) { + if (!\in_array($event, $this->hookEvents)) { + throw new \RuntimeException('Your events array contains an unauthorized event.'); + } + } + + $data['events'] = $events; + } + + return $this->processResponse( + $this->client->post($this->fetchUrl($path), $data), + 201 + ); + } + + /** + * Edit a hook. + * + * @param string $org The name of the organization. + * @param string $url The URL to which the payloads will be delivered. + * @param string $contentType The media type used to serialize the payloads. Supported values include "json" and "form". + * @param string $secret If provided, payloads will be delivered with an X-Hub-Signature header. + * The value of this header is computed as the + * [HMAC hex digest of the body, using the secret as the key][hub-signature]. + * @param boolean $insecureSsl Determines whether the SSL certificate of the host for url will be verified when delivering payloads. + * If false, verification is performed. If true, verification is not performed. + * @param array $events Determines what events the hook is triggered for. + * @param boolean $active Determines whether the hook is actually triggered on pushes. + * + * @return object + * + * @since 1.4.0 + * @throws \UnexpectedValueException + */ + public function edit($org, $url, $contentType = null, $secret = null, $insecureSsl = null, array $events = [], $active = null) + { + // Build the request path. + $path = "/orgs/$org/hooks"; + + $config = [ + 'url' => $url, + ]; + + if ($contentType) { + if (\in_array($contentType, ['form', 'json']) == false) { + throw new \UnexpectedValueException('Content type must be either "form" or "json".'); + } + + $config['content_type'] = $contentType; + } + + if ($insecureSsl !== null) { + $config['insecure_ssl'] = (int) $insecureSsl; + } + + if ($secret) { + $config['secret'] = $secret; + } + + $data = [ + 'config' => (object) $config, + ]; + + if ($active !== null) { + $data['active'] = (bool) $active; + } + + if (!empty($events)) { + // Check to ensure all events are in the allowed list + foreach ($events as $event) { + if (!\in_array($event, $this->hookEvents)) { + throw new \RuntimeException('Your events array contains an unauthorized event.'); + } + } + + $data['events'] = $events; + } + + return $this->processResponse( + $this->client->post($this->fetchUrl($path), $data), + 201 + ); + } + + /** + * Ping a hook. + * + * @param string $org The name of the organization + * @param integer $id ID of the hook to ping + * + * @return object + * + * @since 1.4.0 + * @throws \DomainException + */ + public function ping($org, $id) + { + // Build the request path. + $path = "/orgs/$org/hooks/$id/pings"; + + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode('')), + 204 + ); + } + + /** + * Delete a hook. + * + * @param string $org The name of the organization + * @param integer $id ID of the hook to delete + * + * @return object + * + * @since 1.4.0 + */ + public function delete($org, $id) + { + // Build the request path. + $path = "/orgs/$org/hooks/$id"; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } } diff --git a/src/Package/Orgs/Members.php b/src/Package/Orgs/Members.php index 023344a3..c30e343d 100644 --- a/src/Package/Orgs/Members.php +++ b/src/Package/Orgs/Members.php @@ -19,338 +19,333 @@ */ class Members extends AbstractPackage { - /** - * Members list. - * - * List all users who are members of an organization. - * A member is a user that belongs to at least 1 team in the organization. - * If the authenticated user is also a member of this organization then - * both concealed and public members will be returned. - * If the requester is not a member of the organization the query will be - * redirected to the public members list. - * - * @param string $org The name of the organization. - * - * @throws \UnexpectedValueException - * @since 1.0 - * - * @return boolean|mixed - */ - public function getList($org) - { - // Build the request path. - $path = '/orgs/' . $org . '/members'; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->code) - { - case 302 : - // Requester is not an organization member. - return false; - - case 200 : - return json_decode($response->body); - - default : - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - } - - /** - * Check membership. - * - * Check if a user is, publicly or privately, a member of the organization. - * - * @param string $org The name of the organization. - * @param string $user The name of the user. - * - * @throws \UnexpectedValueException - * @since 1.0 - * - * @return boolean - */ - public function check($org, $user) - { - // Build the request path. - $path = '/orgs/' . $org . '/members/' . $user; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->code) - { - case 204 : - // Requester is an organization member and user is a member. - return true; - - case 404 : - // Requester is an organization member and user is not a member. - // Requester is not an organization member and is inquiring about themselves. - return false; - - case 302 : - // Requester is not an organization member. - return false; - - default : - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - } - - /** - * Add a member. - * - * To add someone as a member to an org, you must add them to a team. - */ - - /** - * Remove a member. - * - * Removing a user from this list will remove them from all teams and they will no longer have - * any access to the organization’s repositories. - * - * @param string $org The name of the organization. - * @param string $user The name of the user. - * - * @since 1.0 - * - * @return object - */ - public function remove($org, $user) - { - // Build the request path. - $path = '/orgs/' . $org . '/members/' . $user; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * Public members list. - * - * Members of an organization can choose to have their membership publicized or not. - * - * @param string $org The name of the organization. - * - * @since 1.0 - * - * @return object - */ - public function getListPublic($org) - { - // Build the request path. - $path = '/orgs/' . $org . '/public_members'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Check public membership. - * - * @param string $org The name of the organization. - * @param string $user The name of the user. - * - * @throws \UnexpectedValueException - * @since 1.0 - * - * @return boolean - */ - public function checkPublic($org, $user) - { - // Build the request path. - $path = '/orgs/' . $org . '/public_members/' . $user; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->code) - { - case 204 : - // Response if user is a public member. - return true; - - case 404 : - // Response if user is not a public member. - return false; - - default : - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - } - - /** - * Publicize a user’s membership. - * - * @param string $org The name of the organization. - * @param string $user The name of the user. - * - * @since 1.0 - * - * @return object - */ - public function publicize($org, $user) - { - // Build the request path. - $path = '/orgs/' . $org . '/public_members/' . $user; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), ''), - 204 - ); - } - - /** - * Conceal a user’s membership. - * - * @param string $org The name of the organization. - * @param string $user The name of the user. - * - * @since 1.0 - * - * @return object - */ - public function conceal($org, $user) - { - // Build the request path. - $path = '/orgs/' . $org . '/public_members/' . $user; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * Get organization membership - * - * In order to get a user's membership with an organization, the authenticated user must be an organization owner. - * - * @param string $org The name of the organization. - * @param string $user The name of the user. - * - * @return object - * - * @since 1.4.0 - */ - public function getMembership($org, $user) - { - // Build the request path. - $path = '/orgs/' . $org . '/memberships/' . $user; - - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Add or update organization membership - * - * In order to create or update a user's membership with an organization, the authenticated user must be an organization owner. - * - * @param string $org The name of the organization. - * @param string $user The name of the user. - * @param string $role The role to give the user in the organization. Can be either 'member' or 'admin'. - * - * @return object - * - * @since 1.4.0 - */ - public function updateMembership($org, $user, $role = 'member') - { - $allowedRoles = ['member', 'admin']; - - if (!\in_array($role, $allowedRoles)) - { - throw new \InvalidArgumentException(sprintf("The user's role must be: %s", implode(', ', $allowedRoles))); - } - - // Build the request path. - $path = "/orgs/$org/memberships/$user"; - - $data = [ - 'role' => $role, - ]; - - return $this->processResponse($this->client->put($this->fetchUrl($path), json_encode($data))); - } - - /** - * Remove organization membership - * - * In order to remove a user's membership with an organization, the authenticated user must be an organization owner. - * - * @param string $org The name of the organization. - * @param string $user The name of the user. - * - * @return object - * - * @since 1.4.0 - */ - public function removeMembership($org, $user) - { - // Build the request path. - $path = '/orgs/' . $org . '/memberships/' . $user; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * List your organization memberships - * - * @return object - * - * @since 1.4.0 - */ - public function listMemberships() - { - // Build the request path. - $path = '/user/memberships/orgs'; - - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Get your organization membership - * - * @param string $org The name of the organization. - * - * @return object - * - * @since 1.4.0 - */ - public function listOrganizationMembership($org) - { - // Build the request path. - $path = '/user/memberships/orgs/' . $org; - - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Edit your organization membership - * - * @param string $org The name of the organization. - * @param string $state The state that the membership should be in. - * - * @return object - * - * @since 1.4.0 - */ - public function editOrganizationMembership($org, $state) - { - // The API only accepts $state == 'active' at present - if ($state != 'active') - { - throw new \InvalidArgumentException('The state must be "active".'); - } - - // Build the request path. - $path = '/user/memberships/orgs/' . $org; - - return $this->processResponse($this->client->patch($this->fetchUrl($path), ['state' => $state])); - } + /** + * Members list. + * + * List all users who are members of an organization. + * A member is a user that belongs to at least 1 team in the organization. + * If the authenticated user is also a member of this organization then + * both concealed and public members will be returned. + * If the requester is not a member of the organization the query will be + * redirected to the public members list. + * + * @param string $org The name of the organization. + * + * @throws \UnexpectedValueException + * @since 1.0 + * + * @return boolean|mixed + */ + public function getList($org) + { + // Build the request path. + $path = '/orgs/' . $org . '/members'; + + $response = $this->client->get($this->fetchUrl($path)); + + switch ($response->code) { + case 302: + // Requester is not an organization member. + return false; + + case 200: + return json_decode($response->body); + + default: + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + } + + /** + * Check membership. + * + * Check if a user is, publicly or privately, a member of the organization. + * + * @param string $org The name of the organization. + * @param string $user The name of the user. + * + * @throws \UnexpectedValueException + * @since 1.0 + * + * @return boolean + */ + public function check($org, $user) + { + // Build the request path. + $path = '/orgs/' . $org . '/members/' . $user; + + $response = $this->client->get($this->fetchUrl($path)); + + switch ($response->code) { + case 204: + // Requester is an organization member and user is a member. + return true; + + case 404: + // Requester is an organization member and user is not a member. + // Requester is not an organization member and is inquiring about themselves. + return false; + + case 302: + // Requester is not an organization member. + return false; + + default: + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + } + + /** + * Add a member. + * + * To add someone as a member to an org, you must add them to a team. + */ + + /** + * Remove a member. + * + * Removing a user from this list will remove them from all teams and they will no longer have + * any access to the organization’s repositories. + * + * @param string $org The name of the organization. + * @param string $user The name of the user. + * + * @since 1.0 + * + * @return object + */ + public function remove($org, $user) + { + // Build the request path. + $path = '/orgs/' . $org . '/members/' . $user; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * Public members list. + * + * Members of an organization can choose to have their membership publicized or not. + * + * @param string $org The name of the organization. + * + * @since 1.0 + * + * @return object + */ + public function getListPublic($org) + { + // Build the request path. + $path = '/orgs/' . $org . '/public_members'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Check public membership. + * + * @param string $org The name of the organization. + * @param string $user The name of the user. + * + * @throws \UnexpectedValueException + * @since 1.0 + * + * @return boolean + */ + public function checkPublic($org, $user) + { + // Build the request path. + $path = '/orgs/' . $org . '/public_members/' . $user; + + $response = $this->client->get($this->fetchUrl($path)); + + switch ($response->code) { + case 204: + // Response if user is a public member. + return true; + + case 404: + // Response if user is not a public member. + return false; + + default: + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + } + + /** + * Publicize a user’s membership. + * + * @param string $org The name of the organization. + * @param string $user The name of the user. + * + * @since 1.0 + * + * @return object + */ + public function publicize($org, $user) + { + // Build the request path. + $path = '/orgs/' . $org . '/public_members/' . $user; + + return $this->processResponse( + $this->client->put($this->fetchUrl($path), ''), + 204 + ); + } + + /** + * Conceal a user’s membership. + * + * @param string $org The name of the organization. + * @param string $user The name of the user. + * + * @since 1.0 + * + * @return object + */ + public function conceal($org, $user) + { + // Build the request path. + $path = '/orgs/' . $org . '/public_members/' . $user; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * Get organization membership + * + * In order to get a user's membership with an organization, the authenticated user must be an organization owner. + * + * @param string $org The name of the organization. + * @param string $user The name of the user. + * + * @return object + * + * @since 1.4.0 + */ + public function getMembership($org, $user) + { + // Build the request path. + $path = '/orgs/' . $org . '/memberships/' . $user; + + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Add or update organization membership + * + * In order to create or update a user's membership with an organization, the authenticated user must be an organization owner. + * + * @param string $org The name of the organization. + * @param string $user The name of the user. + * @param string $role The role to give the user in the organization. Can be either 'member' or 'admin'. + * + * @return object + * + * @since 1.4.0 + */ + public function updateMembership($org, $user, $role = 'member') + { + $allowedRoles = ['member', 'admin']; + + if (!\in_array($role, $allowedRoles)) { + throw new \InvalidArgumentException(sprintf("The user's role must be: %s", implode(', ', $allowedRoles))); + } + + // Build the request path. + $path = "/orgs/$org/memberships/$user"; + + $data = [ + 'role' => $role, + ]; + + return $this->processResponse($this->client->put($this->fetchUrl($path), json_encode($data))); + } + + /** + * Remove organization membership + * + * In order to remove a user's membership with an organization, the authenticated user must be an organization owner. + * + * @param string $org The name of the organization. + * @param string $user The name of the user. + * + * @return object + * + * @since 1.4.0 + */ + public function removeMembership($org, $user) + { + // Build the request path. + $path = '/orgs/' . $org . '/memberships/' . $user; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * List your organization memberships + * + * @return object + * + * @since 1.4.0 + */ + public function listMemberships() + { + // Build the request path. + $path = '/user/memberships/orgs'; + + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Get your organization membership + * + * @param string $org The name of the organization. + * + * @return object + * + * @since 1.4.0 + */ + public function listOrganizationMembership($org) + { + // Build the request path. + $path = '/user/memberships/orgs/' . $org; + + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Edit your organization membership + * + * @param string $org The name of the organization. + * @param string $state The state that the membership should be in. + * + * @return object + * + * @since 1.4.0 + */ + public function editOrganizationMembership($org, $state) + { + // The API only accepts $state == 'active' at present + if ($state != 'active') { + throw new \InvalidArgumentException('The state must be "active".'); + } + + // Build the request path. + $path = '/user/memberships/orgs/' . $org; + + return $this->processResponse($this->client->patch($this->fetchUrl($path), ['state' => $state])); + } } diff --git a/src/Package/Orgs/Teams.php b/src/Package/Orgs/Teams.php index d42885bc..103b1ba8 100644 --- a/src/Package/Orgs/Teams.php +++ b/src/Package/Orgs/Teams.php @@ -22,484 +22,475 @@ */ class Teams extends AbstractPackage { - /** - * List teams. - * - * @param string $org The name of the organization. - * - * @return object - * - * @since 1.0 - */ - public function getList($org) - { - // Build the request path. - $path = '/orgs/' . $org . '/teams'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Get team. - * - * @param integer $id The team id. - * - * @return object - * - * @since 1.0 - */ - public function get($id) - { - // Build the request path. - $path = '/teams/' . (int) $id; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Create team. - * - * In order to create a team, the authenticated user must be an owner of the organization. - * - * @param string $org The name of the organization. - * @param string $name The name of the team. - * @param array $repoNames Repository names. - * @param string $permission The permission. (Deprecated) - * pull - team members can pull, but not push to or administer these repositories. Default - * push - team members can pull and push, but not administer these repositories. - * admin - team members can pull, push and administer these repositories. - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function create($org, $name, array $repoNames = [], $permission = '') - { - // Build the request path. - $path = '/orgs/' . $org . '/teams'; - - $data = [ - 'name' => $name, - ]; - - if ($repoNames) - { - $data['repo_names'] = $repoNames; - } - - if ($permission) - { - if (\in_array($permission, ['pull', 'push', 'admin']) == false) - { - throw new \UnexpectedValueException('Permissions must be either "pull", "push", or "admin".'); - } - - $data['permission'] = $permission; - } - - return $this->processResponse( - $this->client->post($this->fetchUrl($path), $data), - 201 - ); - } - - /** - * Edit team. - * - * In order to edit a team, the authenticated user must be an owner of the org that the team is associated with. - * - * @param integer $id The team id. - * @param string $name The name of the team. - * @param string $permission The permission. (Deprecated) - * pull - team members can pull, but not push to or administer these repositories. Default - * push - team members can pull and push, but not administer these repositories. - * admin - team members can pull, push and administer these repositories. - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function edit($id, $name, $permission = '') - { - // Build the request path. - $path = '/teams/' . (int) $id; - - $data = [ - 'name' => $name, - ]; - - if ($permission) - { - if (\in_array($permission, ['pull', 'push', 'admin']) == false) - { - throw new \UnexpectedValueException('Permissions must be either "pull", "push", or "admin".'); - } - - $data['permission'] = $permission; - } - - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), $data) - ); - } - - /** - * Delete team. - * - * In order to delete a team, the authenticated user must be an owner of the org that the team is associated with. - * - * @param integer $id The team id. - * - * @return object - * - * @since 1.0 - */ - public function delete($id) - { - // Build the request path. - $path = '/teams/' . $id; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * List team members. - * - * In order to list members in a team, the authenticated user must be a member of the team. - * - * @param integer $id The team id. - * - * @return object - * - * @since 1.0 - */ - public function getListMembers($id) - { - // Build the request path. - $path = '/teams/' . $id . '/members'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Get team member. - * - * In order to get if a user is a member of a team, the authenticated user must be a member of the team. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * - * @return boolean - * - * @since 1.0 - * @throws \UnexpectedValueException - * @deprecated Use getTeamMembership() instead - */ - public function isMember($id, $user) - { - // Build the request path. - $path = '/teams/' . $id . '/members/' . $user; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->code) - { - case 204 : - // Response if user is a member - return true; - - case 404 : - // Response if user is not a member - return false; - - default : - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - } - - /** - * Add team member. - * - * In order to add a user to a team, the authenticated user must have ‘admin’ permissions - * to the team or be an owner of the org that the team is associated with. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * - * @return object - * - * @since 1.0 - * @deprecated Use addTeamMembership() instead - */ - public function addMember($id, $user) - { - // Build the request path. - $path = '/teams/' . $id . '/members/' . $user; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), ''), - 204 - ); - } - - /** - * Remove team member. - * - * In order to remove a user from a team, the authenticated user must have ‘admin’ permissions - * to the team or be an owner of the org that the team is associated with. - * NOTE: This does not delete the user, it just remove them from the team. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * - * @return object - * - * @since 1.0 - * @deprecated Use removeTeamMembership() instead - */ - public function removeMember($id, $user) - { - // Build the request path. - $path = '/teams/' . $id . '/members/' . $user; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * Get team membership - * - * In order to get a user's membership with a team, the team must be visible to the authenticated user. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * - * @return string|boolean The state the user's membership is in or boolean false if the user is not a member. - * - * @since 1.4.0 - * @throws \UnexpectedValueException - */ - public function getTeamMembership($id, $user) - { - // Build the request path. - $path = "/teams/$id/memberships/$user"; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->code) - { - case 200 : - // Response if user is an active member or pending membership - $body = json_decode($response->body); - - return $body->state; - - case 404 : - // Response if user is not a member - return false; - - default : - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - } - - /** - * Add team membership - * - * If the user is already a member of the team's organization, this endpoint will add the user to the team. - * In order to add a membership between an organization member and a team, the authenticated user must be - * an organization owner or a maintainer of the team. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * @param string $role The role the user should have on the team. Can be either 'member' or 'maintainer'. - * - * @return object - * - * @since 1.4.0 - * @throws \UnexpectedValueException - */ - public function addTeamMembership($id, $user, $role = 'member') - { - // Build the request path. - $path = "/teams/$id/memberships/$user"; - - if (\in_array($role, ['member', 'maintainer']) == false) - { - throw new \UnexpectedValueException('Roles must be either "member" or "maintainer".'); - } - - $data = [ - 'role' => $role, - ]; - - return $this->processResponse($this->client->put($this->fetchUrl($path), $data)); - } - - /** - * Remove team membership - * - * In order to remove a membership between a user and a team, the authenticated user must have 'admin' permissions to the team - * or be an owner of the organization that the team is associated with. - * NOTE: This does not delete the user, it just removes their membership from the team. - * - * @param integer $id The team id. - * @param string $user The name of the user. - * - * @return object - * - * @since 1.4.0 - * @throws \UnexpectedValueException - */ - public function removeTeamMembership($id, $user) - { - // Build the request path. - $path = "/teams/$id/memberships/$user"; - - return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - } - - /** - * List team repos. - * - * @param integer $id The team id. - * - * @return object - * - * @since 1.0 - */ - public function getListRepos($id) - { - // Build the request path. - $path = '/teams/' . $id . '/repos'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Check if a team manages a repository. - * - * @param integer $id The team id. - * @param string $owner The owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return boolean - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function checkRepo($id, $owner, $repo) - { - // Build the request path. - $path = '/teams/' . $id . '/repos/' . $owner . '/' . $repo; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->code) - { - case 204 : - // Response if repo is managed by this team. - return true; - - case 404 : - // Response if repo is not managed by this team. - return false; - - default : - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - } - - /** - * Add or update team repository. - * - * In order to add a repo to a team, the authenticated user must be an owner of the - * org that the team is associated with. Also, the repo must be owned by the organization, - * or a direct form of a repo owned by the organization. - * - * If you attempt to add a repo to a team that is not owned by the organization, you get: - * Status: 422 Unprocessable Entity - * - * @param integer $id The team id. - * @param string $org The name of the organization of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return object - * - * @since 1.0 - */ - public function addRepo($id, $org, $repo) - { - // Build the request path. - $path = '/teams/' . $id . '/repos/' . $org . '/' . $repo; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), ''), - 204 - ); - } - - /** - * Remove team repository. - * - * In order to remove a repo from a team, the authenticated user must be an owner - * of the org that the team is associated with. NOTE: This does not delete the - * repo, it just removes it from the team. - * - * @param integer $id The team id. - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return object - * - * @since 1.0 - */ - public function removeRepo($id, $owner, $repo) - { - // Build the request path. - $path = '/teams/' . (int) $id . '/repos/' . $owner . '/' . $repo; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * List user teams. - * - * List all of the teams across all of the organizations to which the authenticated user belongs. - * This method requires user, repo, or read:org scope when authenticating via OAuth. - * - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.4.0 - */ - public function getUserTeams($page = 0, $limit = 0) - { - // Build the request path. - $path = '/user/teams'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path, $page, $limit)) - ); - } + /** + * List teams. + * + * @param string $org The name of the organization. + * + * @return object + * + * @since 1.0 + */ + public function getList($org) + { + // Build the request path. + $path = '/orgs/' . $org . '/teams'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Get team. + * + * @param integer $id The team id. + * + * @return object + * + * @since 1.0 + */ + public function get($id) + { + // Build the request path. + $path = '/teams/' . (int) $id; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Create team. + * + * In order to create a team, the authenticated user must be an owner of the organization. + * + * @param string $org The name of the organization. + * @param string $name The name of the team. + * @param array $repoNames Repository names. + * @param string $permission The permission. (Deprecated) + * pull - team members can pull, but not push to or administer these repositories. Default + * push - team members can pull and push, but not administer these repositories. + * admin - team members can pull, push and administer these repositories. + * + * @return object + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function create($org, $name, array $repoNames = [], $permission = '') + { + // Build the request path. + $path = '/orgs/' . $org . '/teams'; + + $data = [ + 'name' => $name, + ]; + + if ($repoNames) { + $data['repo_names'] = $repoNames; + } + + if ($permission) { + if (\in_array($permission, ['pull', 'push', 'admin']) == false) { + throw new \UnexpectedValueException('Permissions must be either "pull", "push", or "admin".'); + } + + $data['permission'] = $permission; + } + + return $this->processResponse( + $this->client->post($this->fetchUrl($path), $data), + 201 + ); + } + + /** + * Edit team. + * + * In order to edit a team, the authenticated user must be an owner of the org that the team is associated with. + * + * @param integer $id The team id. + * @param string $name The name of the team. + * @param string $permission The permission. (Deprecated) + * pull - team members can pull, but not push to or administer these repositories. Default + * push - team members can pull and push, but not administer these repositories. + * admin - team members can pull, push and administer these repositories. + * + * @return object + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function edit($id, $name, $permission = '') + { + // Build the request path. + $path = '/teams/' . (int) $id; + + $data = [ + 'name' => $name, + ]; + + if ($permission) { + if (\in_array($permission, ['pull', 'push', 'admin']) == false) { + throw new \UnexpectedValueException('Permissions must be either "pull", "push", or "admin".'); + } + + $data['permission'] = $permission; + } + + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), $data) + ); + } + + /** + * Delete team. + * + * In order to delete a team, the authenticated user must be an owner of the org that the team is associated with. + * + * @param integer $id The team id. + * + * @return object + * + * @since 1.0 + */ + public function delete($id) + { + // Build the request path. + $path = '/teams/' . $id; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * List team members. + * + * In order to list members in a team, the authenticated user must be a member of the team. + * + * @param integer $id The team id. + * + * @return object + * + * @since 1.0 + */ + public function getListMembers($id) + { + // Build the request path. + $path = '/teams/' . $id . '/members'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Get team member. + * + * In order to get if a user is a member of a team, the authenticated user must be a member of the team. + * + * @param integer $id The team id. + * @param string $user The name of the user. + * + * @return boolean + * + * @since 1.0 + * @throws \UnexpectedValueException + * @deprecated Use getTeamMembership() instead + */ + public function isMember($id, $user) + { + // Build the request path. + $path = '/teams/' . $id . '/members/' . $user; + + $response = $this->client->get($this->fetchUrl($path)); + + switch ($response->code) { + case 204: + // Response if user is a member + return true; + + case 404: + // Response if user is not a member + return false; + + default: + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + } + + /** + * Add team member. + * + * In order to add a user to a team, the authenticated user must have ‘admin’ permissions + * to the team or be an owner of the org that the team is associated with. + * + * @param integer $id The team id. + * @param string $user The name of the user. + * + * @return object + * + * @since 1.0 + * @deprecated Use addTeamMembership() instead + */ + public function addMember($id, $user) + { + // Build the request path. + $path = '/teams/' . $id . '/members/' . $user; + + return $this->processResponse( + $this->client->put($this->fetchUrl($path), ''), + 204 + ); + } + + /** + * Remove team member. + * + * In order to remove a user from a team, the authenticated user must have ‘admin’ permissions + * to the team or be an owner of the org that the team is associated with. + * NOTE: This does not delete the user, it just remove them from the team. + * + * @param integer $id The team id. + * @param string $user The name of the user. + * + * @return object + * + * @since 1.0 + * @deprecated Use removeTeamMembership() instead + */ + public function removeMember($id, $user) + { + // Build the request path. + $path = '/teams/' . $id . '/members/' . $user; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * Get team membership + * + * In order to get a user's membership with a team, the team must be visible to the authenticated user. + * + * @param integer $id The team id. + * @param string $user The name of the user. + * + * @return string|boolean The state the user's membership is in or boolean false if the user is not a member. + * + * @since 1.4.0 + * @throws \UnexpectedValueException + */ + public function getTeamMembership($id, $user) + { + // Build the request path. + $path = "/teams/$id/memberships/$user"; + + $response = $this->client->get($this->fetchUrl($path)); + + switch ($response->code) { + case 200: + // Response if user is an active member or pending membership + $body = json_decode($response->body); + + return $body->state; + + case 404: + // Response if user is not a member + return false; + + default: + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + } + + /** + * Add team membership + * + * If the user is already a member of the team's organization, this endpoint will add the user to the team. + * In order to add a membership between an organization member and a team, the authenticated user must be + * an organization owner or a maintainer of the team. + * + * @param integer $id The team id. + * @param string $user The name of the user. + * @param string $role The role the user should have on the team. Can be either 'member' or 'maintainer'. + * + * @return object + * + * @since 1.4.0 + * @throws \UnexpectedValueException + */ + public function addTeamMembership($id, $user, $role = 'member') + { + // Build the request path. + $path = "/teams/$id/memberships/$user"; + + if (\in_array($role, ['member', 'maintainer']) == false) { + throw new \UnexpectedValueException('Roles must be either "member" or "maintainer".'); + } + + $data = [ + 'role' => $role, + ]; + + return $this->processResponse($this->client->put($this->fetchUrl($path), $data)); + } + + /** + * Remove team membership + * + * In order to remove a membership between a user and a team, the authenticated user must have 'admin' permissions to the team + * or be an owner of the organization that the team is associated with. + * NOTE: This does not delete the user, it just removes their membership from the team. + * + * @param integer $id The team id. + * @param string $user The name of the user. + * + * @return object + * + * @since 1.4.0 + * @throws \UnexpectedValueException + */ + public function removeTeamMembership($id, $user) + { + // Build the request path. + $path = "/teams/$id/memberships/$user"; + + return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); + } + + /** + * List team repos. + * + * @param integer $id The team id. + * + * @return object + * + * @since 1.0 + */ + public function getListRepos($id) + { + // Build the request path. + $path = '/teams/' . $id . '/repos'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Check if a team manages a repository. + * + * @param integer $id The team id. + * @param string $owner The owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return boolean + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function checkRepo($id, $owner, $repo) + { + // Build the request path. + $path = '/teams/' . $id . '/repos/' . $owner . '/' . $repo; + + $response = $this->client->get($this->fetchUrl($path)); + + switch ($response->code) { + case 204: + // Response if repo is managed by this team. + return true; + + case 404: + // Response if repo is not managed by this team. + return false; + + default: + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + } + + /** + * Add or update team repository. + * + * In order to add a repo to a team, the authenticated user must be an owner of the + * org that the team is associated with. Also, the repo must be owned by the organization, + * or a direct form of a repo owned by the organization. + * + * If you attempt to add a repo to a team that is not owned by the organization, you get: + * Status: 422 Unprocessable Entity + * + * @param integer $id The team id. + * @param string $org The name of the organization of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return object + * + * @since 1.0 + */ + public function addRepo($id, $org, $repo) + { + // Build the request path. + $path = '/teams/' . $id . '/repos/' . $org . '/' . $repo; + + return $this->processResponse( + $this->client->put($this->fetchUrl($path), ''), + 204 + ); + } + + /** + * Remove team repository. + * + * In order to remove a repo from a team, the authenticated user must be an owner + * of the org that the team is associated with. NOTE: This does not delete the + * repo, it just removes it from the team. + * + * @param integer $id The team id. + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return object + * + * @since 1.0 + */ + public function removeRepo($id, $owner, $repo) + { + // Build the request path. + $path = '/teams/' . (int) $id . '/repos/' . $owner . '/' . $repo; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * List user teams. + * + * List all of the teams across all of the organizations to which the authenticated user belongs. + * This method requires user, repo, or read:org scope when authenticating via OAuth. + * + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.4.0 + */ + public function getUserTeams($page = 0, $limit = 0) + { + // Build the request path. + $path = '/user/teams'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path, $page, $limit)) + ); + } } diff --git a/src/Package/Pulls.php b/src/Package/Pulls.php index 7ddb61ff..c57e5077 100644 --- a/src/Package/Pulls.php +++ b/src/Package/Pulls.php @@ -22,293 +22,286 @@ */ class Pulls extends AbstractPackage { - /** - * Create a pull request. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $title The title of the new pull request. - * @param string $base The branch (or git ref) you want your changes pulled into. This - * should be an existing branch on the current repository. You cannot - * submit a pull request to one repo that requests a merge to a base - * of another repo. - * @param string $head The branch (or git ref) where your changes are implemented. - * @param string $body The body text for the new pull request. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function create($user, $repo, $title, $base, $head, $body = '') - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls'; - - // Build the request data. - $data = json_encode( - [ - 'title' => $title, - 'base' => $base, - 'head' => $head, - 'body' => $body, - ] - ); - - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } - - /** - * Method to create a pull request from an existing issue. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueId The issue number for which to attach the new pull request. - * @param string $base The branch (or git ref) you want your changes pulled into. This - * should be an existing branch on the current repository. You cannot - * submit a pull request to one repo that requests a merge to a base - * of another repo. - * @param string $head The branch (or git ref) where your changes are implemented. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function createFromIssue($user, $repo, $issueId, $base, $head) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls'; - - // Build the request data. - $data = json_encode( - [ - 'issue' => (int) $issueId, - 'base' => $base, - 'head' => $head, - ] - ); - - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } - - /** - * Update a pull request. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $pullId The pull request number. - * @param string $title The optional new title for the pull request. - * @param string $body The optional new body text for the pull request. - * @param string $state The optional new state for the pull request. [open, closed] - * @param string $base The optional new base branch for the pull request. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function edit($user, $repo, $pullId, $title = null, $body = null, $state = null, $base = null) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId; - - // Create the data object. - $data = new \stdClass; - - // If a title is set add it to the data object. - if (isset($title)) - { - $data->title = $title; - } - - // If a body is set add it to the data object. - if (isset($body)) - { - $data->body = $body; - } - - // If a state is set add it to the data object. - if (isset($state)) - { - $data->state = $state; - } - - // If a base branch is set add it to the data object. - if (isset($base)) - { - $data->base = $base; - } - - // Encode the request data. - $data = json_encode($data); - - // Send the request. - return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); - } - - /** - * Get a single pull request. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $pullId The pull request number. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($user, $repo, $pullId) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * List commits on a pull request. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $pullId The pull request number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getCommits($user, $repo, $pullId, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/commits'; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - } - - /** - * List pull requests files. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $pullId The pull request number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getFiles($user, $repo, $pullId, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/files'; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - } - - /** - * List pull requests. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $state The optional state to filter requests by. [open, closed] - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return array - * - * @since 1.0 - * @throws \DomainException - */ - public function getList($user, $repo, $state = 'open', $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls'; - - // If a state exists append it as an option. - if ($state != 'open') - { - $path .= '?state=' . $state; - } - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - } - - /** - * Get if a pull request has been merged. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $pullId The pull request number. The pull request number. - * - * @return boolean True if the pull request has been merged - * - * @since 1.0 - * @throws UnexpectedResponseException - */ - public function isMerged($user, $repo, $pullId) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/merge'; - - // Send the request. - $response = $this->client->get($this->fetchUrl($path)); - - // Validate the response code. - if ($response->code == 204) - { - return true; - } - - if ($response->code == 404) - { - return false; - } - - // Decode the error response and throw an exception. - $error = json_decode($response->body); - $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; - - throw new UnexpectedResponseException($response, $message, $response->code); - } - - /** - * Merge a pull request (Merge Button). - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $pullId The pull request number. - * @param string $message The message that will be used for the merge commit. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function merge($user, $repo, $pullId, $message = '') - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/merge'; - - // Build the request data. - $data = json_encode( - [ - 'commit_message' => $message, - ] - ); - - // Send the request. - return $this->processResponse($this->client->put($this->fetchUrl($path), $data)); - } + /** + * Create a pull request. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $title The title of the new pull request. + * @param string $base The branch (or git ref) you want your changes pulled into. This + * should be an existing branch on the current repository. You cannot + * submit a pull request to one repo that requests a merge to a base + * of another repo. + * @param string $head The branch (or git ref) where your changes are implemented. + * @param string $body The body text for the new pull request. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function create($user, $repo, $title, $base, $head, $body = '') + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls'; + + // Build the request data. + $data = json_encode( + [ + 'title' => $title, + 'base' => $base, + 'head' => $head, + 'body' => $body, + ] + ); + + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } + + /** + * Method to create a pull request from an existing issue. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueId The issue number for which to attach the new pull request. + * @param string $base The branch (or git ref) you want your changes pulled into. This + * should be an existing branch on the current repository. You cannot + * submit a pull request to one repo that requests a merge to a base + * of another repo. + * @param string $head The branch (or git ref) where your changes are implemented. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function createFromIssue($user, $repo, $issueId, $base, $head) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls'; + + // Build the request data. + $data = json_encode( + [ + 'issue' => (int) $issueId, + 'base' => $base, + 'head' => $head, + ] + ); + + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } + + /** + * Update a pull request. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $pullId The pull request number. + * @param string $title The optional new title for the pull request. + * @param string $body The optional new body text for the pull request. + * @param string $state The optional new state for the pull request. [open, closed] + * @param string $base The optional new base branch for the pull request. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function edit($user, $repo, $pullId, $title = null, $body = null, $state = null, $base = null) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId; + + // Create the data object. + $data = new \stdClass(); + + // If a title is set add it to the data object. + if (isset($title)) { + $data->title = $title; + } + + // If a body is set add it to the data object. + if (isset($body)) { + $data->body = $body; + } + + // If a state is set add it to the data object. + if (isset($state)) { + $data->state = $state; + } + + // If a base branch is set add it to the data object. + if (isset($base)) { + $data->base = $base; + } + + // Encode the request data. + $data = json_encode($data); + + // Send the request. + return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); + } + + /** + * Get a single pull request. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $pullId The pull request number. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($user, $repo, $pullId) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * List commits on a pull request. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $pullId The pull request number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getCommits($user, $repo, $pullId, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/commits'; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); + } + + /** + * List pull requests files. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $pullId The pull request number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getFiles($user, $repo, $pullId, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/files'; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); + } + + /** + * List pull requests. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $state The optional state to filter requests by. [open, closed] + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return array + * + * @since 1.0 + * @throws \DomainException + */ + public function getList($user, $repo, $state = 'open', $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls'; + + // If a state exists append it as an option. + if ($state != 'open') { + $path .= '?state=' . $state; + } + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); + } + + /** + * Get if a pull request has been merged. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $pullId The pull request number. The pull request number. + * + * @return boolean True if the pull request has been merged + * + * @since 1.0 + * @throws UnexpectedResponseException + */ + public function isMerged($user, $repo, $pullId) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/merge'; + + // Send the request. + $response = $this->client->get($this->fetchUrl($path)); + + // Validate the response code. + if ($response->code == 204) { + return true; + } + + if ($response->code == 404) { + return false; + } + + // Decode the error response and throw an exception. + $error = json_decode($response->body); + $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; + + throw new UnexpectedResponseException($response, $message, $response->code); + } + + /** + * Merge a pull request (Merge Button). + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $pullId The pull request number. + * @param string $message The message that will be used for the merge commit. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function merge($user, $repo, $pullId, $message = '') + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/merge'; + + // Build the request data. + $data = json_encode( + [ + 'commit_message' => $message, + ] + ); + + // Send the request. + return $this->processResponse($this->client->put($this->fetchUrl($path), $data)); + } } diff --git a/src/Package/Pulls/Comments.php b/src/Package/Pulls/Comments.php index 8dc02185..c6dec4fb 100644 --- a/src/Package/Pulls/Comments.php +++ b/src/Package/Pulls/Comments.php @@ -19,195 +19,195 @@ */ class Comments extends AbstractPackage { - /** - * Create a comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $pullId The pull request number. - * @param string $body The comment body text. - * @param string $commitId The SHA1 hash of the commit to comment on. - * @param string $filePath The Relative path of the file to comment on. - * @param string $position The line index in the diff to comment on. - * - * @since 1.0 - * - * @return object - */ - public function create($user, $repo, $pullId, $body, $commitId, $filePath, $position) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; - - // Build the request data. - $data = json_encode( - [ - 'body' => $body, - 'commit_id' => $commitId, - 'path' => $filePath, - 'position' => $position, - ] - ); - - // Send the request. - return $this->processResponse( - $this->client->post($this->fetchUrl($path), $data), - 201 - ); - } - - /** - * Method to create a comment in reply to another comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $pullId The pull request number. - * @param string $body The comment body text. - * @param integer $inReplyTo The id of the comment to reply to. - * - * @since 1.0 - * - * @return object - */ - public function createReply($user, $repo, $pullId, $body, $inReplyTo) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; - - // Build the request data. - $data = json_encode( - [ - 'body' => $body, - 'in_reply_to' => (int) $inReplyTo, - ] - ); - - // Send the request. - return $this->processResponse( - $this->client->post($this->fetchUrl($path), $data), - 201 - ); - } - - /** - * Delete a comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $commentId The id of the comment to delete. - * - * @since 1.0 - * - * @return void - */ - public function delete($user, $repo, $commentId) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; - - // Send the request. - $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * Edit a comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $commentId The id of the comment to update. - * @param string $body The new body text for the comment. - * - * @since 1.0 - * - * @return object - */ - public function edit($user, $repo, $commentId, $body) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; - - // Build the request data. - $data = json_encode( - [ - 'body' => $body, - ] - ); - - // Send the request. - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), $data) - ); - } - - /** - * Get a single comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $commentId The comment id to get. - * - * @since 1.0 - * - * @return object - */ - public function get($user, $repo, $commentId) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List comments on a pull request. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $pullId The pull request number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @since 1.0 - * - * @return array - */ - public function getList($user, $repo, $pullId, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path, $page, $limit)) - ); - } - - /** - * List comments in a repository. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return array - * - * @since 1.4.0 - */ - public function getListForRepo($user, $repo, $page = 0, $limit = 0) - { - // Build the request path. - $path = "/repos/$user/$repo/pulls/comments"; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path, $page, $limit)) - ); - } + /** + * Create a comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $pullId The pull request number. + * @param string $body The comment body text. + * @param string $commitId The SHA1 hash of the commit to comment on. + * @param string $filePath The Relative path of the file to comment on. + * @param string $position The line index in the diff to comment on. + * + * @since 1.0 + * + * @return object + */ + public function create($user, $repo, $pullId, $body, $commitId, $filePath, $position) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; + + // Build the request data. + $data = json_encode( + [ + 'body' => $body, + 'commit_id' => $commitId, + 'path' => $filePath, + 'position' => $position, + ] + ); + + // Send the request. + return $this->processResponse( + $this->client->post($this->fetchUrl($path), $data), + 201 + ); + } + + /** + * Method to create a comment in reply to another comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $pullId The pull request number. + * @param string $body The comment body text. + * @param integer $inReplyTo The id of the comment to reply to. + * + * @since 1.0 + * + * @return object + */ + public function createReply($user, $repo, $pullId, $body, $inReplyTo) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; + + // Build the request data. + $data = json_encode( + [ + 'body' => $body, + 'in_reply_to' => (int) $inReplyTo, + ] + ); + + // Send the request. + return $this->processResponse( + $this->client->post($this->fetchUrl($path), $data), + 201 + ); + } + + /** + * Delete a comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $commentId The id of the comment to delete. + * + * @since 1.0 + * + * @return void + */ + public function delete($user, $repo, $commentId) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; + + // Send the request. + $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * Edit a comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $commentId The id of the comment to update. + * @param string $body The new body text for the comment. + * + * @since 1.0 + * + * @return object + */ + public function edit($user, $repo, $commentId, $body) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; + + // Build the request data. + $data = json_encode( + [ + 'body' => $body, + ] + ); + + // Send the request. + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), $data) + ); + } + + /** + * Get a single comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $commentId The comment id to get. + * + * @since 1.0 + * + * @return object + */ + public function get($user, $repo, $commentId) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List comments on a pull request. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $pullId The pull request number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @since 1.0 + * + * @return array + */ + public function getList($user, $repo, $pullId, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments'; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path, $page, $limit)) + ); + } + + /** + * List comments in a repository. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return array + * + * @since 1.4.0 + */ + public function getListForRepo($user, $repo, $page = 0, $limit = 0) + { + // Build the request path. + $path = "/repos/$user/$repo/pulls/comments"; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path, $page, $limit)) + ); + } } diff --git a/src/Package/Repositories.php b/src/Package/Repositories.php index cc8ab7f9..6dd5b628 100644 --- a/src/Package/Repositories.php +++ b/src/Package/Repositories.php @@ -35,377 +35,385 @@ */ class Repositories extends AbstractPackage { - /** - * List your repositories. - * - * List repositories for the authenticated user. - * - * @param string $type Sort type. all, owner, public, private, member. Default: all. - * @param string $sort Sort field. created, updated, pushed, full_name, default: full_name. - * @param string $direction Sort direction. asc or desc, default: when using full_name: asc, otherwise desc. - * - * @return object - * - * @since 1.0 - * @throws \RuntimeException - */ - public function getListOwn($type = 'all', $sort = 'full_name', $direction = '') - { - if (\in_array($type, ['all', 'owner', 'public', 'private', 'member']) == false) - { - throw new \RuntimeException('Invalid type'); - } - - if (\in_array($sort, ['created', 'updated', 'pushed', 'full_name']) == false) - { - throw new \RuntimeException('Invalid sort field'); - } - - // Sort direction default: when using full_name: asc, otherwise desc. - $direction = ($direction) ? : (($sort == 'full_name') ? 'asc' : 'desc'); - - if (\in_array($direction, ['asc', 'desc']) == false) - { - throw new \RuntimeException('Invalid sort order'); - } - - // Build the request path. - $uri = $this->fetchUrl('/user/repos'); - $uri->setVar('type', $type); - $uri->setVar('sort', $sort); - $uri->setVar('direction', $direction); - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * List user repositories. - * - * List public repositories for the specified user. - * - * @param string $user The user name. - * @param string $type Sort type. all, owner, member. Default: all. - * @param string $sort Sort field. created, updated, pushed, full_name, default: full_name. - * @param string $direction Sort direction. asc or desc, default: when using full_name: asc, otherwise desc. - * - * @return object - * - * @since 1.0 - * @throws \RuntimeException - */ - public function getListUser($user, $type = 'all', $sort = 'full_name', $direction = '') - { - if (\in_array($type, ['all', 'owner', 'member']) == false) - { - throw new \RuntimeException('Invalid type'); - } - - if (\in_array($sort, ['created', 'updated', 'pushed', 'full_name']) == false) - { - throw new \RuntimeException('Invalid sort field'); - } - - // Sort direction default: when using full_name: asc, otherwise desc. - $direction = $direction ?: ($sort == 'full_name' ? 'asc' : 'desc'); - - if (\in_array($direction, ['asc', 'desc']) == false) - { - throw new \RuntimeException('Invalid sort order'); - } - - // Build the request path. - $uri = $this->fetchUrl('/users/' . $user . '/repos'); - $uri->setVar('type', $type); - $uri->setVar('sort', $sort); - $uri->setVar('direction', $direction); - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * List organization repositories. - * - * List repositories for the specified org. - * - * @param string $org The name of the organization. - * @param string $type Sort type. all, public, private, forks, sources, member. Default: all. - * - * @return object - * - * @since 1.0 - * @throws \RuntimeException - */ - public function getListOrg($org, $type = 'all') - { - if (\in_array($type, ['all', 'public', 'private', 'forks', 'sources', 'member']) == false) - { - throw new \RuntimeException('Invalid type'); - } - - // Build the request path. - $uri = $this->fetchUrl('/orgs/' . $org . '/repos'); - $uri->setVar('type', $type); - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * List all public repositories. - * - * This provides a dump of every repository, in the order that they were created. - * - * @param integer $id The integer ID of the last Repository that you’ve seen. - * - * @return object - * - * @since 1.0 - * @throws \RuntimeException - */ - public function getList($id = 0) - { - // Build the request path. - $uri = $this->fetchUrl('/repositories'); - - if ($id) - { - $uri->setVar('since', (int) $id); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Create. - * - * Create a new repository for the authenticated user or an organization. OAuth users must supply repo scope. - * - * @param string $name The repository name. - * @param string $org The organization name (if needed). - * @param string $description The repository description. - * @param string $homepage The repository homepage. - * @param boolean $private Set true to create a private repository, false to create a public one. Creating private repositories - * requires a paid GitHub account. - * @param boolean $hasIssues Set true to enable issues for this repository, false to disable them. - * @param boolean $hasWiki Set true to enable the wiki for this repository, false to disable it. - * @param boolean $hasDownloads Set true to enable downloads for this repository, false to disable them. - * @param integer $teamId The id of the team that will be granted access to this repository. This is only valid when creating a - * repo in an organization. - * @param boolean $autoInit true to create an initial commit with empty README. - * @param string $gitignoreTemplate Desired language or platform .gitignore template to apply. Use the name of the template without the - * extension. For example, “Haskell” Ignored if auto_init parameter is not provided. - * - * @return object - * - * @since 1.0 - */ - public function create($name, $org = '', $description = '', $homepage = '', $private = false, $hasIssues = false, $hasWiki = false, - $hasDownloads = false, $teamId = 0, $autoInit = false, $gitignoreTemplate = '' - ) - { - $path = ($org) - // Create a repository for an organization - ? '/orgs/' . $org . '/repos' - // Create a repository for a user - : '/user/repos'; - - $data = [ - 'name' => $name, - 'description' => $description, - 'homepage' => $homepage, - 'private' => $private, - 'has_issues' => $hasIssues, - 'has_wiki' => $hasWiki, - 'has_downloads' => $hasDownloads, - 'team_id' => $teamId, - 'auto_init' => $autoInit, - 'gitignore_template' => $gitignoreTemplate, - ]; - - // Send the request. - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($data)), - 201 - ); - } - - /** - * Get. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function get($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Edit. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param string $name The repository name. - * @param string $description The repository description. - * @param string $homepage The repository homepage. - * @param boolean $private Set true to create a private repository, false to create a public one. Creating private repositories - * requires a paid GitHub account. - * @param boolean $hasIssues Set true to enable issues for this repository, false to disable them. - * @param boolean $hasWiki Set true to enable the wiki for this repository, false to disable it. - * @param boolean $hasDownloads Set true to enable downloads for this repository, false to disable them. - * @param string $defaultBranch Update the default branch for this repository - * - * @return object - * - * @since 1.0 - */ - public function edit($owner, $repo, $name, $description = '', $homepage = '', $private = false, $hasIssues = false, $hasWiki = false, - $hasDownloads = false, $defaultBranch = '' - ) - { - $path = '/repos/' . $owner . '/' . $repo; - - $data = [ - 'name' => $name, - 'description' => $description, - 'homepage' => $homepage, - 'private' => $private, - 'has_issues' => $hasIssues, - 'has_wiki' => $hasWiki, - 'has_downloads' => $hasDownloads, - 'default_branch' => $defaultBranch, - ]; - - // Send the request. - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), json_encode($data)) - ); - } - - /** - * List contributors. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param boolean $anon Set to 1 or true to include anonymous contributors in results. - * - * @return object - * - * @since 1.0 - */ - public function getListContributors($owner, $repo, $anon = false) - { - // Build the request path. - $uri = $this->fetchUrl('/repos/' . $owner . '/' . $repo . '/contributors'); - - if ($anon) - { - $uri->setVar('anon', 'true'); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * List languages. - * - * List languages for the specified repository. The value on the right of a language is the number of bytes of code - * written in that language. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function getListLanguages($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/languages'; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List Teams - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function getListTeams($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/teams'; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List Tags. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function getListTags($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/tags'; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Delete a Repository. - * - * Deleting a repository requires admin access. If OAuth is used, the delete_repo scope is required. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.0 - */ - public function delete($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo; - - // Send the request. - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)) - ); - } + /** + * List your repositories. + * + * List repositories for the authenticated user. + * + * @param string $type Sort type. all, owner, public, private, member. Default: all. + * @param string $sort Sort field. created, updated, pushed, full_name, default: full_name. + * @param string $direction Sort direction. asc or desc, default: when using full_name: asc, otherwise desc. + * + * @return object + * + * @since 1.0 + * @throws \RuntimeException + */ + public function getListOwn($type = 'all', $sort = 'full_name', $direction = '') + { + if (\in_array($type, ['all', 'owner', 'public', 'private', 'member']) == false) { + throw new \RuntimeException('Invalid type'); + } + + if (\in_array($sort, ['created', 'updated', 'pushed', 'full_name']) == false) { + throw new \RuntimeException('Invalid sort field'); + } + + // Sort direction default: when using full_name: asc, otherwise desc. + $direction = ($direction) ?: (($sort == 'full_name') ? 'asc' : 'desc'); + + if (\in_array($direction, ['asc', 'desc']) == false) { + throw new \RuntimeException('Invalid sort order'); + } + + // Build the request path. + $uri = $this->fetchUrl('/user/repos'); + $uri->setVar('type', $type); + $uri->setVar('sort', $sort); + $uri->setVar('direction', $direction); + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * List user repositories. + * + * List public repositories for the specified user. + * + * @param string $user The user name. + * @param string $type Sort type. all, owner, member. Default: all. + * @param string $sort Sort field. created, updated, pushed, full_name, default: full_name. + * @param string $direction Sort direction. asc or desc, default: when using full_name: asc, otherwise desc. + * + * @return object + * + * @since 1.0 + * @throws \RuntimeException + */ + public function getListUser($user, $type = 'all', $sort = 'full_name', $direction = '') + { + if (\in_array($type, ['all', 'owner', 'member']) == false) { + throw new \RuntimeException('Invalid type'); + } + + if (\in_array($sort, ['created', 'updated', 'pushed', 'full_name']) == false) { + throw new \RuntimeException('Invalid sort field'); + } + + // Sort direction default: when using full_name: asc, otherwise desc. + $direction = $direction ?: ($sort == 'full_name' ? 'asc' : 'desc'); + + if (\in_array($direction, ['asc', 'desc']) == false) { + throw new \RuntimeException('Invalid sort order'); + } + + // Build the request path. + $uri = $this->fetchUrl('/users/' . $user . '/repos'); + $uri->setVar('type', $type); + $uri->setVar('sort', $sort); + $uri->setVar('direction', $direction); + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * List organization repositories. + * + * List repositories for the specified org. + * + * @param string $org The name of the organization. + * @param string $type Sort type. all, public, private, forks, sources, member. Default: all. + * + * @return object + * + * @since 1.0 + * @throws \RuntimeException + */ + public function getListOrg($org, $type = 'all') + { + if (\in_array($type, ['all', 'public', 'private', 'forks', 'sources', 'member']) == false) { + throw new \RuntimeException('Invalid type'); + } + + // Build the request path. + $uri = $this->fetchUrl('/orgs/' . $org . '/repos'); + $uri->setVar('type', $type); + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * List all public repositories. + * + * This provides a dump of every repository, in the order that they were created. + * + * @param integer $id The integer ID of the last Repository that you’ve seen. + * + * @return object + * + * @since 1.0 + * @throws \RuntimeException + */ + public function getList($id = 0) + { + // Build the request path. + $uri = $this->fetchUrl('/repositories'); + + if ($id) { + $uri->setVar('since', (int) $id); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * Create. + * + * Create a new repository for the authenticated user or an organization. OAuth users must supply repo scope. + * + * @param string $name The repository name. + * @param string $org The organization name (if needed). + * @param string $description The repository description. + * @param string $homepage The repository homepage. + * @param boolean $private Set true to create a private repository, false to create a public one. Creating private repositories + * requires a paid GitHub account. + * @param boolean $hasIssues Set true to enable issues for this repository, false to disable them. + * @param boolean $hasWiki Set true to enable the wiki for this repository, false to disable it. + * @param boolean $hasDownloads Set true to enable downloads for this repository, false to disable them. + * @param integer $teamId The id of the team that will be granted access to this repository. This is only valid when creating a + * repo in an organization. + * @param boolean $autoInit true to create an initial commit with empty README. + * @param string $gitignoreTemplate Desired language or platform .gitignore template to apply. Use the name of the template without the + * extension. For example, “Haskell” Ignored if auto_init parameter is not provided. + * + * @return object + * + * @since 1.0 + */ + public function create( + $name, + $org = '', + $description = '', + $homepage = '', + $private = false, + $hasIssues = false, + $hasWiki = false, + $hasDownloads = false, + $teamId = 0, + $autoInit = false, + $gitignoreTemplate = '' + ) { + $path = ($org) + // Create a repository for an organization + ? '/orgs/' . $org . '/repos' + // Create a repository for a user + : '/user/repos'; + + $data = [ + 'name' => $name, + 'description' => $description, + 'homepage' => $homepage, + 'private' => $private, + 'has_issues' => $hasIssues, + 'has_wiki' => $hasWiki, + 'has_downloads' => $hasDownloads, + 'team_id' => $teamId, + 'auto_init' => $autoInit, + 'gitignore_template' => $gitignoreTemplate, + ]; + + // Send the request. + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($data)), + 201 + ); + } + + /** + * Get. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function get($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Edit. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param string $name The repository name. + * @param string $description The repository description. + * @param string $homepage The repository homepage. + * @param boolean $private Set true to create a private repository, false to create a public one. Creating private repositories + * requires a paid GitHub account. + * @param boolean $hasIssues Set true to enable issues for this repository, false to disable them. + * @param boolean $hasWiki Set true to enable the wiki for this repository, false to disable it. + * @param boolean $hasDownloads Set true to enable downloads for this repository, false to disable them. + * @param string $defaultBranch Update the default branch for this repository + * + * @return object + * + * @since 1.0 + */ + public function edit( + $owner, + $repo, + $name, + $description = '', + $homepage = '', + $private = false, + $hasIssues = false, + $hasWiki = false, + $hasDownloads = false, + $defaultBranch = '' + ) { + $path = '/repos/' . $owner . '/' . $repo; + + $data = [ + 'name' => $name, + 'description' => $description, + 'homepage' => $homepage, + 'private' => $private, + 'has_issues' => $hasIssues, + 'has_wiki' => $hasWiki, + 'has_downloads' => $hasDownloads, + 'default_branch' => $defaultBranch, + ]; + + // Send the request. + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), json_encode($data)) + ); + } + + /** + * List contributors. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param boolean $anon Set to 1 or true to include anonymous contributors in results. + * + * @return object + * + * @since 1.0 + */ + public function getListContributors($owner, $repo, $anon = false) + { + // Build the request path. + $uri = $this->fetchUrl('/repos/' . $owner . '/' . $repo . '/contributors'); + + if ($anon) { + $uri->setVar('anon', 'true'); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * List languages. + * + * List languages for the specified repository. The value on the right of a language is the number of bytes of code + * written in that language. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function getListLanguages($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/languages'; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List Teams + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function getListTeams($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/teams'; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List Tags. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function getListTags($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/tags'; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Delete a Repository. + * + * Deleting a repository requires admin access. If OAuth is used, the delete_repo scope is required. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.0 + */ + public function delete($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo; + + // Send the request. + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)) + ); + } } diff --git a/src/Package/Repositories/Branches.php b/src/Package/Repositories/Branches.php index 1a5c485c..04230132 100644 --- a/src/Package/Repositories/Branches.php +++ b/src/Package/Repositories/Branches.php @@ -19,46 +19,46 @@ */ class Branches extends AbstractPackage { - /** - * List Branches. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * - * @return object - * - * @since 1.4.0 - */ - public function getList($owner, $repo) - { - // Build the request path. - $path = "/repos/$owner/$repo/branches"; + /** + * List Branches. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * + * @return object + * + * @since 1.4.0 + */ + public function getList($owner, $repo) + { + // Build the request path. + $path = "/repos/$owner/$repo/branches"; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Get Branch. - * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param string $branch Branch name. - * - * @return object - * - * @since 1.4.0 - */ - public function get($owner, $repo, $branch) - { - // Build the request path. - $path = "/repos/$owner/$repo/branches/$branch"; + /** + * Get Branch. + * + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param string $branch Branch name. + * + * @return object + * + * @since 1.4.0 + */ + public function get($owner, $repo, $branch) + { + // Build the request path. + $path = "/repos/$owner/$repo/branches/$branch"; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } } diff --git a/src/Package/Repositories/Collaborators.php b/src/Package/Repositories/Collaborators.php index e3cd324e..7dfe05c0 100644 --- a/src/Package/Repositories/Collaborators.php +++ b/src/Package/Repositories/Collaborators.php @@ -19,103 +19,102 @@ */ class Collaborators extends AbstractPackage { - /** - * List collaborators. - * - * When authenticating as an organization owner of an organization-owned repository, all organization - * owners are included in the list of collaborators. Otherwise, only users with access to the repository - * are returned in the collaborators list. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @since 1.0 - * - * @return object - */ - public function getList($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/collaborators'; + /** + * List collaborators. + * + * When authenticating as an organization owner of an organization-owned repository, all organization + * owners are included in the list of collaborators. Otherwise, only users with access to the repository + * are returned in the collaborators list. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @since 1.0 + * + * @return object + */ + public function getList($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/collaborators'; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Check if a user is a collaborator. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $user The name of the GitHub user. - * - * @throws \UnexpectedValueException - * @since 1.0 - * - * @return boolean - */ - public function get($owner, $repo, $user) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user; + /** + * Check if a user is a collaborator. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $user The name of the GitHub user. + * + * @throws \UnexpectedValueException + * @since 1.0 + * + * @return boolean + */ + public function get($owner, $repo, $user) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user; - $response = $this->client->get($this->fetchUrl($path)); + $response = $this->client->get($this->fetchUrl($path)); - switch ($response->code) - { - case '204' : - return true; + switch ($response->code) { + case '204': + return true; - case '404' : - return false; + case '404': + return false; - default : - throw new \UnexpectedValueException('Unexpected code: ' . $response->code); - } - } + default: + throw new \UnexpectedValueException('Unexpected code: ' . $response->code); + } + } - /** - * Add user as a collaborator. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $user The name of the GitHub user. - * - * @since 1.0 - * - * @return object - */ - public function add($owner, $repo, $user) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user; + /** + * Add user as a collaborator. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $user The name of the GitHub user. + * + * @since 1.0 + * + * @return object + */ + public function add($owner, $repo, $user) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user; - return $this->processResponse( - $this->client->put($this->fetchUrl($path), ''), - 204 - ); - } + return $this->processResponse( + $this->client->put($this->fetchUrl($path), ''), + 204 + ); + } - /** - * Remove user as a collaborator. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $user The name of the GitHub user. - * - * @since 1.0 - * - * @return object - */ - public function remove($owner, $repo, $user) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user; + /** + * Remove user as a collaborator. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $user The name of the GitHub user. + * + * @since 1.0 + * + * @return object + */ + public function remove($owner, $repo, $user) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/collaborators/' . $user; - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } } diff --git a/src/Package/Repositories/Comments.php b/src/Package/Repositories/Comments.php index 986c0672..ae22eb94 100644 --- a/src/Package/Repositories/Comments.php +++ b/src/Package/Repositories/Comments.php @@ -19,160 +19,160 @@ */ class Comments extends AbstractPackage { - /** - * List commit comments for a repository. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $page Page to request - * @param integer $limit Number of results to return per page - * - * @return array - * - * @since 1.0 - */ - public function getListRepository($user, $repo, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/comments'; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path, $page, $limit)) - ); - } - - /** - * List comments for a single commit. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha The SHA of the commit to retrieve. - * @param integer $page Page to request - * @param integer $limit Number of results to return per page - * - * @return array - * - * @since 1.0 - */ - public function getList($user, $repo, $sha, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/comments'; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path, $page, $limit)) - ); - } - - /** - * Get a single commit comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id ID of the comment to retrieve - * - * @return array - * - * @since 1.0 - */ - public function get($user, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/comments/' . (int) $id; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Update a commit comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $id The ID of the comment to edit. - * @param string $comment The text of the comment. - * - * @return object - * - * @since 1.0 - */ - public function edit($user, $repo, $id, $comment) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/comments/' . $id; - - $data = json_encode( - [ - 'body' => $comment, - ] - ); - - // Send the request. - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), $data) - ); - } - - /** - * Delete a commit comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $id The ID of the comment to edit. - * - * @return object - * - * @since 1.0 - */ - public function delete($user, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/comments/' . $id; - - // Send the request. - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * Create a commit comment. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha The SHA of the commit to comment on. - * @param string $comment The text of the comment. - * @param integer $line The line number of the commit to comment on. - * @param string $filepath A relative path to the file to comment on within the commit. - * @param integer $position Line index in the diff to comment on. - * - * @return object - * - * @since 1.0 - */ - public function create($user, $repo, $sha, $comment, $line, $filepath, $position) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/comments'; - - $data = json_encode( - [ - 'body' => $comment, - 'path' => $filepath, - 'position' => (int) $position, - 'line' => (int) $line, - ] - ); - - // Send the request. - return $this->processResponse( - $this->client->post($this->fetchUrl($path), $data), - 201 - ); - } + /** + * List commit comments for a repository. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $page Page to request + * @param integer $limit Number of results to return per page + * + * @return array + * + * @since 1.0 + */ + public function getListRepository($user, $repo, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/comments'; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path, $page, $limit)) + ); + } + + /** + * List comments for a single commit. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha The SHA of the commit to retrieve. + * @param integer $page Page to request + * @param integer $limit Number of results to return per page + * + * @return array + * + * @since 1.0 + */ + public function getList($user, $repo, $sha, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/comments'; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path, $page, $limit)) + ); + } + + /** + * Get a single commit comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id ID of the comment to retrieve + * + * @return array + * + * @since 1.0 + */ + public function get($user, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/comments/' . (int) $id; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Update a commit comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $id The ID of the comment to edit. + * @param string $comment The text of the comment. + * + * @return object + * + * @since 1.0 + */ + public function edit($user, $repo, $id, $comment) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/comments/' . $id; + + $data = json_encode( + [ + 'body' => $comment, + ] + ); + + // Send the request. + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), $data) + ); + } + + /** + * Delete a commit comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $id The ID of the comment to edit. + * + * @return object + * + * @since 1.0 + */ + public function delete($user, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/comments/' . $id; + + // Send the request. + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * Create a commit comment. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha The SHA of the commit to comment on. + * @param string $comment The text of the comment. + * @param integer $line The line number of the commit to comment on. + * @param string $filepath A relative path to the file to comment on within the commit. + * @param integer $position Line index in the diff to comment on. + * + * @return object + * + * @since 1.0 + */ + public function create($user, $repo, $sha, $comment, $line, $filepath, $position) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha . '/comments'; + + $data = json_encode( + [ + 'body' => $comment, + 'path' => $filepath, + 'position' => (int) $position, + 'line' => (int) $line, + ] + ); + + // Send the request. + return $this->processResponse( + $this->client->post($this->fetchUrl($path), $data), + 201 + ); + } } diff --git a/src/Package/Repositories/Commits.php b/src/Package/Repositories/Commits.php index e4ac6289..c0a03029 100644 --- a/src/Package/Repositories/Commits.php +++ b/src/Package/Repositories/Commits.php @@ -20,137 +20,131 @@ */ class Commits extends AbstractPackage { - /** - * List commits on a repository. - * - * A special note on pagination: Due to the way Git works, commits are paginated based on SHA - * instead of page number. - * Please follow the link headers as outlined in the pagination overview instead of constructing - * page links yourself. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha Sha or branch to start listing commits from. - * @param string $path Only commits containing this file path will be returned. - * @param string $author GitHub login, name, or email by which to filter by commit author. - * @param \DateTimeInterface $since ISO 8601 Date - Only commits after this date will be returned. - * @param \DateTimeInterface $until ISO 8601 Date - Only commits before this date will be returned. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getList($user, $repo, $sha = '', $path = '', $author = '', \DateTimeInterface $since = null, \DateTimeInterface $until = null) - { - // Build the request path. - $rPath = '/repos/' . $user . '/' . $repo . '/commits'; - - $uri = $this->fetchUrl($rPath); - - if ($sha) - { - $uri->setVar('sha', $sha); - } - - if ($path) - { - $uri->setVar('path', $path); - } - - if ($author) - { - $uri->setVar('author', $author); - } - - if ($since) - { - $uri->setVar('since', $since->format(\DateTime::RFC3339)); - } - - if ($until) - { - $uri->setVar('until', $until->format(\DateTime::RFC3339)); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Get a single commit. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha The SHA of the commit to retrieve. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($user, $repo, $sha) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Get the SHA-1 of a commit reference. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $ref The commit reference - * - * @return string - * - * @since 1.4.0 - * @throws UnexpectedResponseException - */ - public function getSha($user, $repo, $ref) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/commits/' . $ref; - - // Send the request. - $response = $this->client->get($this->fetchUrl($path)); - - // Validate the response code. - if ($response->code != 200) - { - // Decode the error response and throw an exception. - $error = json_decode($response->body); - $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; - - throw new UnexpectedResponseException($response, $message, $response->code); - } - - return $response->body; - } - - /** - * Compare two commits. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $base The base of the diff, either a commit SHA or branch. - * @param string $head The head of the diff, either a commit SHA or branch. - * - * @return object - * - * @since 1.0 - */ - public function compare($user, $repo, $base, $head) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/compare/' . $base . '...' . $head; - - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + /** + * List commits on a repository. + * + * A special note on pagination: Due to the way Git works, commits are paginated based on SHA + * instead of page number. + * Please follow the link headers as outlined in the pagination overview instead of constructing + * page links yourself. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha Sha or branch to start listing commits from. + * @param string $path Only commits containing this file path will be returned. + * @param string $author GitHub login, name, or email by which to filter by commit author. + * @param \DateTimeInterface $since ISO 8601 Date - Only commits after this date will be returned. + * @param \DateTimeInterface $until ISO 8601 Date - Only commits before this date will be returned. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getList($user, $repo, $sha = '', $path = '', $author = '', \DateTimeInterface $since = null, \DateTimeInterface $until = null) + { + // Build the request path. + $rPath = '/repos/' . $user . '/' . $repo . '/commits'; + + $uri = $this->fetchUrl($rPath); + + if ($sha) { + $uri->setVar('sha', $sha); + } + + if ($path) { + $uri->setVar('path', $path); + } + + if ($author) { + $uri->setVar('author', $author); + } + + if ($since) { + $uri->setVar('since', $since->format(\DateTime::RFC3339)); + } + + if ($until) { + $uri->setVar('until', $until->format(\DateTime::RFC3339)); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get a single commit. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha The SHA of the commit to retrieve. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($user, $repo, $sha) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/commits/' . $sha; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Get the SHA-1 of a commit reference. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $ref The commit reference + * + * @return string + * + * @since 1.4.0 + * @throws UnexpectedResponseException + */ + public function getSha($user, $repo, $ref) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/commits/' . $ref; + + // Send the request. + $response = $this->client->get($this->fetchUrl($path)); + + // Validate the response code. + if ($response->code != 200) { + // Decode the error response and throw an exception. + $error = json_decode($response->body); + $message = isset($error->message) ? $error->message : 'Invalid response received from GitHub.'; + + throw new UnexpectedResponseException($response, $message, $response->code); + } + + return $response->body; + } + + /** + * Compare two commits. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $base The base of the diff, either a commit SHA or branch. + * @param string $head The head of the diff, either a commit SHA or branch. + * + * @return object + * + * @since 1.0 + */ + public function compare($user, $repo, $base, $head) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/compare/' . $base . '...' . $head; + + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } } diff --git a/src/Package/Repositories/Contents.php b/src/Package/Repositories/Contents.php index 64cfe1ed..4505c47f 100644 --- a/src/Package/Repositories/Contents.php +++ b/src/Package/Repositories/Contents.php @@ -22,317 +22,326 @@ */ class Contents extends AbstractPackage { - /** - * Get the README. - * - * This method returns the preferred README for a repository. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $ref The String name of the Commit/Branch/Tag. Defaults to master. - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function getReadme($owner, $repo, $ref = '') - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/readme'; - - $uri = $this->fetchUrl($path); - - if ($ref) - { - $uri->setVar('ref', $ref); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Get contents. - * - * This method returns the contents of any file or directory in a repository. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $path The content path. - * @param string $ref The String name of the Commit/Branch/Tag. Defaults to master. - * - * @return object - * - * @since 1.0 - */ - public function get($owner, $repo, $path, $ref = '') - { - // Build the request path. - $rPath = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; - - $uri = $this->fetchUrl($rPath); - - if ($ref) - { - $uri->setVar('ref', $ref); - } - - // Send the request. - return $this->processResponse($this->client->get($uri)); - } - - /** - * Get archive link. - * - * This method will return a 302 to a URL to download a tarball or zipball archive for a repository. - * Please make sure your HTTP framework is configured to follow redirects or you will need to use the - * Location header to make a second GET request. - * - * Note: For private repositories, these links are temporary and expire quickly. - * - * To follow redirects with curl, use the -L switch: - * curl -L https://api.github.com/repos/pengwynn/octokit/tarball > octokit.tar.gz - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $archiveFormat Either tarball or zipball. - * @param string $ref The String name of the Commit/Branch/Tag. Defaults to master. - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function getArchiveLink($owner, $repo, $archiveFormat = 'zipball', $ref = '') - { - if (\in_array($archiveFormat, ['tarball', 'zipball']) == false) - { - throw new \UnexpectedValueException('Archive format must be either "tarball" or "zipball".'); - } - - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/' . $archiveFormat; - $uri = $this->fetchUrl($path); - - if ($ref) - { - $uri->setVar('ref', $ref); - } - - // Send the request. - return $this->processResponse($this->client->get($uri), 302); - } - - /** - * Create a file. - * - * This method creates a new file in a repository. - * - * Optional Parameters - * The author section is optional and is filled in with the committer information if omitted. - * If the committer information is omitted, the authenticated user’s information is used. - * - * You must provide values for both name and email, whether you choose to use author or committer. - * Otherwise, you’ll receive a 500 status code. - * - * @param string $owner The owner of the repository. - * @param string $repo The repository name. - * @param string $path The content path. - * @param string $message The commit message. - * @param string $content The new file content, Base64 encoded. - * @param string $branch The branch name. If not provided, uses the repository’s default branch (usually master). - * @param string $authorName The name of the author of the commit - * @param string $authorEmail The email of the author of the commit - * @param string $committerName The name of the committer of the commit - * @param string $committerEmail The email of the committer of the commit - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function create($owner, $repo, $path, $message, $content, $branch = 'master', $authorName = '', $authorEmail = '', $committerName = '', - $committerEmail = '' - ) - { - // Build the request path. - $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; - - $data = [ - 'message' => $message, - 'content' => $content, - 'branch' => $branch, - ]; - - if ($authorName) - { - if (!$authorEmail) - { - throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); - } - - $data['author'] = [ - 'name' => $authorName, - 'email' => $authorEmail, - ]; - } - - if ($committerName) - { - if (!$committerEmail) - { - throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); - } - - $data['committer'] = [ - 'name' => $committerName, - 'email' => $committerEmail, - ]; - } - - return $this->processResponse($this->client->put($this->fetchUrl($route), json_encode($data)), 201); - } - - /** - * Update a file. - * - * This method updates a file in a repository. - * - * Optional Parameters - * The author section is optional and is filled in with the committer information if omitted. - * If the committer information is omitted, the authenticated user’s information is used. - * - * You must provide values for both name and email, whether you choose to use author or committer. - * Otherwise, you’ll receive a 500 status code. - * - * @param string $owner The owner of the repository. - * @param string $repo The repository name. - * @param string $path The content path. - * @param string $message The commit message. - * @param string $content The new file content, Base64 encoded. - * @param string $sha The blob SHA of the file being replaced. - * @param string $branch The branch name. If not provided, uses the repository’s default branch (usually master). - * @param string $authorName The name of the author of the commit - * @param string $authorEmail The email of the author of the commit - * @param string $committerName The name of the committer of the commit - * @param string $committerEmail The email of the committer of the commit - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function update($owner, $repo, $path, $message, $content, $sha, $branch = 'master', $authorName = '', $authorEmail = '', - $committerName = '', $committerEmail = '' - ) - { - // Build the request path. - $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; - - $data = [ - 'message' => $message, - 'content' => $content, - 'sha' => $sha, - 'branch' => $branch, - ]; - - if ($authorName) - { - if (!$authorEmail) - { - throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); - } - - $data['author'] = [ - 'name' => $authorName, - 'email' => $authorEmail, - ]; - } - - if ($committerName) - { - if (!$committerEmail) - { - throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); - } - - $data['committer'] = [ - 'name' => $committerName, - 'email' => $committerEmail, - ]; - } - - return $this->processResponse($this->client->put($this->fetchUrl($route), json_encode($data))); - } - - /** - * Delete a file. - * - * This method deletes a file in a repository. - * - * @param string $owner The owner of the repository. - * @param string $repo The repository name. - * @param string $path The content path. - * @param string $message The commit message. - * @param string $sha The blob SHA of the file being replaced. - * @param string $branch The branch name. If not provided, uses the repository’s default branch (usually master). - * @param string $authorName The name of the author of the commit - * @param string $authorEmail The email of the author of the commit - * @param string $committerName The name of the committer of the commit - * @param string $committerEmail The email of the committer of the commit - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function delete($owner, $repo, $path, $message, $sha, $branch = 'master', $authorName = '', $authorEmail = '', $committerName = '', - $committerEmail = '' - ) - { - // Build the request path. - $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; - - $data = [ - 'message' => $message, - 'sha' => $sha, - 'branch' => $branch, - ]; - - if ($authorName) - { - if (!$authorEmail) - { - throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); - } - - $data['author'] = [ - 'name' => $authorName, - 'email' => $authorEmail, - ]; - } - - if ($committerName) - { - if (!$committerEmail) - { - throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); - } - - $data['committer'] = [ - 'name' => $committerName, - 'email' => $committerEmail, - ]; - } - - return $this->processResponse( - $this->client->delete( - $this->fetchUrl($route), - [], - null, - json_encode($data) - ) - ); - } + /** + * Get the README. + * + * This method returns the preferred README for a repository. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $ref The String name of the Commit/Branch/Tag. Defaults to master. + * + * @return object + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function getReadme($owner, $repo, $ref = '') + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/readme'; + + $uri = $this->fetchUrl($path); + + if ($ref) { + $uri->setVar('ref', $ref); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get contents. + * + * This method returns the contents of any file or directory in a repository. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $path The content path. + * @param string $ref The String name of the Commit/Branch/Tag. Defaults to master. + * + * @return object + * + * @since 1.0 + */ + public function get($owner, $repo, $path, $ref = '') + { + // Build the request path. + $rPath = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; + + $uri = $this->fetchUrl($rPath); + + if ($ref) { + $uri->setVar('ref', $ref); + } + + // Send the request. + return $this->processResponse($this->client->get($uri)); + } + + /** + * Get archive link. + * + * This method will return a 302 to a URL to download a tarball or zipball archive for a repository. + * Please make sure your HTTP framework is configured to follow redirects or you will need to use the + * Location header to make a second GET request. + * + * Note: For private repositories, these links are temporary and expire quickly. + * + * To follow redirects with curl, use the -L switch: + * curl -L https://api.github.com/repos/pengwynn/octokit/tarball > octokit.tar.gz + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $archiveFormat Either tarball or zipball. + * @param string $ref The String name of the Commit/Branch/Tag. Defaults to master. + * + * @return object + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function getArchiveLink($owner, $repo, $archiveFormat = 'zipball', $ref = '') + { + if (\in_array($archiveFormat, ['tarball', 'zipball']) == false) { + throw new \UnexpectedValueException('Archive format must be either "tarball" or "zipball".'); + } + + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/' . $archiveFormat; + $uri = $this->fetchUrl($path); + + if ($ref) { + $uri->setVar('ref', $ref); + } + + // Send the request. + return $this->processResponse($this->client->get($uri), 302); + } + + /** + * Create a file. + * + * This method creates a new file in a repository. + * + * Optional Parameters + * The author section is optional and is filled in with the committer information if omitted. + * If the committer information is omitted, the authenticated user’s information is used. + * + * You must provide values for both name and email, whether you choose to use author or committer. + * Otherwise, you’ll receive a 500 status code. + * + * @param string $owner The owner of the repository. + * @param string $repo The repository name. + * @param string $path The content path. + * @param string $message The commit message. + * @param string $content The new file content, Base64 encoded. + * @param string $branch The branch name. If not provided, uses the repository’s default branch (usually master). + * @param string $authorName The name of the author of the commit + * @param string $authorEmail The email of the author of the commit + * @param string $committerName The name of the committer of the commit + * @param string $committerEmail The email of the committer of the commit + * + * @return object + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function create( + $owner, + $repo, + $path, + $message, + $content, + $branch = 'master', + $authorName = '', + $authorEmail = '', + $committerName = '', + $committerEmail = '' + ) { + // Build the request path. + $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; + + $data = [ + 'message' => $message, + 'content' => $content, + 'branch' => $branch, + ]; + + if ($authorName) { + if (!$authorEmail) { + throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); + } + + $data['author'] = [ + 'name' => $authorName, + 'email' => $authorEmail, + ]; + } + + if ($committerName) { + if (!$committerEmail) { + throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); + } + + $data['committer'] = [ + 'name' => $committerName, + 'email' => $committerEmail, + ]; + } + + return $this->processResponse($this->client->put($this->fetchUrl($route), json_encode($data)), 201); + } + + /** + * Update a file. + * + * This method updates a file in a repository. + * + * Optional Parameters + * The author section is optional and is filled in with the committer information if omitted. + * If the committer information is omitted, the authenticated user’s information is used. + * + * You must provide values for both name and email, whether you choose to use author or committer. + * Otherwise, you’ll receive a 500 status code. + * + * @param string $owner The owner of the repository. + * @param string $repo The repository name. + * @param string $path The content path. + * @param string $message The commit message. + * @param string $content The new file content, Base64 encoded. + * @param string $sha The blob SHA of the file being replaced. + * @param string $branch The branch name. If not provided, uses the repository’s default branch (usually master). + * @param string $authorName The name of the author of the commit + * @param string $authorEmail The email of the author of the commit + * @param string $committerName The name of the committer of the commit + * @param string $committerEmail The email of the committer of the commit + * + * @return object + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function update( + $owner, + $repo, + $path, + $message, + $content, + $sha, + $branch = 'master', + $authorName = '', + $authorEmail = '', + $committerName = '', + $committerEmail = '' + ) { + // Build the request path. + $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; + + $data = [ + 'message' => $message, + 'content' => $content, + 'sha' => $sha, + 'branch' => $branch, + ]; + + if ($authorName) { + if (!$authorEmail) { + throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); + } + + $data['author'] = [ + 'name' => $authorName, + 'email' => $authorEmail, + ]; + } + + if ($committerName) { + if (!$committerEmail) { + throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); + } + + $data['committer'] = [ + 'name' => $committerName, + 'email' => $committerEmail, + ]; + } + + return $this->processResponse($this->client->put($this->fetchUrl($route), json_encode($data))); + } + + /** + * Delete a file. + * + * This method deletes a file in a repository. + * + * @param string $owner The owner of the repository. + * @param string $repo The repository name. + * @param string $path The content path. + * @param string $message The commit message. + * @param string $sha The blob SHA of the file being replaced. + * @param string $branch The branch name. If not provided, uses the repository’s default branch (usually master). + * @param string $authorName The name of the author of the commit + * @param string $authorEmail The email of the author of the commit + * @param string $committerName The name of the committer of the commit + * @param string $committerEmail The email of the committer of the commit + * + * @return object + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function delete( + $owner, + $repo, + $path, + $message, + $sha, + $branch = 'master', + $authorName = '', + $authorEmail = '', + $committerName = '', + $committerEmail = '' + ) { + // Build the request path. + $route = '/repos/' . $owner . '/' . $repo . '/contents/' . $path; + + $data = [ + 'message' => $message, + 'sha' => $sha, + 'branch' => $branch, + ]; + + if ($authorName) { + if (!$authorEmail) { + throw new \UnexpectedValueException('You must provide an author e-mail if you supply an author name'); + } + + $data['author'] = [ + 'name' => $authorName, + 'email' => $authorEmail, + ]; + } + + if ($committerName) { + if (!$committerEmail) { + throw new \UnexpectedValueException('You must provide a committer e-mail if you supply a committer name'); + } + + $data['committer'] = [ + 'name' => $committerName, + 'email' => $committerEmail, + ]; + } + + return $this->processResponse( + $this->client->delete( + $this->fetchUrl($route), + [], + null, + json_encode($data) + ) + ); + } } diff --git a/src/Package/Repositories/Deployments.php b/src/Package/Repositories/Deployments.php index c235677e..ca2c9002 100644 --- a/src/Package/Repositories/Deployments.php +++ b/src/Package/Repositories/Deployments.php @@ -19,200 +19,194 @@ */ class Deployments extends AbstractPackage { - /** - * List Deployments. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha The SHA that was recorded at creation time. - * @param string $ref The name of the ref. This can be a branch, tag, or SHA. - * @param string $task The name of the task for the deployment. - * @param string $environment The name of the environment that was deployed to. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.4.0 - */ - public function getList($owner, $repo, $sha = '', $ref = '', $task = '', $environment = '', $page = 0, $limit = 0) - { - // Build the request path. - $path = "/repos/$owner/$repo/deployments"; - - $uri = $this->fetchUrl($path, $page, $limit); - - if ($sha) - { - $uri->setVar('sha', $sha); - } - - if ($ref) - { - $uri->setVar('ref', $ref); - } - - if ($task) - { - $uri->setVar('task', $task); - } - - if ($environment) - { - $uri->setVar('environment', $environment); - } - - return $this->processResponse($this->client->get($uri)); - } - - /** - * Create a Deployment. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $ref The ref to deploy. This can be a branch, tag, or SHA. - * @param string $task Optional parameter to specify a task to execute. - * @param boolean $autoMerge Optional parameter to merge the default branch into the requested ref if - * it is behind the default branch. - * @param array|null $requiredContexts Optional array of status contexts verified against commit status checks. - * If this parameter is omitted - * from the parameters then all unique contexts will be verified before a - * deployment is created. To bypass checking entirely pass an empty array. - * Defaults to all unique contexts. - * @param string $payload Optional JSON payload with extra information about the deployment. - * @param string $environment Optional name for the target deployment environment. - * @param string $description Optional short description. - * - * @return object - * - * @since 1.4.0 - * @throws \RuntimeException - */ - public function create($owner, $repo, $ref, $task = '', $autoMerge = true, $requiredContexts = null, $payload = '', $environment = '', - $description = '' - ) - { - // Build the request path. - $path = "/repos/$owner/$repo/deployments"; - - $data = [ - 'ref' => $ref, - 'auto_merge' => $autoMerge, - ]; - - if ($task) - { - $data['task'] = $task; - } - - if (\is_array($requiredContexts)) - { - $data['required_contexts'] = $requiredContexts; - } - - if ($payload) - { - $data['payload'] = $payload; - } - - if ($environment) - { - $data['environment'] = $environment; - } - - if ($description) - { - $data['description'] = $description; - } - - $response = $this->client->post($this->fetchUrl($path), json_encode($data)); - - switch ($response->code) - { - case 201 : - // The deployment was successful - return json_decode($response->body); - - case 409 : - // There was a merge conflict or a status check failed. - $body = json_decode($response->body); - $message = isset($body->message) ? $body->message : 'Invalid response received from GitHub.'; - - throw new \RuntimeException($message, $response->code); - - default : - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - } - - /** - * List Deployment Statuses. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The Deployment ID to list the statuses from. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.4.0 - */ - public function getDeploymentStatuses($owner, $repo, $id, $page = 0, $limit = 0) - { - // Build the request path. - $path = "/repos/$owner/$repo/deployments/" . (int) $id . '/statuses'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path, $page, $limit)) - ); - } - - /** - * Create a Deployment Status. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The Deployment ID to list the statuses from. - * @param string $state The state of the status. - * @param string $targetUrl The target URL to associate with this status. This URL should contain output to keep the user updated while - * the task is running or serve as historical information for what happened in the deployment. - * @param string $description A short description of the status. Maximum length of 140 characters. - * - * @return object - * - * @since 1.4.0 - * @throws \InvalidArgumentException - */ - public function createStatus($owner, $repo, $id, $state, $targetUrl = '', $description = '') - { - $allowedStates = ['pending', 'success', 'error', 'failure']; - - // Build the request path. - $path = "/repos/$owner/$repo/deployments/" . (int) $id . '/statuses'; - - if (!\in_array($state, $allowedStates)) - { - throw new \InvalidArgumentException(sprintf('The deployment state must be: %s', implode(', ', $allowedStates))); - } - - $data = [ - 'state' => $state, - ]; - - if ($targetUrl) - { - $data['target_url'] = $targetUrl; - } - - if ($description) - { - $data['description'] = $description; - } - - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($data)), - 201 - ); - } + /** + * List Deployments. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha The SHA that was recorded at creation time. + * @param string $ref The name of the ref. This can be a branch, tag, or SHA. + * @param string $task The name of the task for the deployment. + * @param string $environment The name of the environment that was deployed to. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.4.0 + */ + public function getList($owner, $repo, $sha = '', $ref = '', $task = '', $environment = '', $page = 0, $limit = 0) + { + // Build the request path. + $path = "/repos/$owner/$repo/deployments"; + + $uri = $this->fetchUrl($path, $page, $limit); + + if ($sha) { + $uri->setVar('sha', $sha); + } + + if ($ref) { + $uri->setVar('ref', $ref); + } + + if ($task) { + $uri->setVar('task', $task); + } + + if ($environment) { + $uri->setVar('environment', $environment); + } + + return $this->processResponse($this->client->get($uri)); + } + + /** + * Create a Deployment. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $ref The ref to deploy. This can be a branch, tag, or SHA. + * @param string $task Optional parameter to specify a task to execute. + * @param boolean $autoMerge Optional parameter to merge the default branch into the requested ref if + * it is behind the default branch. + * @param array|null $requiredContexts Optional array of status contexts verified against commit status checks. + * If this parameter is omitted + * from the parameters then all unique contexts will be verified before a + * deployment is created. To bypass checking entirely pass an empty array. + * Defaults to all unique contexts. + * @param string $payload Optional JSON payload with extra information about the deployment. + * @param string $environment Optional name for the target deployment environment. + * @param string $description Optional short description. + * + * @return object + * + * @since 1.4.0 + * @throws \RuntimeException + */ + public function create( + $owner, + $repo, + $ref, + $task = '', + $autoMerge = true, + $requiredContexts = null, + $payload = '', + $environment = '', + $description = '' + ) { + // Build the request path. + $path = "/repos/$owner/$repo/deployments"; + + $data = [ + 'ref' => $ref, + 'auto_merge' => $autoMerge, + ]; + + if ($task) { + $data['task'] = $task; + } + + if (\is_array($requiredContexts)) { + $data['required_contexts'] = $requiredContexts; + } + + if ($payload) { + $data['payload'] = $payload; + } + + if ($environment) { + $data['environment'] = $environment; + } + + if ($description) { + $data['description'] = $description; + } + + $response = $this->client->post($this->fetchUrl($path), json_encode($data)); + + switch ($response->code) { + case 201: + // The deployment was successful + return json_decode($response->body); + + case 409: + // There was a merge conflict or a status check failed. + $body = json_decode($response->body); + $message = isset($body->message) ? $body->message : 'Invalid response received from GitHub.'; + + throw new \RuntimeException($message, $response->code); + + default: + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + } + + /** + * List Deployment Statuses. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id The Deployment ID to list the statuses from. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.4.0 + */ + public function getDeploymentStatuses($owner, $repo, $id, $page = 0, $limit = 0) + { + // Build the request path. + $path = "/repos/$owner/$repo/deployments/" . (int) $id . '/statuses'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path, $page, $limit)) + ); + } + + /** + * Create a Deployment Status. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id The Deployment ID to list the statuses from. + * @param string $state The state of the status. + * @param string $targetUrl The target URL to associate with this status. This URL should contain output to keep the user updated while + * the task is running or serve as historical information for what happened in the deployment. + * @param string $description A short description of the status. Maximum length of 140 characters. + * + * @return object + * + * @since 1.4.0 + * @throws \InvalidArgumentException + */ + public function createStatus($owner, $repo, $id, $state, $targetUrl = '', $description = '') + { + $allowedStates = ['pending', 'success', 'error', 'failure']; + + // Build the request path. + $path = "/repos/$owner/$repo/deployments/" . (int) $id . '/statuses'; + + if (!\in_array($state, $allowedStates)) { + throw new \InvalidArgumentException(sprintf('The deployment state must be: %s', implode(', ', $allowedStates))); + } + + $data = [ + 'state' => $state, + ]; + + if ($targetUrl) { + $data['target_url'] = $targetUrl; + } + + if ($description) { + $data['description'] = $description; + } + + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($data)), + 201 + ); + } } diff --git a/src/Package/Repositories/Downloads.php b/src/Package/Repositories/Downloads.php index ed6c62a4..6cfbc3d4 100644 --- a/src/Package/Repositories/Downloads.php +++ b/src/Package/Repositories/Downloads.php @@ -24,146 +24,146 @@ */ class Downloads extends AbstractPackage { - /** - * List downloads for a repository. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return object - * - * @since 1.0 - * @deprecated The Releases API should be used instead - */ - public function getList($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/downloads'; + /** + * List downloads for a repository. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return object + * + * @since 1.0 + * @deprecated The Releases API should be used instead + */ + public function getList($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/downloads'; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Get a single download. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The id of the download. - * - * @return object - * - * @since 1.0 - * @deprecated The Releases API should be used instead - */ - public function get($owner, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/downloads/' . $id; + /** + * Get a single download. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id The id of the download. + * + * @return object + * + * @since 1.0 + * @deprecated The Releases API should be used instead + */ + public function get($owner, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/downloads/' . $id; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Create a new download (Part 1: Create the resource). - * - * Creating a new download is a two step process. You must first create a new download resource. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $name The name. - * @param string $size Size of file in bytes. - * @param string $description The description. - * @param string $contentType The content type. - * - * @return void - * - * @note This API endpoint no longer exists at GitHub - * @since 1.0 - * @throws \RuntimeException - * @deprecated The Releases API should be used instead - */ - public function create($owner, $repo, $name, $size, $description = '', $contentType = '') - { - throw new \RuntimeException('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); - } + /** + * Create a new download (Part 1: Create the resource). + * + * Creating a new download is a two step process. You must first create a new download resource. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $name The name. + * @param string $size Size of file in bytes. + * @param string $description The description. + * @param string $contentType The content type. + * + * @return void + * + * @note This API endpoint no longer exists at GitHub + * @since 1.0 + * @throws \RuntimeException + * @deprecated The Releases API should be used instead + */ + public function create($owner, $repo, $name, $size, $description = '', $contentType = '') + { + throw new \RuntimeException('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); + } - /** - * Create a new download (Part 2: Upload file to s3). - * - * Now that you have created the download resource, you can use the information - * in the response to upload your file to s3. This can be done with a POST to - * the s3_url you got in the create response. Here is a brief example using curl: - * - * curl \ - * -F "key=downloads/octocat/Hello-World/new_file.jpg" \ - * -F "acl=public-read" \ - * -F "success_action_status=201" \ - * -F "Filename=new_file.jpg" \ - * -F "AWSAccessKeyId=1ABCDEF..." \ - * -F "Policy=ewogIC..." \ - * -F "Signature=mwnF..." \ - * -F "Content-Type=image/jpeg" \ - * -F "file=@new_file.jpg" \ - * https://github.s3.amazonaws.com/ - * - * NOTES - * The order in which you pass these fields matters! Follow the order shown above exactly. - * All parameters shown are required and if you excluded or modify them your upload will - * fail because the values are hashed and signed by the policy. - * - * More information about using the REST API to interact with s3 can be found here: - * http://docs.amazonwebservices.com/AmazonS3/latest/API/ - * - * @param string $key Value of path field in the response. - * @param string $acl Value of acl field in the response. - * @param string $successActionStatus 201, or whatever you want to get back. - * @param string $filename Value of name field in the response. - * @param string $awsAccessKeyId Value of accesskeyid field in the response. - * @param string $policy Value of policy field in the response. - * @param string $signature Value of signature field in the response. - * @param string $contentType Value of mime_type field in the response. - * @param string $file Local file. Example assumes the file existing in the directory - * where you are running the curl command. Yes, the @ matters. - * - * @return void - * - * @note This API endpoint no longer exists at GitHub - * @since 1.0 - * @throws \RuntimeException - * @deprecated The Releases API should be used instead - */ - public function upload($key, $acl, $successActionStatus, $filename, $awsAccessKeyId, $policy, $signature, $contentType, $file) - { - throw new \RuntimeException('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); - } + /** + * Create a new download (Part 2: Upload file to s3). + * + * Now that you have created the download resource, you can use the information + * in the response to upload your file to s3. This can be done with a POST to + * the s3_url you got in the create response. Here is a brief example using curl: + * + * curl \ + * -F "key=downloads/octocat/Hello-World/new_file.jpg" \ + * -F "acl=public-read" \ + * -F "success_action_status=201" \ + * -F "Filename=new_file.jpg" \ + * -F "AWSAccessKeyId=1ABCDEF..." \ + * -F "Policy=ewogIC..." \ + * -F "Signature=mwnF..." \ + * -F "Content-Type=image/jpeg" \ + * -F "file=@new_file.jpg" \ + * https://github.s3.amazonaws.com/ + * + * NOTES + * The order in which you pass these fields matters! Follow the order shown above exactly. + * All parameters shown are required and if you excluded or modify them your upload will + * fail because the values are hashed and signed by the policy. + * + * More information about using the REST API to interact with s3 can be found here: + * http://docs.amazonwebservices.com/AmazonS3/latest/API/ + * + * @param string $key Value of path field in the response. + * @param string $acl Value of acl field in the response. + * @param string $successActionStatus 201, or whatever you want to get back. + * @param string $filename Value of name field in the response. + * @param string $awsAccessKeyId Value of accesskeyid field in the response. + * @param string $policy Value of policy field in the response. + * @param string $signature Value of signature field in the response. + * @param string $contentType Value of mime_type field in the response. + * @param string $file Local file. Example assumes the file existing in the directory + * where you are running the curl command. Yes, the @ matters. + * + * @return void + * + * @note This API endpoint no longer exists at GitHub + * @since 1.0 + * @throws \RuntimeException + * @deprecated The Releases API should be used instead + */ + public function upload($key, $acl, $successActionStatus, $filename, $awsAccessKeyId, $policy, $signature, $contentType, $file) + { + throw new \RuntimeException('The GitHub API no longer supports creating downloads. The Releases API should be used instead.'); + } - /** - * Delete a download. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The id of the download. - * - * @return object - * - * @since 1.0 - * @deprecated The Releases API should be used instead - */ - public function delete($owner, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/downloads/' . (int) $id; + /** + * Delete a download. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id The id of the download. + * + * @return object + * + * @since 1.0 + * @deprecated The Releases API should be used instead + */ + public function delete($owner, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/downloads/' . (int) $id; - // Send the request. - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + // Send the request. + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } } diff --git a/src/Package/Repositories/Forks.php b/src/Package/Repositories/Forks.php index 6aa7d68b..03459d1f 100644 --- a/src/Package/Repositories/Forks.php +++ b/src/Package/Repositories/Forks.php @@ -19,57 +19,54 @@ */ class Forks extends AbstractPackage { - /** - * Create a fork. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $org The organization to fork the repo into. By default it is forked to the current user. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function create($owner, $repo, $org = '') - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/forks'; + /** + * Create a fork. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $org The organization to fork the repo into. By default it is forked to the current user. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function create($owner, $repo, $org = '') + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/forks'; - if (\strlen($org) > 0) - { - $data = json_encode( - ['org' => $org] - ); - } - else - { - $data = json_encode([]); - } + if (\strlen($org) > 0) { + $data = json_encode( + ['org' => $org] + ); + } else { + $data = json_encode([]); + } - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 202); - } + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 202); + } - /** - * List forks. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $page Page to request - * @param integer $limit Number of results to return per page - * - * @return array - * - * @since 1.0 - * @throws \DomainException - */ - public function getList($owner, $repo, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/forks'; + /** + * List forks. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $page Page to request + * @param integer $limit Number of results to return per page + * + * @return array + * + * @since 1.0 + * @throws \DomainException + */ + public function getList($owner, $repo, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/forks'; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit)), 200); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit)), 200); + } } diff --git a/src/Package/Repositories/Hooks.php b/src/Package/Repositories/Hooks.php index 0f7b1739..a63bd778 100644 --- a/src/Package/Repositories/Hooks.php +++ b/src/Package/Repositories/Hooks.php @@ -19,220 +19,212 @@ */ class Hooks extends AbstractPackage { - /** - * Create a hook. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $name The name of the service being called. - * @param array $config Array containing the config for the service. - * @param array $events The events the hook will be triggered for. - * @param boolean $active Flag to determine if the hook is active - * - * @return object - * - * @since 1.0 - * @throws \DomainException - * @throws \RuntimeException - */ - public function create($user, $repo, $name, $config, array $events = ['push'], $active = true) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/hooks'; - - // Check to ensure all events are in the allowed list - foreach ($events as $event) - { - if (!\in_array($event, $this->hookEvents)) - { - throw new \RuntimeException('Your events array contains an unauthorized event.'); - } - } - - $data = json_encode( - ['name' => $name, 'config' => $config, 'events' => $events, 'active' => $active] - ); - - return $this->processResponse( - $this->client->post($this->fetchUrl($path), $data), - 201 - ); - } - - /** - * Delete a hook - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id ID of the hook to delete. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function delete($user, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * Edit a hook. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id ID of the hook to edit. - * @param string $name The name of the service being called. - * @param array $config Array containing the config for the service. - * @param array $events The events the hook will be triggered for. This resets the currently set list - * @param array $addEvents Events to add to the hook. - * @param array $removeEvents Events to remove from the hook. - * @param boolean $active Flag to determine if the hook is active - * - * @return object - * - * @since 1.0 - * @throws \DomainException - * @throws \RuntimeException - */ - public function edit($user, $repo, $id, $name, $config, array $events = ['push'], array $addEvents = [], array $removeEvents = [], $active = true) - { - // Check to ensure all events are in the allowed list - foreach ($events as $event) - { - if (!\in_array($event, $this->hookEvents)) - { - throw new \RuntimeException('Your events array contains an unauthorized event.'); - } - } - - foreach ($addEvents as $event) - { - if (!\in_array($event, $this->hookEvents)) - { - throw new \RuntimeException('Your active_events array contains an unauthorized event.'); - } - } - - foreach ($removeEvents as $event) - { - if (!\in_array($event, $this->hookEvents)) - { - throw new \RuntimeException('Your remove_events array contains an unauthorized event.'); - } - } - - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id; - - $data = json_encode( - [ - 'name' => $name, - 'config' => $config, - 'events' => $events, - 'add_events' => $addEvents, - 'remove_events' => $removeEvents, - 'active' => $active, - ] - ); - - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), $data) - ); - } - - /** - * Get single hook. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id ID of the hook to retrieve - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($user, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List hooks. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getList($user, $repo) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/hooks'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Ping a hook. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id ID of the hook to ping - * - * @return object - * - * @since 1.4.0 - * @throws \DomainException - */ - public function ping($user, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id . '/pings'; - - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode('')), - 204 - ); - } - - /** - * Test a `push` hook. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id ID of the hook to test - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function test($user, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id . '/test'; - - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode('')), - 204 - ); - } + /** + * Create a hook. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $name The name of the service being called. + * @param array $config Array containing the config for the service. + * @param array $events The events the hook will be triggered for. + * @param boolean $active Flag to determine if the hook is active + * + * @return object + * + * @since 1.0 + * @throws \DomainException + * @throws \RuntimeException + */ + public function create($user, $repo, $name, $config, array $events = ['push'], $active = true) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/hooks'; + + // Check to ensure all events are in the allowed list + foreach ($events as $event) { + if (!\in_array($event, $this->hookEvents)) { + throw new \RuntimeException('Your events array contains an unauthorized event.'); + } + } + + $data = json_encode( + ['name' => $name, 'config' => $config, 'events' => $events, 'active' => $active] + ); + + return $this->processResponse( + $this->client->post($this->fetchUrl($path), $data), + 201 + ); + } + + /** + * Delete a hook + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id ID of the hook to delete. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function delete($user, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * Edit a hook. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id ID of the hook to edit. + * @param string $name The name of the service being called. + * @param array $config Array containing the config for the service. + * @param array $events The events the hook will be triggered for. This resets the currently set list + * @param array $addEvents Events to add to the hook. + * @param array $removeEvents Events to remove from the hook. + * @param boolean $active Flag to determine if the hook is active + * + * @return object + * + * @since 1.0 + * @throws \DomainException + * @throws \RuntimeException + */ + public function edit($user, $repo, $id, $name, $config, array $events = ['push'], array $addEvents = [], array $removeEvents = [], $active = true) + { + // Check to ensure all events are in the allowed list + foreach ($events as $event) { + if (!\in_array($event, $this->hookEvents)) { + throw new \RuntimeException('Your events array contains an unauthorized event.'); + } + } + + foreach ($addEvents as $event) { + if (!\in_array($event, $this->hookEvents)) { + throw new \RuntimeException('Your active_events array contains an unauthorized event.'); + } + } + + foreach ($removeEvents as $event) { + if (!\in_array($event, $this->hookEvents)) { + throw new \RuntimeException('Your remove_events array contains an unauthorized event.'); + } + } + + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id; + + $data = json_encode( + [ + 'name' => $name, + 'config' => $config, + 'events' => $events, + 'add_events' => $addEvents, + 'remove_events' => $removeEvents, + 'active' => $active, + ] + ); + + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), $data) + ); + } + + /** + * Get single hook. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id ID of the hook to retrieve + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($user, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List hooks. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getList($user, $repo) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/hooks'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Ping a hook. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id ID of the hook to ping + * + * @return object + * + * @since 1.4.0 + * @throws \DomainException + */ + public function ping($user, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id . '/pings'; + + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode('')), + 204 + ); + } + + /** + * Test a `push` hook. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id ID of the hook to test + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function test($user, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id . '/test'; + + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode('')), + 204 + ); + } } diff --git a/src/Package/Repositories/Keys.php b/src/Package/Repositories/Keys.php index 1e53f49c..54f18f0c 100644 --- a/src/Package/Repositories/Keys.php +++ b/src/Package/Repositories/Keys.php @@ -19,124 +19,124 @@ */ class Keys extends AbstractPackage { - /** - * List deploy keys. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @since 1.0 - * - * @return object - */ - public function getList($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/keys'; + /** + * List deploy keys. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @since 1.0 + * + * @return object + */ + public function getList($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/keys'; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Get a deploy key. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The id of the key. - * - * @since 1.0 - * - * @return object - */ - public function get($owner, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id; + /** + * Get a deploy key. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id The id of the key. + * + * @since 1.0 + * + * @return object + */ + public function get($owner, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Add a new deploy key. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $title The key title. - * @param string $key The key. - * - * @since 1.0 - * - * @return object - */ - public function create($owner, $repo, $title, $key) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/keys'; + /** + * Add a new deploy key. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $title The key title. + * @param string $key The key. + * + * @since 1.0 + * + * @return object + */ + public function create($owner, $repo, $title, $key) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/keys'; - $data = [ - 'title' => $title, - 'key' => $key, - ]; + $data = [ + 'title' => $title, + 'key' => $key, + ]; - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($data)), - 201 - ); - } + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($data)), + 201 + ); + } - /** - * Edit a deploy key. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The id of the key. - * @param string $title The key title. - * @param string $key The key. - * - * @since 1.0 - * - * @return object - */ - public function edit($owner, $repo, $id, $title, $key) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id; + /** + * Edit a deploy key. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id The id of the key. + * @param string $title The key title. + * @param string $key The key. + * + * @since 1.0 + * + * @return object + */ + public function edit($owner, $repo, $id, $title, $key) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id; - $data = [ - 'title' => $title, - 'key' => $key, - ]; + $data = [ + 'title' => $title, + 'key' => $key, + ]; - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), json_encode($data)) - ); - } + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), json_encode($data)) + ); + } - /** - * Remove a deploy key. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $id The id of the key. - * - * @since 1.0 - * - * @return boolean - */ - public function delete($owner, $repo, $id) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id; + /** + * Remove a deploy key. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $id The id of the key. + * + * @since 1.0 + * + * @return boolean + */ + public function delete($owner, $repo, $id) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/keys/' . (int) $id; - $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); + $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); - return true; - } + return true; + } } diff --git a/src/Package/Repositories/Merging.php b/src/Package/Repositories/Merging.php index 292c8cbd..5b257649 100644 --- a/src/Package/Repositories/Merging.php +++ b/src/Package/Repositories/Merging.php @@ -19,67 +19,65 @@ */ class Merging extends AbstractPackage { - /** - * Perform a merge. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $base The name of the base branch that the head will be merged into. - * @param string $head The head to merge. This can be a branch name or a commit SHA1. - * @param string $commitMessage Commit message to use for the merge commit. - * If omitted, a default message will be used. - * - * @return boolean - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function perform($owner, $repo, $base, $head, $commitMessage = '') - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/merges'; - - $data = new \stdClass; - - $data->base = $base; - $data->head = $head; - - if ($commitMessage) - { - $data->commit_message = $commitMessage; - } - - // Send the request. - $response = $this->client->post($this->fetchUrl($path), json_encode($data)); - - switch ($response->code) - { - case '201': - // Success - return json_decode($response->body); - - case '204': - // No-op response (base already contains the head, nothing to merge) - throw new \UnexpectedValueException('Nothing to merge'); - - case '404': - // Missing base or Missing head response - $error = json_decode($response->body); - - $message = (isset($error->message)) ? $error->message : 'Missing base or head: ' . $response->code; - - throw new \UnexpectedValueException($message); - - case '409': - // Merge conflict response - $error = json_decode($response->body); - - $message = (isset($error->message)) ? $error->message : 'Merge conflict ' . $response->code; - - throw new \UnexpectedValueException($message); - - default : - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - } + /** + * Perform a merge. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $base The name of the base branch that the head will be merged into. + * @param string $head The head to merge. This can be a branch name or a commit SHA1. + * @param string $commitMessage Commit message to use for the merge commit. + * If omitted, a default message will be used. + * + * @return boolean + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function perform($owner, $repo, $base, $head, $commitMessage = '') + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/merges'; + + $data = new \stdClass(); + + $data->base = $base; + $data->head = $head; + + if ($commitMessage) { + $data->commit_message = $commitMessage; + } + + // Send the request. + $response = $this->client->post($this->fetchUrl($path), json_encode($data)); + + switch ($response->code) { + case '201': + // Success + return json_decode($response->body); + + case '204': + // No-op response (base already contains the head, nothing to merge) + throw new \UnexpectedValueException('Nothing to merge'); + + case '404': + // Missing base or Missing head response + $error = json_decode($response->body); + + $message = (isset($error->message)) ? $error->message : 'Missing base or head: ' . $response->code; + + throw new \UnexpectedValueException($message); + + case '409': + // Merge conflict response + $error = json_decode($response->body); + + $message = (isset($error->message)) ? $error->message : 'Merge conflict ' . $response->code; + + throw new \UnexpectedValueException($message); + + default: + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + } } diff --git a/src/Package/Repositories/Pages.php b/src/Package/Repositories/Pages.php index 44dd6198..2c0d79e8 100644 --- a/src/Package/Repositories/Pages.php +++ b/src/Package/Repositories/Pages.php @@ -19,65 +19,65 @@ */ class Pages extends AbstractPackage { - /** - * Get information about a Pages site. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return object - * - * @since 1.4.0 - */ - public function getInfo($owner, $repo) - { - // Build the request path. - $path = "/repos/$owner/$repo/pages"; + /** + * Get information about a Pages site. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return object + * + * @since 1.4.0 + */ + public function getInfo($owner, $repo) + { + // Build the request path. + $path = "/repos/$owner/$repo/pages"; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * List Pages builds. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.4.0 - */ - public function getList($owner, $repo, $page = 0, $limit = 0) - { - // Build the request path. - $path = "/repos/$owner/$repo/pages/builds"; + /** + * List Pages builds. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.4.0 + */ + public function getList($owner, $repo, $page = 0, $limit = 0) + { + // Build the request path. + $path = "/repos/$owner/$repo/pages/builds"; - return $this->processResponse( - $this->client->get($this->fetchUrl($path, $page, $limit)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path, $page, $limit)) + ); + } - /** - * List latest Pages build. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return object - * - * @since 1.4.0 - */ - public function getLatest($owner, $repo) - { - // Build the request path. - $path = "/repos/$owner/$repo/pages/builds/latest"; + /** + * List latest Pages build. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return object + * + * @since 1.4.0 + */ + public function getLatest($owner, $repo) + { + // Build the request path. + $path = "/repos/$owner/$repo/pages/builds/latest"; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } } diff --git a/src/Package/Repositories/Releases.php b/src/Package/Repositories/Releases.php index cacc90a6..75724eee 100644 --- a/src/Package/Repositories/Releases.php +++ b/src/Package/Repositories/Releases.php @@ -19,317 +19,309 @@ */ class Releases extends AbstractPackage { - /** - * Create a release. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $tagName The name of the tag. - * @param string $targetCommitish The commitish value that determines where the Git tag is created from. - * @param string $name The name of the release. - * @param string $body Text describing the contents of the tag. - * @param boolean $draft True to create a draft (unpublished) release, false to create a published one. - * @param boolean $preRelease True to identify the release as a prerelease. false to identify the release as a full release. - * - * @return object - * - * @link http://developer.github.com/v3/repos/releases/#create-a-release - * @since 1.1.0 - */ - public function create($user, $repo, $tagName, $targetCommitish = '', $name = '', $body = '', $draft = false, $preRelease = false) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/releases'; - - // Build the request data. - $data = json_encode( - [ - 'tag_name' => $tagName, - 'target_commitish' => $targetCommitish, - 'name' => $name, - 'body' => $body, - 'draft' => (boolean) $draft, - 'prerelease' => (boolean) $preRelease, - ] - ); - - // Send the request. - return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); - } - - /** - * Delete a release. - * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $releaseId The release id. - * - * @return object - * - * @since 1.4.0 - */ - public function delete($owner, $repo, $releaseId) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/releases/' . (int) $releaseId; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } - - /** - * Edit a release. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $releaseId The release id. - * @param string $tagName The name of the tag. - * @param string $targetCommitish The commitish value that determines where the Git tag is created from. - * @param string $name The branch (or git ref) you want your changes pulled into. This should be an existing branch on the current - * repository. You cannot submit a pull request to one repo that requests a merge to a base of another repo. - * @param boolean $body The body text for the new pull request. - * @param boolean $draft The branch (or git ref) where your changes are implemented. - * @param string $preRelease The branch (or git ref) where your changes are implemented. - * - * @return object - * - * @link http://developer.github.com/v3/repos/releases/#edit-a-release - * @since 1.1.0 - * @throws \DomainException - */ - public function edit($user, $repo, $releaseId, $tagName, $targetCommitish = null, $name = null, $body = null, $draft = null, $preRelease = null) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/releases/' . (int) $releaseId; - - // Create the data object. - $data = new \stdClass; - $data->tag_name = $tagName; - - // Check if input values are set and add them to the data object. - if (isset($targetCommitish)) - { - $data->target_commitish = $targetCommitish; - } - - if (isset($name)) - { - $data->name = $name; - } - - if (isset($body)) - { - $data->body = $body; - } - - if (isset($draft)) - { - $data->draft = $draft; - } - - if (isset($preRelease)) - { - $data->prerelease = $preRelease; - } - - // Encode the request data. - $data = json_encode($data); - - // Send the request. - return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); - } - - /** - * Get a single release. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $ref Valid values are: 'latest', 'tags/2.0.24' or Release Id, for example: '1643513' - * - * @return object - * - * @since 1.1.0 - * @throws \DomainException - */ - public function get($user, $repo, $ref) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/releases/' . $ref; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Get the latest release. - * - * View the latest published full release for the repository. - * Draft releases and prereleases are not returned by this endpoint. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * - * @return object - * - * @since 1.4.0 - */ - public function getLatest($user, $repo) - { - // Build the request path. - $path = "/repos/$user/$repo/releases/latest"; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Get a release by tag name. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $tag The name of the tag. - * - * @return object - * - * @since 1.4.0 - */ - public function getByTag($user, $repo, $tag) - { - // Build the request path. - $path = "/repos/$user/$repo/releases/tags/$tag"; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * List releases for a repository. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return array An associative array of releases keyed by the tag name. - * - * @since 1.1.0 - * @throws \DomainException - */ - public function getList($user, $repo, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/releases'; - - // Send the request. - $response = $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - - $releases = []; - - if (\is_array($response)) - { - foreach ($response as $release) - { - $releases[$release->tag_name] = $release; - } - } - - return $releases; - } - - /** - * List assets for a release. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $releaseId The release id. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * - * @return object - * - * @since 1.4.0 - */ - public function getListAssets($user, $repo, $releaseId, $page = 0, $limit = 0) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/releases/' . (int) $releaseId . '/assets'; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); - } - - /** - * Get a single release asset. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $assetId The asset id. - * - * @return object - * - * @since 1.4.0 - */ - public function getAsset($user, $repo, $assetId) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/releases/assets/' . (int) $assetId; - - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } - - /** - * Edit a release asset. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $assetId The asset id. - * @param string $name The file name of the asset. - * @param string $label An alternate short description of the asset. Used in place of the filename. - * - * @return object - * - * @since 1.4.0 - */ - public function editAsset($user, $repo, $assetId, $name, $label = '') - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/releases/assets/' . (int) $assetId; - - $data = [ - 'name' => $name, - ]; - - if ($label) - { - $data['label'] = $label; - } - - // Send the request. - return $this->processResponse($this->client->patch($this->fetchUrl($path), json_encode($data))); - } - - /** - * Delete a release asset. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $assetId The asset id. - * - * @return boolean - * - * @since 1.4.0 - */ - public function deleteAsset($user, $repo, $assetId) - { - // Build the request path. - $path = '/repos/' . $user . '/' . $repo . '/releases/assets/' . (int) $assetId; - - // Send the request. - $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); - - return true; - } + /** + * Create a release. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $tagName The name of the tag. + * @param string $targetCommitish The commitish value that determines where the Git tag is created from. + * @param string $name The name of the release. + * @param string $body Text describing the contents of the tag. + * @param boolean $draft True to create a draft (unpublished) release, false to create a published one. + * @param boolean $preRelease True to identify the release as a prerelease. false to identify the release as a full release. + * + * @return object + * + * @link http://developer.github.com/v3/repos/releases/#create-a-release + * @since 1.1.0 + */ + public function create($user, $repo, $tagName, $targetCommitish = '', $name = '', $body = '', $draft = false, $preRelease = false) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/releases'; + + // Build the request data. + $data = json_encode( + [ + 'tag_name' => $tagName, + 'target_commitish' => $targetCommitish, + 'name' => $name, + 'body' => $body, + 'draft' => (bool) $draft, + 'prerelease' => (bool) $preRelease, + ] + ); + + // Send the request. + return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); + } + + /** + * Delete a release. + * + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $releaseId The release id. + * + * @return object + * + * @since 1.4.0 + */ + public function delete($owner, $repo, $releaseId) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/releases/' . (int) $releaseId; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } + + /** + * Edit a release. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $releaseId The release id. + * @param string $tagName The name of the tag. + * @param string $targetCommitish The commitish value that determines where the Git tag is created from. + * @param string $name The branch (or git ref) you want your changes pulled into. This should be an existing branch on the current + * repository. You cannot submit a pull request to one repo that requests a merge to a base of another repo. + * @param boolean $body The body text for the new pull request. + * @param boolean $draft The branch (or git ref) where your changes are implemented. + * @param string $preRelease The branch (or git ref) where your changes are implemented. + * + * @return object + * + * @link http://developer.github.com/v3/repos/releases/#edit-a-release + * @since 1.1.0 + * @throws \DomainException + */ + public function edit($user, $repo, $releaseId, $tagName, $targetCommitish = null, $name = null, $body = null, $draft = null, $preRelease = null) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/releases/' . (int) $releaseId; + + // Create the data object. + $data = new \stdClass(); + $data->tag_name = $tagName; + + // Check if input values are set and add them to the data object. + if (isset($targetCommitish)) { + $data->target_commitish = $targetCommitish; + } + + if (isset($name)) { + $data->name = $name; + } + + if (isset($body)) { + $data->body = $body; + } + + if (isset($draft)) { + $data->draft = $draft; + } + + if (isset($preRelease)) { + $data->prerelease = $preRelease; + } + + // Encode the request data. + $data = json_encode($data); + + // Send the request. + return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); + } + + /** + * Get a single release. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $ref Valid values are: 'latest', 'tags/2.0.24' or Release Id, for example: '1643513' + * + * @return object + * + * @since 1.1.0 + * @throws \DomainException + */ + public function get($user, $repo, $ref) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/releases/' . $ref; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Get the latest release. + * + * View the latest published full release for the repository. + * Draft releases and prereleases are not returned by this endpoint. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return object + * + * @since 1.4.0 + */ + public function getLatest($user, $repo) + { + // Build the request path. + $path = "/repos/$user/$repo/releases/latest"; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Get a release by tag name. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $tag The name of the tag. + * + * @return object + * + * @since 1.4.0 + */ + public function getByTag($user, $repo, $tag) + { + // Build the request path. + $path = "/repos/$user/$repo/releases/tags/$tag"; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * List releases for a repository. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return array An associative array of releases keyed by the tag name. + * + * @since 1.1.0 + * @throws \DomainException + */ + public function getList($user, $repo, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/releases'; + + // Send the request. + $response = $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); + + $releases = []; + + if (\is_array($response)) { + foreach ($response as $release) { + $releases[$release->tag_name] = $release; + } + } + + return $releases; + } + + /** + * List assets for a release. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $releaseId The release id. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * + * @return object + * + * @since 1.4.0 + */ + public function getListAssets($user, $repo, $releaseId, $page = 0, $limit = 0) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/releases/' . (int) $releaseId . '/assets'; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path, $page, $limit))); + } + + /** + * Get a single release asset. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $assetId The asset id. + * + * @return object + * + * @since 1.4.0 + */ + public function getAsset($user, $repo, $assetId) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/releases/assets/' . (int) $assetId; + + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } + + /** + * Edit a release asset. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $assetId The asset id. + * @param string $name The file name of the asset. + * @param string $label An alternate short description of the asset. Used in place of the filename. + * + * @return object + * + * @since 1.4.0 + */ + public function editAsset($user, $repo, $assetId, $name, $label = '') + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/releases/assets/' . (int) $assetId; + + $data = [ + 'name' => $name, + ]; + + if ($label) { + $data['label'] = $label; + } + + // Send the request. + return $this->processResponse($this->client->patch($this->fetchUrl($path), json_encode($data))); + } + + /** + * Delete a release asset. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $assetId The asset id. + * + * @return boolean + * + * @since 1.4.0 + */ + public function deleteAsset($user, $repo, $assetId) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/releases/assets/' . (int) $assetId; + + // Send the request. + $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); + + return true; + } } diff --git a/src/Package/Repositories/Statistics.php b/src/Package/Repositories/Statistics.php index d8db3ee3..2252c396 100644 --- a/src/Package/Repositories/Statistics.php +++ b/src/Package/Repositories/Statistics.php @@ -21,155 +21,154 @@ * * @since 1.0 */ -class Statistics extends AbstractPackage +class Statistics extends AbstractPackage { - /** - * Get contributors list with additions, deletions, and commit counts. - * - * Response include: - * total - The Total number of commits authored by the contributor. - * - * Weekly Hash - * - * w - Start of the week - * a - Number of additions - * d - Number of deletions - * c - Number of commits - * - * @param string $owner The owner of the repository. - * @param string $repo The repository name. - * - * @return object - * - * @since 1.0 - */ - public function getListContributors($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/stats/contributors'; + /** + * Get contributors list with additions, deletions, and commit counts. + * + * Response include: + * total - The Total number of commits authored by the contributor. + * + * Weekly Hash + * + * w - Start of the week + * a - Number of additions + * d - Number of deletions + * c - Number of commits + * + * @param string $owner The owner of the repository. + * @param string $repo The repository name. + * + * @return object + * + * @since 1.0 + */ + public function getListContributors($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/stats/contributors'; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } - /** - * Get the last year of commit activity data. - * - * Returns the last year of commit activity grouped by week. - * The days array is a group of commits per day, starting on Sunday. - * - * @param string $owner The owner of the repository. - * @param string $repo The repository name. - * - * @return object - * - * @since 1.0 - */ - public function getActivityData($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/stats/commit_activity'; + /** + * Get the last year of commit activity data. + * + * Returns the last year of commit activity grouped by week. + * The days array is a group of commits per day, starting on Sunday. + * + * @param string $owner The owner of the repository. + * @param string $repo The repository name. + * + * @return object + * + * @since 1.0 + */ + public function getActivityData($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/stats/commit_activity'; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } - /** - * Get the number of additions and deletions per week. - * - * Response returns a weekly aggregate of the number of additions and deletions pushed to a repository. - * - * @param string $owner The owner of the repository. - * @param string $repo The repository name. - * - * @return object - * - * @since 1.0 - */ - public function getCodeFrequency($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/stats/code_frequency'; + /** + * Get the number of additions and deletions per week. + * + * Response returns a weekly aggregate of the number of additions and deletions pushed to a repository. + * + * @param string $owner The owner of the repository. + * @param string $repo The repository name. + * + * @return object + * + * @since 1.0 + */ + public function getCodeFrequency($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/stats/code_frequency'; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } - /** - * Get the weekly commit count for the repository owner and everyone else. - * - * Returns the total commit counts for the "owner" and total commit counts in "all". "all" is everyone combined, - * including the owner in the last 52 weeks. - * If you’d like to get the commit counts for non-owners, you can subtract all from owner. - * - * The array order is oldest week (index 0) to most recent week. - * - * @param string $owner The owner of the repository. - * @param string $repo The repository name. - * - * @return object - * - * @since 1.0 - */ - public function getParticipation($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/stats/participation'; + /** + * Get the weekly commit count for the repository owner and everyone else. + * + * Returns the total commit counts for the "owner" and total commit counts in "all". "all" is everyone combined, + * including the owner in the last 52 weeks. + * If you’d like to get the commit counts for non-owners, you can subtract all from owner. + * + * The array order is oldest week (index 0) to most recent week. + * + * @param string $owner The owner of the repository. + * @param string $repo The repository name. + * + * @return object + * + * @since 1.0 + */ + public function getParticipation($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/stats/participation'; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } - /** - * Get the number of commits per hour in each day. - * - * Response - * Each array contains the day number, hour number, and number of commits: - * - * 0-6: Sunday - Saturday - * 0-23: Hour of day - * Number of commits - * - * For example, [2, 14, 25] indicates that there were 25 total commits, during the 2:00pm hour on Tuesdays. - * All times are based on the time zone of individual commits. - * - * @param string $owner The owner of the repository. - * @param string $repo The repository name. - * - * @return object - * - * @since 1.0 - */ - public function getPunchCard($owner, $repo) - { - // Build the request path. - $path = '/repos/' . $owner . '/' . $repo . '/stats/punch_card'; + /** + * Get the number of commits per hour in each day. + * + * Response + * Each array contains the day number, hour number, and number of commits: + * + * 0-6: Sunday - Saturday + * 0-23: Hour of day + * Number of commits + * + * For example, [2, 14, 25] indicates that there were 25 total commits, during the 2:00pm hour on Tuesdays. + * All times are based on the time zone of individual commits. + * + * @param string $owner The owner of the repository. + * @param string $repo The repository name. + * + * @return object + * + * @since 1.0 + */ + public function getPunchCard($owner, $repo) + { + // Build the request path. + $path = '/repos/' . $owner . '/' . $repo . '/stats/punch_card'; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } - /** - * Process the response and decode it. - * - * @param Response $response The response. - * @param integer $expectedCode The expected "good" code. - * - * @return mixed - * - * @since 1.0 - * @throws \DomainException - */ - protected function processResponse(Response $response, $expectedCode = 200) - { - if ($response->code == 202) - { - throw new \DomainException( - 'GitHub is building the statistics data. Please try again in a few moments.', - $response->code - ); - } + /** + * Process the response and decode it. + * + * @param Response $response The response. + * @param integer $expectedCode The expected "good" code. + * + * @return mixed + * + * @since 1.0 + * @throws \DomainException + */ + protected function processResponse(Response $response, $expectedCode = 200) + { + if ($response->code == 202) { + throw new \DomainException( + 'GitHub is building the statistics data. Please try again in a few moments.', + $response->code + ); + } - return parent::processResponse($response, $expectedCode); - } + return parent::processResponse($response, $expectedCode); + } } diff --git a/src/Package/Repositories/Statuses.php b/src/Package/Repositories/Statuses.php index 4136eaef..26241271 100644 --- a/src/Package/Repositories/Statuses.php +++ b/src/Package/Repositories/Statuses.php @@ -19,99 +19,95 @@ */ class Statuses extends AbstractPackage { - /** - * Create a Status. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha The SHA1 value for which to set the status. - * @param string $state The state (pending, success, error or failure). - * @param string $targetUrl Optional target URL. - * @param string $description Optional description for the status. - * @param string $context A string label to differentiate this status from the status of other systems. - * Default: "default" - * - * @throws \InvalidArgumentException - * @throws \DomainException - * - * @return object - * - * @since 1.0 - */ - public function create($user, $repo, $sha, $state, $targetUrl = null, $description = null, $context = null) - { - // Build the request path. - $path = "/repos/$user/$repo/statuses/$sha"; + /** + * Create a Status. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha The SHA1 value for which to set the status. + * @param string $state The state (pending, success, error or failure). + * @param string $targetUrl Optional target URL. + * @param string $description Optional description for the status. + * @param string $context A string label to differentiate this status from the status of other systems. + * Default: "default" + * + * @throws \InvalidArgumentException + * @throws \DomainException + * + * @return object + * + * @since 1.0 + */ + public function create($user, $repo, $sha, $state, $targetUrl = null, $description = null, $context = null) + { + // Build the request path. + $path = "/repos/$user/$repo/statuses/$sha"; - if (!\in_array($state, ['pending', 'success', 'error', 'failure'])) - { - throw new \InvalidArgumentException('State must be one of pending, success, error or failure.'); - } + if (!\in_array($state, ['pending', 'success', 'error', 'failure'])) { + throw new \InvalidArgumentException('State must be one of pending, success, error or failure.'); + } - // Build the request data. - $data = [ - 'state' => $state, - ]; + // Build the request data. + $data = [ + 'state' => $state, + ]; - if ($targetUrl !== null) - { - $data['target_url'] = $targetUrl; - } + if ($targetUrl !== null) { + $data['target_url'] = $targetUrl; + } - if ($description !== null) - { - $data['description'] = $description; - } + if ($description !== null) { + $data['description'] = $description; + } - if ($context !== null) - { - $data['context'] = $context; - } + if ($context !== null) { + $data['context'] = $context; + } - // Send the request. - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($data)), - 201 - ); - } + // Send the request. + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($data)), + 201 + ); + } - /** - * List Statuses for a specific Ref. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha SHA1 for which to get the statuses. - * - * @return array - * - * @since 1.0 - */ - public function getList($user, $repo, $sha) - { - // Build the request path. - $path = "/repos/$user/$repo/statuses/$sha"; + /** + * List Statuses for a specific Ref. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha SHA1 for which to get the statuses. + * + * @return array + * + * @since 1.0 + */ + public function getList($user, $repo, $sha) + { + // Build the request path. + $path = "/repos/$user/$repo/statuses/$sha"; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } - /** - * Get the combined Status for a specific Ref. - * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha SHA1 for which to get the combined status. - * - * @return array - * - * @since 1.4.0 - */ - public function getCombinedStatus($user, $repo, $sha) - { - // Build the request path. - $path = "/repos/$user/$repo/commits/$sha/status"; + /** + * Get the combined Status for a specific Ref. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha SHA1 for which to get the combined status. + * + * @return array + * + * @since 1.4.0 + */ + public function getCombinedStatus($user, $repo, $sha) + { + // Build the request path. + $path = "/repos/$user/$repo/commits/$sha/status"; - // Send the request. - return $this->processResponse($this->client->get($this->fetchUrl($path))); - } + // Send the request. + return $this->processResponse($this->client->get($this->fetchUrl($path))); + } } diff --git a/src/Package/Search.php b/src/Package/Search.php index e50f4d79..5a0b56dd 100644 --- a/src/Package/Search.php +++ b/src/Package/Search.php @@ -19,122 +19,118 @@ */ class Search extends AbstractPackage { - /** - * Search issues. - * - * @param string $owner The name of the owner of the repository. - * @param string $repo The name of the repository. - * @param string $state The state - open or closed. - * @param string $keyword The search term. - * - * @return object - * - * @since 1.0 - * @throws \UnexpectedValueException - * @deprecated The legacy API is deprecated - */ - public function issues($owner, $repo, $state, $keyword) - { - if (\in_array($state, ['open', 'close']) == false) - { - throw new \UnexpectedValueException('State must be either "open" or "closed"'); - } + /** + * Search issues. + * + * @param string $owner The name of the owner of the repository. + * @param string $repo The name of the repository. + * @param string $state The state - open or closed. + * @param string $keyword The search term. + * + * @return object + * + * @since 1.0 + * @throws \UnexpectedValueException + * @deprecated The legacy API is deprecated + */ + public function issues($owner, $repo, $state, $keyword) + { + if (\in_array($state, ['open', 'close']) == false) { + throw new \UnexpectedValueException('State must be either "open" or "closed"'); + } - // Build the request path. - $path = '/legacy/issues/search/' . $owner . '/' . $repo . '/' . $state . '/' . $keyword; + // Build the request path. + $path = '/legacy/issues/search/' . $owner . '/' . $repo . '/' . $state . '/' . $keyword; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Search repositories. - * - * Find repositories by keyword. Note, this legacy method does not follow - * the v3 pagination pattern. - * This method returns up to 100 results per page and pages can be fetched - * using the start_page parameter. - * - * @param string $keyword The search term. - * @param string $language Filter results by language https://github.com/languages - * @param integer $startPage Page number to fetch - * - * @return object - * - * @since 1.0 - * @deprecated The legacy API is deprecated - */ - public function repositories($keyword, $language = '', $startPage = 0) - { - // Build the request path. - $uri = $this->fetchUrl('/legacy/repos/search/' . $keyword); + /** + * Search repositories. + * + * Find repositories by keyword. Note, this legacy method does not follow + * the v3 pagination pattern. + * This method returns up to 100 results per page and pages can be fetched + * using the start_page parameter. + * + * @param string $keyword The search term. + * @param string $language Filter results by language https://github.com/languages + * @param integer $startPage Page number to fetch + * + * @return object + * + * @since 1.0 + * @deprecated The legacy API is deprecated + */ + public function repositories($keyword, $language = '', $startPage = 0) + { + // Build the request path. + $uri = $this->fetchUrl('/legacy/repos/search/' . $keyword); - if ($language) - { - $uri->setVar('language', $language); - } + if ($language) { + $uri->setVar('language', $language); + } - if ($startPage) - { - $uri->setVar('start_page', $startPage); - } + if ($startPage) { + $uri->setVar('start_page', $startPage); + } - // Send the request. - return $this->processResponse($this->client->get($uri)); - } + // Send the request. + return $this->processResponse($this->client->get($uri)); + } - /** - * Search users. - * - * Find users by keyword. - * - * @param string $keyword The search term. - * @param integer $startPage Page number to fetch - * - * @return object - * - * @since 1.0 - * @deprecated The legacy API is deprecated - */ - public function users($keyword, $startPage = 0) - { - // Build the request path. - $uri = $this->fetchUrl('/legacy/user/search/' . $keyword); + /** + * Search users. + * + * Find users by keyword. + * + * @param string $keyword The search term. + * @param integer $startPage Page number to fetch + * + * @return object + * + * @since 1.0 + * @deprecated The legacy API is deprecated + */ + public function users($keyword, $startPage = 0) + { + // Build the request path. + $uri = $this->fetchUrl('/legacy/user/search/' . $keyword); - if ($startPage) - { - $uri->setVar('start_page', $startPage); - } + if ($startPage) { + $uri->setVar('start_page', $startPage); + } - // Send the request. - return $this->processResponse($this->client->get($uri)); - } + // Send the request. + return $this->processResponse($this->client->get($uri)); + } - /** - * Email search. - * - * This API call is added for compatibility reasons only. There’s no guarantee - * that full email searches will always be available. The @ character in the - * address must be left unencoded. Searches only against public email addresses - * (as configured on the user’s GitHub profile). - * - * @param string $email The email address(es). - * - * @return object - * - * @since 1.0 - * @deprecated The legacy API is deprecated - */ - public function email($email) - { - // Build the request path. - $path = '/legacy/user/email/' . $email; + /** + * Email search. + * + * This API call is added for compatibility reasons only. There’s no guarantee + * that full email searches will always be available. The @ character in the + * address must be left unencoded. Searches only against public email addresses + * (as configured on the user’s GitHub profile). + * + * @param string $email The email address(es). + * + * @return object + * + * @since 1.0 + * @deprecated The legacy API is deprecated + */ + public function email($email) + { + // Build the request path. + $path = '/legacy/user/email/' . $email; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } } diff --git a/src/Package/Users.php b/src/Package/Users.php index 445df649..c808f04e 100644 --- a/src/Package/Users.php +++ b/src/Package/Users.php @@ -23,106 +23,105 @@ */ class Users extends AbstractPackage { - /** - * Get a single user. - * - * @param string $user The users login name. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function get($user) - { - // Build the request path. - $path = '/users/' . $user; + /** + * Get a single user. + * + * @param string $user The users login name. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function get($user) + { + // Build the request path. + $path = '/users/' . $user; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Get the authenticated user. - * - * @return mixed - * - * @since 1.0 - * @throws \DomainException - */ - public function getAuthenticatedUser() - { - // Build the request path. - $path = '/user'; + /** + * Get the authenticated user. + * + * @return mixed + * + * @since 1.0 + * @throws \DomainException + */ + public function getAuthenticatedUser() + { + // Build the request path. + $path = '/user'; - // Send the request. - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Update the authenticated user. - * - * @param string $name The full name - * @param string $email The email - * @param string $blog The blog - * @param string $company The company - * @param string $location The location - * @param string $hireable If he is unemployed :P - * @param string $bio The biometrical DNA fingerprint (or smthng...) - * - * @return mixed - * - * @since 1.0 - * @throws \DomainException - */ - public function edit($name = '', $email = '', $blog = '', $company = '', $location = '', $hireable = '', $bio = '') - { - $data = [ - 'name' => $name, - 'email' => $email, - 'blog' => $blog, - 'company' => $company, - 'location' => $location, - 'hireable' => $hireable, - 'bio' => $bio, - ]; + /** + * Update the authenticated user. + * + * @param string $name The full name + * @param string $email The email + * @param string $blog The blog + * @param string $company The company + * @param string $location The location + * @param string $hireable If he is unemployed :P + * @param string $bio The biometrical DNA fingerprint (or smthng...) + * + * @return mixed + * + * @since 1.0 + * @throws \DomainException + */ + public function edit($name = '', $email = '', $blog = '', $company = '', $location = '', $hireable = '', $bio = '') + { + $data = [ + 'name' => $name, + 'email' => $email, + 'blog' => $blog, + 'company' => $company, + 'location' => $location, + 'hireable' => $hireable, + 'bio' => $bio, + ]; - // Build the request path. - $path = '/user'; + // Build the request path. + $path = '/user'; - // Send the request. - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), json_encode($data)) - ); - } + // Send the request. + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), json_encode($data)) + ); + } - /** - * Get all users. - * - * This provides a dump of every user, in the order that they signed up for GitHub. - * - * @param integer $since The integer ID of the last User that you’ve seen. - * - * @return object - * - * @since 1.0 - * @throws \DomainException - */ - public function getList($since = 0) - { - // Build the request path. - $uri = $this->fetchUrl('/users'); + /** + * Get all users. + * + * This provides a dump of every user, in the order that they signed up for GitHub. + * + * @param integer $since The integer ID of the last User that you’ve seen. + * + * @return object + * + * @since 1.0 + * @throws \DomainException + */ + public function getList($since = 0) + { + // Build the request path. + $uri = $this->fetchUrl('/users'); - if ($since) - { - $uri->setVar('since', $since); - } + if ($since) { + $uri->setVar('since', $since); + } - // Send the request. - return $this->processResponse($this->client->get($uri)); - } + // Send the request. + return $this->processResponse($this->client->get($uri)); + } } diff --git a/src/Package/Users/Emails.php b/src/Package/Users/Emails.php index ca7592a8..b6504705 100644 --- a/src/Package/Users/Emails.php +++ b/src/Package/Users/Emails.php @@ -22,62 +22,62 @@ */ class Emails extends AbstractPackage { - /** - * List email addresses for a user. - * - * @return object - * - * @since 1.0 - */ - public function getList() - { - // Build the request path. - $path = '/user/emails'; + /** + * List email addresses for a user. + * + * @return object + * + * @since 1.0 + */ + public function getList() + { + // Build the request path. + $path = '/user/emails'; - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } - /** - * Add email address(es). - * - * @param string|array $email The email address(es). - * - * @return object - * - * @since 1.0 - */ - public function add($email) - { - // Build the request path. - $path = '/user/emails'; + /** + * Add email address(es). + * + * @param string|array $email The email address(es). + * + * @return object + * + * @since 1.0 + */ + public function add($email) + { + // Build the request path. + $path = '/user/emails'; - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($email)), - 201 - ); - } + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($email)), + 201 + ); + } - /** - * Delete email address(es). - * - * @param string|array $email The email address(es). - * - * @return object - * - * @since 1.0 - */ - public function delete($email) - { - // Build the request path. - $path = '/user/emails'; + /** + * Delete email address(es). + * + * @param string|array $email The email address(es). + * + * @return object + * + * @since 1.0 + */ + public function delete($email) + { + // Build the request path. + $path = '/user/emails'; - $this->client->setOption('body', json_encode($email)); + $this->client->setOption('body', json_encode($email)); - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } } diff --git a/src/Package/Users/Followers.php b/src/Package/Users/Followers.php index 8df9bc39..77e07a37 100644 --- a/src/Package/Users/Followers.php +++ b/src/Package/Users/Followers.php @@ -19,156 +19,154 @@ */ class Followers extends AbstractPackage { - /** - * List followers of a user. - * - * @param string $user The name of the user. If not set the current authenticated user will be used. - * - * @return object - * - * @since 1.0 - */ - public function getList($user = '') - { - // Build the request path. - $path = ($user) - ? '/users/' . $user . '/followers' - : '/user/followers'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List users followed by another user. - * - * @param string $user The name of the user. If not set the current authenticated user will be used. - * - * @return object - * - * @since 1.0 - */ - public function getListFollowedBy($user = '') - { - // Build the request path. - $path = ($user) - ? '/users/' . $user . '/following' - : '/user/following'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Check if you are following a user. - * - * @param string $user The name of the user. - * - * @return boolean - * - * @since 1.0 - * @throws \UnexpectedValueException - */ - public function check($user) - { - // Build the request path. - $path = '/user/following/' . $user; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->code) - { - case '204' : - // You are following this user - return true; - - case '404' : - // You are not following this user - return false; - - default : - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - } - - /** - * Check if one user follows another. - * - * @param string $user The name of the user. - * @param string $target The name of the user to check is being followed. - * - * @return boolean - * - * @since 1.4.0 - * @throws \UnexpectedValueException - */ - public function checkUserFollowing($user, $target) - { - // Build the request path. - $path = "/user/$user/following/$target"; - - $response = $this->client->get($this->fetchUrl($path)); - - switch ($response->code) - { - case '204' : - // User is following the target - return true; - - case '404' : - // User is not following the target - return false; - - default : - throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); - } - } - - /** - * Follow a user. - * - * Following a user requires the user to be logged in and authenticated with - * basic auth or OAuth with the user:follow scope. - * - * @param string $user The name of the user. - * - * @return object - * - * @since 1.0 - */ - public function follow($user) - { - // Build the request path. - $path = '/user/following/' . $user; - - return $this->processResponse( - $this->client->put($this->fetchUrl($path), ''), - 204 - ); - } - - /** - * Unfollow a user. - * - * Unfollowing a user requires the user to be logged in and authenticated with - * basic auth or OAuth with the user:follow scope. - * - * @param string $user The name of the user. - * - * @return object - * - * @since 1.0 - */ - public function unfollow($user) - { - // Build the request path. - $path = '/user/following/' . $user; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + /** + * List followers of a user. + * + * @param string $user The name of the user. If not set the current authenticated user will be used. + * + * @return object + * + * @since 1.0 + */ + public function getList($user = '') + { + // Build the request path. + $path = ($user) + ? '/users/' . $user . '/followers' + : '/user/followers'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List users followed by another user. + * + * @param string $user The name of the user. If not set the current authenticated user will be used. + * + * @return object + * + * @since 1.0 + */ + public function getListFollowedBy($user = '') + { + // Build the request path. + $path = ($user) + ? '/users/' . $user . '/following' + : '/user/following'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Check if you are following a user. + * + * @param string $user The name of the user. + * + * @return boolean + * + * @since 1.0 + * @throws \UnexpectedValueException + */ + public function check($user) + { + // Build the request path. + $path = '/user/following/' . $user; + + $response = $this->client->get($this->fetchUrl($path)); + + switch ($response->code) { + case '204': + // You are following this user + return true; + + case '404': + // You are not following this user + return false; + + default: + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + } + + /** + * Check if one user follows another. + * + * @param string $user The name of the user. + * @param string $target The name of the user to check is being followed. + * + * @return boolean + * + * @since 1.4.0 + * @throws \UnexpectedValueException + */ + public function checkUserFollowing($user, $target) + { + // Build the request path. + $path = "/user/$user/following/$target"; + + $response = $this->client->get($this->fetchUrl($path)); + + switch ($response->code) { + case '204': + // User is following the target + return true; + + case '404': + // User is not following the target + return false; + + default: + throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); + } + } + + /** + * Follow a user. + * + * Following a user requires the user to be logged in and authenticated with + * basic auth or OAuth with the user:follow scope. + * + * @param string $user The name of the user. + * + * @return object + * + * @since 1.0 + */ + public function follow($user) + { + // Build the request path. + $path = '/user/following/' . $user; + + return $this->processResponse( + $this->client->put($this->fetchUrl($path), ''), + 204 + ); + } + + /** + * Unfollow a user. + * + * Unfollowing a user requires the user to be logged in and authenticated with + * basic auth or OAuth with the user:follow scope. + * + * @param string $user The name of the user. + * + * @return object + * + * @since 1.0 + */ + public function unfollow($user) + { + // Build the request path. + $path = '/user/following/' . $user; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } } diff --git a/src/Package/Users/Keys.php b/src/Package/Users/Keys.php index 52aa501e..64c7ee25 100644 --- a/src/Package/Users/Keys.php +++ b/src/Package/Users/Keys.php @@ -19,136 +19,136 @@ */ class Keys extends AbstractPackage { - /** - * List public keys for a user. - * - * Lists the verified public keys for a user. This is accessible by anyone. - * - * @param string $user The name of the user. - * - * @return object - * - * @since 1.0 - */ - public function getListUser($user) - { - // Build the request path. - $path = '/users/' . $user . '/keys'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * List your public keys. - * - * Lists the current user’s keys. - * Management of public keys via the API requires that you are authenticated - * through basic auth, or OAuth with the ‘user’ scope. - * - * @return object - * - * @since 1.0 - */ - public function getList() - { - // Build the request path. - $path = '/users/keys'; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Get a single public key. - * - * @param integer $id The id of the key. - * - * @return object - * - * @since 1.0 - */ - public function get($id) - { - // Build the request path. - $path = '/users/keys/' . $id; - - return $this->processResponse( - $this->client->get($this->fetchUrl($path)) - ); - } - - /** - * Create a public key - * - * @param string $title The title of the key. - * @param string $key The key. - * - * @return object - * - * @since 1.0 - */ - public function create($title, $key) - { - // Build the request path. - $path = '/users/keys'; - - $data = [ - 'title' => $title, - 'key' => $key, - ]; - - return $this->processResponse( - $this->client->post($this->fetchUrl($path), json_encode($data)), - 201 - ); - } - - /** - * Update a public key. - * - * @param integer $id The id of the key. - * @param string $title The title of the key. - * @param string $key The key. - * - * @return object - * - * @since 1.0 - */ - public function edit($id, $title, $key) - { - // Build the request path. - $path = '/users/keys/' . $id; - - $data = [ - 'title' => $title, - 'key' => $key, - ]; - - return $this->processResponse( - $this->client->patch($this->fetchUrl($path), json_encode($data)) - ); - } - - /** - * Delete a public key. - * - * @param integer $id The id of the key. - * - * @return object - * - * @since 1.0 - */ - public function delete($id) - { - // Build the request path. - $path = '/users/keys/' . (int) $id; - - return $this->processResponse( - $this->client->delete($this->fetchUrl($path)), - 204 - ); - } + /** + * List public keys for a user. + * + * Lists the verified public keys for a user. This is accessible by anyone. + * + * @param string $user The name of the user. + * + * @return object + * + * @since 1.0 + */ + public function getListUser($user) + { + // Build the request path. + $path = '/users/' . $user . '/keys'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * List your public keys. + * + * Lists the current user’s keys. + * Management of public keys via the API requires that you are authenticated + * through basic auth, or OAuth with the ‘user’ scope. + * + * @return object + * + * @since 1.0 + */ + public function getList() + { + // Build the request path. + $path = '/users/keys'; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Get a single public key. + * + * @param integer $id The id of the key. + * + * @return object + * + * @since 1.0 + */ + public function get($id) + { + // Build the request path. + $path = '/users/keys/' . $id; + + return $this->processResponse( + $this->client->get($this->fetchUrl($path)) + ); + } + + /** + * Create a public key + * + * @param string $title The title of the key. + * @param string $key The key. + * + * @return object + * + * @since 1.0 + */ + public function create($title, $key) + { + // Build the request path. + $path = '/users/keys'; + + $data = [ + 'title' => $title, + 'key' => $key, + ]; + + return $this->processResponse( + $this->client->post($this->fetchUrl($path), json_encode($data)), + 201 + ); + } + + /** + * Update a public key. + * + * @param integer $id The id of the key. + * @param string $title The title of the key. + * @param string $key The key. + * + * @return object + * + * @since 1.0 + */ + public function edit($id, $title, $key) + { + // Build the request path. + $path = '/users/keys/' . $id; + + $data = [ + 'title' => $title, + 'key' => $key, + ]; + + return $this->processResponse( + $this->client->patch($this->fetchUrl($path), json_encode($data)) + ); + } + + /** + * Delete a public key. + * + * @param integer $id The id of the key. + * + * @return object + * + * @since 1.0 + */ + public function delete($id) + { + // Build the request path. + $path = '/users/keys/' . (int) $id; + + return $this->processResponse( + $this->client->delete($this->fetchUrl($path)), + 204 + ); + } } diff --git a/src/Package/Zen.php b/src/Package/Zen.php index bc012718..6411c155 100644 --- a/src/Package/Zen.php +++ b/src/Package/Zen.php @@ -19,22 +19,21 @@ */ class Zen extends AbstractPackage { - /** - * Get a random response about one of our design philosophies. - * - * @throws \RuntimeException - * - * @return string - */ - public function get() - { - $response = $this->client->get($this->fetchUrl('/zen')); + /** + * Get a random response about one of our design philosophies. + * + * @throws \RuntimeException + * + * @return string + */ + public function get() + { + $response = $this->client->get($this->fetchUrl('/zen')); - if ($response->code != 200) - { - throw new \RuntimeException('Can\'t get a Zen'); - } + if ($response->code != 200) { + throw new \RuntimeException('Can\'t get a Zen'); + } - return $response->body; - } + return $response->body; + } } From cd16ff4743978e781f9d5541672998941c4af00f Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Tue, 31 Jan 2023 23:05:32 +0100 Subject: [PATCH 69/79] Several codestyle fixes --- Tests/GithubObjectTest.php | 1 + Tests/GithubTest.php | 1 + Tests/Package/Activity/EventsTest.php | 1 + Tests/Package/Activity/FeedsTest.php | 1 + Tests/Package/Activity/NotificationsTest.php | 1 + Tests/Package/Activity/StarringTest.php | 1 + Tests/Package/Activity/WatchingTest.php | 1 + Tests/Package/ActivityTest.php | 1 + Tests/Package/AuthorizationsTest.php | 1 + Tests/Package/Data/BlobsTest.php | 1 + Tests/Package/Data/CommitsTest.php | 1 + Tests/Package/Data/RefsTest.php | 1 + Tests/Package/Data/TagsTest.php | 1 + Tests/Package/Data/TreesTest.php | 1 + Tests/Package/DataTest.php | 1 + Tests/Package/EmojisTest.php | 1 + Tests/Package/GistsTest.php | 1 + Tests/Package/GitignoreTest.php | 1 + Tests/Package/GraphqlTest.php | 1 + Tests/Package/Issues/AssigneesTest.php | 1 + Tests/Package/Issues/CommentsTest.php | 1 + Tests/Package/Issues/EventsTest.php | 1 + Tests/Package/Issues/LabelsTest.php | 1 + Tests/Package/Issues/MilestonesTest.php | 1 + Tests/Package/IssuesTest.php | 1 + Tests/Package/MarkdownTest.php | 1 + Tests/Package/MetaTest.php | 1 + Tests/Package/Orgs/HooksTest.php | 1 + Tests/Package/Orgs/MembersTest.php | 1 + Tests/Package/Orgs/TeamsTest.php | 1 + Tests/Package/OrgsTest.php | 1 + Tests/Package/Pulls/CommentsTest.php | 1 + Tests/Package/PullsTest.php | 1 + Tests/Package/Repositories/BranchesTest.php | 1 + Tests/Package/Repositories/CollaboratorsTest.php | 1 + Tests/Package/Repositories/CommentsTest.php | 1 + Tests/Package/Repositories/CommitsTest.php | 1 + Tests/Package/Repositories/ContentsTest.php | 1 + Tests/Package/Repositories/DeploymentsTest.php | 1 + Tests/Package/Repositories/DownloadsTest.php | 1 + Tests/Package/Repositories/ForksTest.php | 1 + Tests/Package/Repositories/HooksTest.php | 1 + Tests/Package/Repositories/KeysTest.php | 1 + Tests/Package/Repositories/MergingTest.php | 1 + src/AbstractGithubObject.php | 1 + src/AbstractPackage.php | 1 + src/Github.php | 1 + src/Package/Activity.php | 1 + src/Package/Activity/Events.php | 1 + src/Package/Activity/Feeds.php | 1 + src/Package/Activity/Notifications.php | 1 + src/Package/Activity/Starring.php | 1 + src/Package/Activity/Watching.php | 1 + src/Package/Authorization.php | 1 + src/Package/Data.php | 1 + src/Package/Data/Blobs.php | 1 + src/Package/Data/Commits.php | 1 + src/Package/Data/Refs.php | 1 + src/Package/Data/Tags.php | 1 + src/Package/Data/Trees.php | 1 + src/Package/Emojis.php | 1 + src/Package/Gists.php | 1 + src/Package/Gists/Comments.php | 1 + src/Package/Gitignore.php | 1 + src/Package/Graphql.php | 1 + src/Package/Issues.php | 1 + src/Package/Issues/Assignees.php | 1 + src/Package/Issues/Comments.php | 1 + src/Package/Issues/Events.php | 1 + src/Package/Issues/Labels.php | 1 + src/Package/Issues/Milestones.php | 1 + src/Package/Markdown.php | 1 + src/Package/Meta.php | 1 + src/Package/Orgs.php | 1 + src/Package/Orgs/Hooks.php | 1 + src/Package/Orgs/Members.php | 1 + src/Package/Orgs/Teams.php | 1 + src/Package/Pulls.php | 1 + src/Package/Pulls/Comments.php | 1 + src/Package/Repositories.php | 1 + src/Package/Repositories/Branches.php | 1 + src/Package/Repositories/Collaborators.php | 1 + src/Package/Repositories/Comments.php | 1 + src/Package/Repositories/Commits.php | 1 + src/Package/Repositories/Contents.php | 1 + src/Package/Repositories/Deployments.php | 1 + src/Package/Repositories/Downloads.php | 1 + src/Package/Repositories/Forks.php | 1 + src/Package/Repositories/Hooks.php | 1 + src/Package/Repositories/Keys.php | 1 + src/Package/Repositories/Merging.php | 1 + src/Package/Repositories/Pages.php | 1 + src/Package/Repositories/Releases.php | 1 + src/Package/Repositories/Statistics.php | 1 + src/Package/Repositories/Statuses.php | 3 ++- src/Package/Search.php | 1 + src/Package/Users.php | 1 + src/Package/Users/Emails.php | 1 + src/Package/Users/Followers.php | 1 + src/Package/Users/Keys.php | 1 + src/Package/Zen.php | 1 + 101 files changed, 102 insertions(+), 1 deletion(-) diff --git a/Tests/GithubObjectTest.php b/Tests/GithubObjectTest.php index 5ad836f4..43bf0795 100755 --- a/Tests/GithubObjectTest.php +++ b/Tests/GithubObjectTest.php @@ -1,4 +1,5 @@ Date: Tue, 31 Jan 2023 23:43:16 +0100 Subject: [PATCH 70/79] Add composer alias for 3.0-dev --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b98ce4ac..269a3875 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,8 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-2.0-dev": "2.0-dev" + "dev-2.0-dev": "2.0-dev", + "dev-3.x-dev": "3.0-dev" } } } From 45ca9469f074a6dc2b57077740a9c70869362f95 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Wed, 1 Feb 2023 00:07:25 +0100 Subject: [PATCH 71/79] Updating all Joomla dependencies to 3.x-dev --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 269a3875..43f80754 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,9 @@ "license": "GPL-2.0-or-later", "require": { "php": "~8.1.0", - "joomla/http": "^2.0", - "joomla/registry": "^2.0", - "joomla/uri": "^2.0" + "joomla/http": "3.0.x-dev", + "joomla/registry": "3.0.x-dev", + "joomla/uri": "3.0.x-dev" }, "require-dev": { "phpunit/phpunit": "^8.5|^9.0", From 08c62e4e878c3e1c92344a335e86710fae2d3a4f Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Wed, 1 Feb 2023 09:24:33 +0100 Subject: [PATCH 72/79] Raising minimum version of PHPUnit to 9.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 43f80754..49d4e666 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "joomla/uri": "3.0.x-dev" }, "require-dev": { - "phpunit/phpunit": "^8.5|^9.0", + "phpunit/phpunit": "^9.0", "squizlabs/php_codesniffer": "~3.7.1" }, "autoload": { From 886d6a07093d6d60a63baf9c4b45edaeb9d6db8e Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Thu, 2 Feb 2023 10:13:49 +0100 Subject: [PATCH 73/79] Updating .editorconfig to PSR12 --- .editorconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index c8bb3e7b..78a64203 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,8 @@ # Unix-style newlines with a newline ending every file [*] -indent_style = tab +indent_style = space +indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true From ba8d1d8c32465c3606b7d5cbb04e06c67ecf58da Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Thu, 2 Feb 2023 10:54:57 +0100 Subject: [PATCH 74/79] Raising requirements for PHPUnit to 9.5.28 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 49d4e666..2cae4572 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "joomla/uri": "3.0.x-dev" }, "require-dev": { - "phpunit/phpunit": "^9.0", + "phpunit/phpunit": "^9.5.28", "squizlabs/php_codesniffer": "~3.7.1" }, "autoload": { From 553b25b29f496fad2c7dcc040983d000ee9126da Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Sat, 4 Feb 2023 13:27:50 +0100 Subject: [PATCH 75/79] Adding stubs for documentation --- docs/index.md | 1 + docs/overview.md | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 docs/index.md create mode 100644 docs/overview.md diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 00000000..c87f1b49 --- /dev/null +++ b/docs/index.md @@ -0,0 +1 @@ +* [Overview](overview.md) diff --git a/docs/overview.md b/docs/overview.md new file mode 100644 index 00000000..cfd53634 --- /dev/null +++ b/docs/overview.md @@ -0,0 +1,3 @@ +# Github API package + +TODO From 3af205c4df4b93386bc0930f5b4d3737237214ef Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Wed, 22 Mar 2023 15:07:20 +0100 Subject: [PATCH 76/79] Updating dependencies, drone setup and adding phan setup (#58) --- .drone.jsonnet | 17 +- .drone.yml | 301 ++++++++------------- .phan/config.php | 349 +++++++++++++++++++++++++ composer.json | 6 +- src/AbstractGithubObject.php | 4 +- src/AbstractPackage.php | 4 +- src/Github.php | 6 +- src/Package/Activity/Notifications.php | 36 +-- src/Package/Data/Refs.php | 2 +- src/Package/Gists.php | 20 +- src/Package/Issues.php | 40 +-- src/Package/Issues/Comments.php | 22 +- src/Package/Repositories/Commits.php | 14 +- 13 files changed, 540 insertions(+), 281 deletions(-) create mode 100644 .phan/config.php diff --git a/.drone.jsonnet b/.drone.jsonnet index 1e236fb3..e13974c7 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -25,7 +25,7 @@ local composer(phpversion, params) = { local phpunit(phpversion) = { name: "PHPUnit", image: "joomlaprojects/docker-images:php" + phpversion, - [if phpversion == "8.2" then "failure"]: "ignore", + [if phpversion == "8.3" then "failure"]: "ignore", commands: ["vendor/bin/phpunit"] }; @@ -51,8 +51,7 @@ local pipeline(name, phpversion, params) = { volumes: volumes, commands: [ "php -v", - "composer update", - "composer require phpmd/phpmd phpstan/phpstan" + "composer update" ] }, { @@ -64,16 +63,12 @@ local pipeline(name, phpversion, params) = { ] }, { - name: "phpmd", - image: "joomlaprojects/docker-images:php8.1", + name: "phan", + image: "joomlaprojects/docker-images:php8.1-ast", depends: [ "composer" ], failure: "ignore", commands: [ - "vendor/bin/phpmd src text cleancode", - "vendor/bin/phpmd src text codesize", - "vendor/bin/phpmd src text controversial", - "vendor/bin/phpmd src text design", - "vendor/bin/phpmd src text unusedcode", + "vendor/bin/phan" ] }, { @@ -107,5 +102,5 @@ local pipeline(name, phpversion, params) = { }, pipeline("8.1 lowest", "8.1", "--prefer-stable --prefer-lowest"), pipeline("8.1", "8.1", "--prefer-stable"), - pipeline("8.2", "8.2", "--prefer-stable --ignore-platform-reqs"), + pipeline("8.2", "8.2", "--prefer-stable"), ] diff --git a/.drone.yml b/.drone.yml index 341d9d51..0b8d4d90 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,202 +1,115 @@ --- -{ - "kind": "pipeline", - "name": "Codequality", - "steps": [ - { - "commands": [ - "php -v", - "composer update", - "composer require phpmd/phpmd phpstan/phpstan" - ], - "image": "joomlaprojects/docker-images:php8.1", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpcs --standard=ruleset.xml src/" - ], - "depends": [ - "composer" - ], - "image": "joomlaprojects/docker-images:php8.1", - "name": "phpcs" - }, - { - "commands": [ - "vendor/bin/phpmd src text cleancode", - "vendor/bin/phpmd src text codesize", - "vendor/bin/phpmd src text controversial", - "vendor/bin/phpmd src text design", - "vendor/bin/phpmd src text unusedcode" - ], - "depends": [ - "composer" - ], - "failure": "ignore", - "image": "joomlaprojects/docker-images:php8.1", - "name": "phpmd" - }, - { - "commands": [ - "vendor/bin/phpstan analyse src" - ], - "depends": [ - "composer" - ], - "failure": "ignore", - "image": "joomlaprojects/docker-images:php8.1", - "name": "phpstan" - }, - { - "commands": [ - "phploc src" - ], - "depends": [ - "composer" - ], - "failure": "ignore", - "image": "joomlaprojects/docker-images:php8.1", - "name": "phploc" - }, - { - "commands": [ - "phpcpd src" - ], - "depends": [ - "composer" - ], - "failure": "ignore", - "image": "joomlaprojects/docker-images:php8.1", - "name": "phpcpd" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} +kind: pipeline +name: Codequality +steps: +- commands: + - php -v + - composer update + image: joomlaprojects/docker-images:php8.1 + name: composer + volumes: + - name: composer-cache + path: /tmp/composer-cache +- commands: + - vendor/bin/phpcs --standard=ruleset.xml src/ + depends: + - composer + image: joomlaprojects/docker-images:php8.1 + name: phpcs +- commands: + - vendor/bin/phan + depends: + - composer + failure: ignore + image: joomlaprojects/docker-images:php8.1-ast + name: phan +- commands: + - vendor/bin/phpstan analyse src + depends: + - composer + failure: ignore + image: joomlaprojects/docker-images:php8.1 + name: phpstan +- commands: + - phploc src + depends: + - composer + failure: ignore + image: joomlaprojects/docker-images:php8.1 + name: phploc +- commands: + - phpcpd src + depends: + - composer + failure: ignore + image: joomlaprojects/docker-images:php8.1 + name: phpcpd +volumes: +- host: + path: /tmp/composer-cache + name: composer-cache --- -{ - "kind": "pipeline", - "name": "PHP 8.1 lowest", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable --prefer-lowest" - ], - "image": "joomlaprojects/docker-images:php8.1", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php8.1", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} +kind: pipeline +name: PHP 8.1 lowest +steps: +- commands: + - php -v + - composer update --prefer-stable --prefer-lowest + image: joomlaprojects/docker-images:php8.1 + name: composer + volumes: + - name: composer-cache + path: /tmp/composer-cache +- commands: + - vendor/bin/phpunit + image: joomlaprojects/docker-images:php8.1 + name: PHPUnit +volumes: +- host: + path: /tmp/composer-cache + name: composer-cache --- -{ - "kind": "pipeline", - "name": "PHP 8.1", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable" - ], - "image": "joomlaprojects/docker-images:php8.1", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "image": "joomlaprojects/docker-images:php8.1", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} +kind: pipeline +name: PHP 8.1 +steps: +- commands: + - php -v + - composer update --prefer-stable + image: joomlaprojects/docker-images:php8.1 + name: composer + volumes: + - name: composer-cache + path: /tmp/composer-cache +- commands: + - vendor/bin/phpunit + image: joomlaprojects/docker-images:php8.1 + name: PHPUnit +volumes: +- host: + path: /tmp/composer-cache + name: composer-cache --- -{ - "kind": "pipeline", - "name": "PHP 8.2", - "steps": [ - { - "commands": [ - "php -v", - "composer update --prefer-stable --ignore-platform-reqs" - ], - "image": "joomlaprojects/docker-images:php8.2", - "name": "composer", - "volumes": [ - { - "name": "composer-cache", - "path": "/tmp/composer-cache" - } - ] - }, - { - "commands": [ - "vendor/bin/phpunit" - ], - "failure": "ignore", - "image": "joomlaprojects/docker-images:php8.2", - "name": "PHPUnit" - } - ], - "volumes": [ - { - "host": { - "path": "/tmp/composer-cache" - }, - "name": "composer-cache" - } - ] -} +kind: pipeline +name: PHP 8.2 +steps: +- commands: + - php -v + - composer update --prefer-stable + image: joomlaprojects/docker-images:php8.2 + name: composer + volumes: + - name: composer-cache + path: /tmp/composer-cache +- commands: + - vendor/bin/phpunit + image: joomlaprojects/docker-images:php8.2 + name: PHPUnit +volumes: +- host: + path: /tmp/composer-cache + name: composer-cache --- kind: signature -hmac: 76b430f45f715002fd687d4ae23425ab479d656bdc36645198e302b6052f070f +hmac: 5e5d25d380c8471aa6a55d802339463ba763c8b2337c8810984e93a0c2f6b6e4 ... diff --git a/.phan/config.php b/.phan/config.php new file mode 100644 index 00000000..7face806 --- /dev/null +++ b/.phan/config.php @@ -0,0 +1,349 @@ + '8.1', + + // If enabled, missing properties will be created when + // they are first seen. If false, we'll report an + // error message if there is an attempt to write + // to a class property that wasn't explicitly + // defined. + 'allow_missing_properties' => true, + + // If enabled, null can be cast to any type and any + // type can be cast to null. Setting this to true + // will cut down on false positives. + 'null_casts_as_any_type' => true, + + // If enabled, allow null to be cast as any array-like type. + // + // This is an incremental step in migrating away from `null_casts_as_any_type`. + // If `null_casts_as_any_type` is true, this has no effect. + 'null_casts_as_array' => true, + + // If enabled, allow any array-like type to be cast to null. + // This is an incremental step in migrating away from `null_casts_as_any_type`. + // If `null_casts_as_any_type` is true, this has no effect. + 'array_casts_as_null' => true, + + // If enabled, scalars (int, float, bool, string, null) + // are treated as if they can cast to each other. + // This does not affect checks of array keys. See `scalar_array_key_cast`. + 'scalar_implicit_cast' => true, + + // If enabled, any scalar array keys (int, string) + // are treated as if they can cast to each other. + // E.g. `array` can cast to `array` and vice versa. + // Normally, a scalar type such as int could only cast to/from int and mixed. + 'scalar_array_key_cast' => true, + + // If this has entries, scalars (int, float, bool, string, null) + // are allowed to perform the casts listed. + // + // E.g. `['int' => ['float', 'string'], 'float' => ['int'], 'string' => ['int'], 'null' => ['string']]` + // allows casting null to a string, but not vice versa. + // (subset of `scalar_implicit_cast`) + 'scalar_implicit_partial' => [], + + // If enabled, Phan will warn if **any** type in a method invocation's object + // is definitely not an object, + // or if **any** type in an invoked expression is not a callable. + // Setting this to true will introduce numerous false positives + // (and reveal some bugs). + 'strict_method_checking' => false, + + // If enabled, Phan will warn if **any** type of the object expression for a property access + // does not contain that property. + 'strict_object_checking' => false, + + // If enabled, Phan will warn if **any** type in the argument's union type + // cannot be cast to a type in the parameter's expected union type. + // Setting this to true will introduce numerous false positives + // (and reveal some bugs). + 'strict_param_checking' => false, + + // If enabled, Phan will warn if **any** type in a property assignment's union type + // cannot be cast to a type in the property's declared union type. + // Setting this to true will introduce numerous false positives + // (and reveal some bugs). + 'strict_property_checking' => false, + + // If enabled, Phan will warn if **any** type in a returned value's union type + // cannot be cast to the declared return type. + // Setting this to true will introduce numerous false positives + // (and reveal some bugs). + 'strict_return_checking' => false, + + // If true, seemingly undeclared variables in the global + // scope will be ignored. + // + // This is useful for projects with complicated cross-file + // globals that you have no hope of fixing. + 'ignore_undeclared_variables_in_global_scope' => true, + + // Set this to false to emit `PhanUndeclaredFunction` issues for internal functions that Phan has signatures for, + // but aren't available in the codebase, or from Reflection. + // (may lead to false positives if an extension isn't loaded) + // + // If this is true(default), then Phan will not warn. + // + // Even when this is false, Phan will still infer return values and check parameters of internal functions + // if Phan has the signatures. + 'ignore_undeclared_functions_with_known_signatures' => true, + + // Backwards Compatibility Checking. This is slow + // and expensive, but you should consider running + // it before upgrading your version of PHP to a + // new version that has backward compatibility + // breaks. + // + // If you are migrating from PHP 5 to PHP 7, + // you should also look into using + // [php7cc (no longer maintained)](https://github.com/sstalle/php7cc) + // and [php7mar](https://github.com/Alexia/php7mar), + // which have different backwards compatibility checks. + // + // If you are still using versions of php older than 5.6, + // `PHP53CompatibilityPlugin` may be worth looking into if you are not running + // syntax checks for php 5.3 through another method such as + // `InvokePHPNativeSyntaxCheckPlugin` (see .phan/plugins/README.md). + 'backward_compatibility_checks' => false, + + // If true, check to make sure the return type declared + // in the doc-block (if any) matches the return type + // declared in the method signature. + 'check_docblock_signature_return_type_match' => true, + + // This setting maps case-insensitive strings to union types. + // + // This is useful if a project uses phpdoc that differs from the phpdoc2 standard. + // + // If the corresponding value is the empty string, + // then Phan will ignore that union type (E.g. can ignore 'the' in `@return the value`) + // + // If the corresponding value is not empty, + // then Phan will act as though it saw the corresponding UnionTypes(s) + // when the keys show up in a UnionType of `@param`, `@return`, `@var`, `@property`, etc. + // + // This matches the **entire string**, not parts of the string. + // (E.g. `@return the|null` will still look for a class with the name `the`, but `@return the` will be ignored with the below setting) + // + // (These are not aliases, this setting is ignored outside of doc comments). + // (Phan does not check if classes with these names exist) + // + // Example setting: `['unknown' => '', 'number' => 'int|float', 'char' => 'string', 'long' => 'int', 'the' => '']` + 'phpdoc_type_mapping' => [], + + // Set to true in order to attempt to detect dead + // (unreferenced) code. Keep in mind that the + // results will only be a guess given that classes, + // properties, constants and methods can be referenced + // as variables (like `$class->$property` or + // `$class->$method()`) in ways that we're unable + // to make sense of. + // + // To more aggressively detect dead code, + // you may want to set `dead_code_detection_prefer_false_negative` to `false`. + 'dead_code_detection' => false, + + // Set to true in order to attempt to detect unused variables. + // `dead_code_detection` will also enable unused variable detection. + // + // This has a few known false positives, e.g. for loops or branches. + 'unused_variable_detection' => false, + + // Set to true in order to attempt to detect redundant and impossible conditions. + // + // This has some false positives involving loops, + // variables set in branches of loops, and global variables. + 'redundant_condition_detection' => false, + + // If enabled, Phan will act as though it's certain of real return types of a subset of internal functions, + // even if those return types aren't available in reflection (real types were taken from php 7.3 or 8.0-dev, depending on target_php_version). + // + // Note that with php 7 and earlier, php would return null or false for many internal functions if the argument types or counts were incorrect. + // As a result, enabling this setting with target_php_version 8.0 may result in false positives for `--redundant-condition-detection` when codebases also support php 7.x. + 'assume_real_types_for_internal_functions' => false, + + // If true, this runs a quick version of checks that takes less + // time at the cost of not running as thorough + // of an analysis. You should consider setting this + // to true only when you wish you had more **undiagnosed** issues + // to fix in your code base. + // + // In quick-mode the scanner doesn't rescan a function + // or a method's code block every time a call is seen. + // This means that the problem here won't be detected: + // + // ```php + // false, + + // Override to hardcode existence and types of (non-builtin) globals in the global scope. + // Class names should be prefixed with `\`. + // + // (E.g. `['_FOO' => '\FooClass', 'page' => '\PageClass', 'userId' => 'int']`) + 'globals_type_map' => [], + + // The minimum severity level to report on. This can be + // set to `Issue::SEVERITY_LOW`, `Issue::SEVERITY_NORMAL` or + // `Issue::SEVERITY_CRITICAL`. Setting it to only + // critical issues is a good place to start on a big + // sloppy mature code base. + 'minimum_severity' => Issue::SEVERITY_NORMAL, + + // Add any issue types (such as `'PhanUndeclaredMethod'`) + // to this list to inhibit them from being reported. + // 'PhanDeprecatedClass', 'PhanUndeclaredConstant','PhanDeprecatedFunction' + 'suppress_issue_types' => [], + + // A regular expression to match files to be excluded + // from parsing and analysis and will not be read at all. + // + // This is useful for excluding groups of test or example + // directories/files, unanalyzable files, or files that + // can't be removed for whatever reason. + // (e.g. `'@Test\.php$@'`, or `'@vendor/.*/(tests|Tests)/@'`) + 'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@', + + // A list of files that will be excluded from parsing and analysis + // and will not be read at all. + // + // This is useful for excluding hopelessly unanalyzable + // files that can't be removed for whatever reason. + 'exclude_file_list' => [ + ], + + // A directory list that defines files that will be excluded + // from static analysis, but whose class and method + // information should be included. + // + // Generally, you'll want to include the directories for + // third-party code (such as "vendor/") in this list. + // + // n.b.: If you'd like to parse but not analyze 3rd + // party code, directories containing that code + // should be added to the `directory_list` as well as + // to `exclude_analysis_directory_list`. + 'exclude_analysis_directory_list' => [ + 'vendor/' + ], + + // Enable this to enable checks of require/include statements referring to valid paths. + // The settings `include_paths` and `warn_about_relative_include_statement` affect the checks. + 'enable_include_path_checks' => false, + + // The number of processes to fork off during the analysis + // phase. + 'processes' => 1, + + // List of case-insensitive file extensions supported by Phan. + // (e.g. `['php', 'html', 'htm']`) + 'analyzed_file_extensions' => [ + 'php', + ], + + // You can put paths to stubs of internal extensions in this config option. + // If the corresponding extension is **not** loaded, then Phan will use the stubs instead. + // Phan will continue using its detailed type annotations, + // but load the constants, classes, functions, and classes (and their Reflection types) + // from these stub files (doubling as valid php files). + // Use a different extension from php to avoid accidentally loading these. + // The `tools/make_stubs` script can be used to generate your own stubs (compatible with php 7.0+ right now) + // + // (e.g. `['xdebug' => '.phan/internal_stubs/xdebug.phan_php']`) + 'autoload_internal_extension_signatures' => [ + ], + + // A list of plugin files to execute. + // + // Plugins which are bundled with Phan can be added here by providing their name (e.g. `'AlwaysReturnPlugin'`) + // + // Documentation about available bundled plugins can be found [here](https://github.com/phan/phan/tree/v4/.phan/plugins). + // + // Alternately, you can pass in the full path to a PHP file with the plugin's implementation (e.g. `'vendor/phan/phan/.phan/plugins/AlwaysReturnPlugin.php'`) + 'plugins' => [], + + // A list of directories that should be parsed for class and + // method information. After excluding the directories + // defined in `exclude_analysis_directory_list`, the remaining + // files will be statically analyzed for errors. + // + // Thus, both first-party and third-party code being used by + // your application should be included in this list. + 'directory_list' => [ + 'src', + 'vendor' + ], + + // A list of individual files to include in analysis + // with a path relative to the root directory of the + // project. + 'file_list' => [], +]; diff --git a/composer.json b/composer.json index 2cae4572..b21aa67b 100644 --- a/composer.json +++ b/composer.json @@ -6,14 +6,16 @@ "homepage": "https://github.com/joomla-framework/github-api", "license": "GPL-2.0-or-later", "require": { - "php": "~8.1.0", + "php": "^8.1.0", "joomla/http": "3.0.x-dev", "joomla/registry": "3.0.x-dev", "joomla/uri": "3.0.x-dev" }, "require-dev": { "phpunit/phpunit": "^9.5.28", - "squizlabs/php_codesniffer": "~3.7.1" + "squizlabs/php_codesniffer": "^3.7.2", + "phpstan/phpstan": "^1.10.7", + "phan/phan": "^5.4.2" }, "autoload": { "psr-4": { diff --git a/src/AbstractGithubObject.php b/src/AbstractGithubObject.php index 3c864e4a..b283fce4 100644 --- a/src/AbstractGithubObject.php +++ b/src/AbstractGithubObject.php @@ -83,8 +83,8 @@ abstract class AbstractGithubObject /** * Constructor. * - * @param Registry $options GitHub options object. - * @param BaseHttp $client The HTTP client object. + * @param ?Registry $options GitHub options object. + * @param ?BaseHttp $client The HTTP client object. * * @since 1.0 */ diff --git a/src/AbstractPackage.php b/src/AbstractPackage.php index 4e6b2568..71266b7c 100644 --- a/src/AbstractPackage.php +++ b/src/AbstractPackage.php @@ -22,8 +22,8 @@ abstract class AbstractPackage extends AbstractGithubObject /** * Constructor. * - * @param Registry $options GitHub options object. - * @param Http $client The HTTP client object. + * @param ?Registry $options GitHub options object. + * @param ?Http $client The HTTP client object. * * @since 1.0 */ diff --git a/src/Github.php b/src/Github.php index a6f1c477..632c54e4 100644 --- a/src/Github.php +++ b/src/Github.php @@ -40,7 +40,7 @@ class Github /** * Options for the GitHub object. * - * @var array + * @var Registry * @since 1.0 */ protected $options; @@ -56,8 +56,8 @@ class Github /** * Constructor. * - * @param Registry $options GitHub options object. - * @param Http $client The HTTP client object. + * @param ?Registry $options GitHub options object. + * @param ?Http $client The HTTP client object. * * @since 1.0 */ diff --git a/src/Package/Activity/Notifications.php b/src/Package/Activity/Notifications.php index 333af07c..7b228b2f 100644 --- a/src/Package/Activity/Notifications.php +++ b/src/Package/Activity/Notifications.php @@ -25,10 +25,10 @@ class Notifications extends AbstractPackage * * List all notifications for the current user, grouped by repository. * - * @param boolean $all True to show notifications marked as read. - * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. - * @param \DateTimeInterface $since Only show notifications updated after the given time. - * @param \DateTimeInterface $before Only show notifications updated before the given time. + * @param boolean $all True to show notifications marked as read. + * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. + * @param ?\DateTimeInterface $since Only show notifications updated after the given time. + * @param ?\DateTimeInterface $before Only show notifications updated before the given time. * * @return object * @@ -65,12 +65,12 @@ public function getList($all = true, $participating = true, \DateTimeInterface $ * * List all notifications for the current user. * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param boolean $all True to show notifications marked as read. - * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. - * @param \DateTimeInterface $since Only show notifications updated after the given time. - * @param \DateTimeInterface $before Only show notifications updated before the given time. + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param boolean $all True to show notifications marked as read. + * @param boolean $participating True to show only notifications in which the user is directly participating or mentioned. + * @param ?\DateTimeInterface $since Only show notifications updated after the given time. + * @param ?\DateTimeInterface $before Only show notifications updated before the given time. * * @return object * @@ -113,9 +113,9 @@ public function getListRepository( * * Marking a notification as “read” removes it from the default view on GitHub.com. * - * @param boolean $unread Changes the unread status of the threads. - * @param boolean $read Inverse of “unread”. - * @param \DateTimeInterface $lastReadAt Describes the last point that notifications were checked. + * @param boolean $unread Changes the unread status of the threads. + * @param boolean $read Inverse of “unread”. + * @param ?\DateTimeInterface $lastReadAt Describes the last point that notifications were checked. * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. * * @return object @@ -147,11 +147,11 @@ public function markRead($unread = true, $read = true, \DateTimeInterface $lastR * * Marking all notifications in a repository as “read” removes them from the default view on GitHub.com. * - * @param string $owner Repository owner. - * @param string $repo Repository name. - * @param boolean $unread Changes the unread status of the threads. - * @param boolean $read Inverse of “unread”. - * @param \DateTimeInterface $lastReadAt Describes the last point that notifications were checked. + * @param string $owner Repository owner. + * @param string $repo Repository name. + * @param boolean $unread Changes the unread status of the threads. + * @param boolean $read Inverse of “unread”. + * @param ?\DateTimeInterface $lastReadAt Describes the last point that notifications were checked. * Anything updated since this time will not be updated. Default: Now. Expected in ISO 8601 format. * * @return object diff --git a/src/Package/Data/Refs.php b/src/Package/Data/Refs.php index c98fa143..02111536 100644 --- a/src/Package/Data/Refs.php +++ b/src/Package/Data/Refs.php @@ -110,7 +110,7 @@ public function create($user, $repo, $ref, $sha) * @return object * * @since 1.0 - * @throws DomainException + * @throws \DomainException */ public function edit($user, $repo, $ref, $sha, $force = false) { diff --git a/src/Package/Gists.php b/src/Package/Gists.php index 371b5671..6b4473ba 100644 --- a/src/Package/Gists.php +++ b/src/Package/Gists.php @@ -221,10 +221,10 @@ public function getList($page = 0, $limit = 0) /** * List a user’s gists. * - * @param string $user The name of the GitHub user from which to list gists. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * @param \DateTime $since Only gists updated at or after this time are returned. + * @param string $user The name of the GitHub user from which to list gists. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * @param ?\DateTime $since Only gists updated at or after this time are returned. * * @return array * @@ -247,9 +247,9 @@ public function getListByUser($user, $page = 0, $limit = 0, \DateTime $since = n /** * List all public gists. * - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * @param \DateTime $since Only gists updated at or after this time are returned. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * @param ?\DateTime $since Only gists updated at or after this time are returned. * * @return array * @@ -272,9 +272,9 @@ public function getListPublic($page = 0, $limit = 0, \DateTime $since = null) /** * List starred gists. * - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * @param \DateTime $since Only gists updated at or after this time are returned. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * @param ?\DateTime $since Only gists updated at or after this time are returned. * * @return array * diff --git a/src/Package/Issues.php b/src/Package/Issues.php index 3e7caf96..a82d2235 100644 --- a/src/Package/Issues.php +++ b/src/Package/Issues.php @@ -170,14 +170,14 @@ public function get($user, $repo, $issueId) /** * List issues. * - * @param string $filter The filter type: assigned, created, mentioned, subscribed. - * @param string $state The optional state to filter requests by. [open, closed] - * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. - * @param string $sort The sort order: created, updated, comments, default: created. - * @param string $direction The list direction: asc or desc, default: desc. - * @param \DateTimeInterface $since Only issues updated at or after this time are returned. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. + * @param string $filter The filter type: assigned, created, mentioned, subscribed. + * @param string $state The optional state to filter requests by. [open, closed] + * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. + * @param string $sort The sort order: created, updated, comments, default: created. + * @param string $direction The list direction: asc or desc, default: desc. + * @param ?\DateTimeInterface $since Only issues updated at or after this time are returned. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. * * @return object * @@ -228,18 +228,18 @@ public function getList( /** * List issues for a repository. * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $milestone The milestone number, 'none', or *. - * @param string $state The optional state to filter requests by. [open, closed] - * @param string $assignee The assignee name, 'none', or *. - * @param string $mentioned The GitHub user name. - * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. - * @param string $sort The sort order: created, updated, comments, default: created. - * @param string $direction The list direction: asc or desc, default: desc. - * @param \DateTimeInterface $since Only issues updated at or after this time are returned. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $milestone The milestone number, 'none', or *. + * @param string $state The optional state to filter requests by. [open, closed] + * @param string $assignee The assignee name, 'none', or *. + * @param string $mentioned The GitHub user name. + * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. + * @param string $sort The sort order: created, updated, comments, default: created. + * @param string $direction The list direction: asc or desc, default: desc. + * @param ?\DateTimeInterface $since Only issues updated at or after this time are returned. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. * * @return object * diff --git a/src/Package/Issues/Comments.php b/src/Package/Issues/Comments.php index 8edb9248..81ed9f8c 100644 --- a/src/Package/Issues/Comments.php +++ b/src/Package/Issues/Comments.php @@ -26,12 +26,12 @@ class Comments extends AbstractPackage /** * List comments on an issue. * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param integer $issueId The issue number. - * @param integer $page The page number from which to get items. - * @param integer $limit The number of items on a page. - * @param \DateTimeInterface $since Only comments updated at or after this time are returned. + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param integer $issueId The issue number. + * @param integer $page The page number from which to get items. + * @param integer $limit The number of items on a page. + * @param ?\DateTimeInterface $since Only comments updated at or after this time are returned. * * @return object * @@ -56,11 +56,11 @@ public function getList($owner, $repo, $issueId, $page = 0, $limit = 0, \DateTim /** * List comments in a repository. * - * @param string $owner The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sort The sort field - created or updated. - * @param string $direction The sort order- asc or desc. Ignored without sort parameter. - * @param \DateTimeInterface $since Only comments updated at or after this time are returned. + * @param string $owner The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sort The sort field - created or updated. + * @param string $direction The sort order- asc or desc. Ignored without sort parameter. + * @param ?\DateTimeInterface $since Only comments updated at or after this time are returned. * * @return object * diff --git a/src/Package/Repositories/Commits.php b/src/Package/Repositories/Commits.php index a552a13e..2e1dc50d 100644 --- a/src/Package/Repositories/Commits.php +++ b/src/Package/Repositories/Commits.php @@ -29,13 +29,13 @@ class Commits extends AbstractPackage * Please follow the link headers as outlined in the pagination overview instead of constructing * page links yourself. * - * @param string $user The name of the owner of the GitHub repository. - * @param string $repo The name of the GitHub repository. - * @param string $sha Sha or branch to start listing commits from. - * @param string $path Only commits containing this file path will be returned. - * @param string $author GitHub login, name, or email by which to filter by commit author. - * @param \DateTimeInterface $since ISO 8601 Date - Only commits after this date will be returned. - * @param \DateTimeInterface $until ISO 8601 Date - Only commits before this date will be returned. + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $sha Sha or branch to start listing commits from. + * @param string $path Only commits containing this file path will be returned. + * @param string $author GitHub login, name, or email by which to filter by commit author. + * @param ?\DateTimeInterface $since ISO 8601 Date - Only commits after this date will be returned. + * @param ?\DateTimeInterface $until ISO 8601 Date - Only commits before this date will be returned. * * @return object * From abf40885dbd214310510bd77df2842bd9daf64ec Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Mon, 5 Jun 2023 22:00:07 +0200 Subject: [PATCH 77/79] Remove broken codestyle rule --- ruleset.xml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ruleset.xml b/ruleset.xml index 07be5d2b..0bb9e5b0 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -19,10 +19,4 @@ - - - - - -
From 01e24ca4da896de49b8b15205dd6327a40697614 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Sat, 7 Oct 2023 23:17:58 +0200 Subject: [PATCH 78/79] Setting dependencies to version 3 of the Joomla framework --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index b21aa67b..21c9d6ea 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,9 @@ "license": "GPL-2.0-or-later", "require": { "php": "^8.1.0", - "joomla/http": "3.0.x-dev", - "joomla/registry": "3.0.x-dev", - "joomla/uri": "3.0.x-dev" + "joomla/http": "^3.0", + "joomla/registry": "^3.0", + "joomla/uri": "^3.0" }, "require-dev": { "phpunit/phpunit": "^9.5.28", From 68aee6068786350e6ea56f40df757ecc85a53aa3 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Mon, 2 Jun 2025 11:27:56 +0200 Subject: [PATCH 79/79] Remove specific .github files --- .github/CONTRIBUTING.md | 3 --- .github/FUNDING.yml | 2 -- .github/ISSUE_TEMPLATE.md | 14 -------------- .github/PULL_REQUEST_TEMPLATE.md | 7 ------- 4 files changed, 26 deletions(-) delete mode 100644 .github/CONTRIBUTING.md delete mode 100644 .github/FUNDING.yml delete mode 100644 .github/ISSUE_TEMPLATE.md delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md deleted file mode 100644 index 368ba80a..00000000 --- a/.github/CONTRIBUTING.md +++ /dev/null @@ -1,3 +0,0 @@ -# Contributing to the Joomla! Framework - -Please review [http://framework.joomla.org/contribute](http://framework.joomla.org/contribute) for information on how to contribute to the Framework's development. diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 1914e099..00000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1,2 +0,0 @@ -github: joomla -custom: https://community.joomla.org/sponsorship-campaigns.html diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index c275880f..00000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,14 +0,0 @@ -### Steps to reproduce the issue - - -### Expected result - - -### Actual result - - -### System information (as much as possible) - - -### Additional comments - diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index f457c25f..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ -Pull Request for Issue # - -### Summary of Changes - -### Testing Instructions - -### Documentation Changes Required pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy