From fb54d8a8e85520eaa6d1997edbf6441e83b6dfdd Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 12:08:32 +0000 Subject: [PATCH 01/11] added starring api --- lib/Github/Api/CurrentUser.php | 11 ++--- lib/Github/Api/CurrentUser/Starred.php | 65 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 lib/Github/Api/CurrentUser/Starred.php diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 38318959589..1ae2f013845 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -7,6 +7,7 @@ use Github\Api\CurrentUser\Followers; use Github\Api\CurrentUser\Notifications; use Github\Api\CurrentUser\Watchers; +use Github\Api\CurrentUser\Starred; /** * @link http://developer.github.com/v3/users/ @@ -119,13 +120,11 @@ public function watched($page = 1) )); } - /** - * @link http://developer.github.com/changes/2012-9-5-watcher-api/ + /** + * @return Starred */ - public function starred($page = 1) + public function starred() { - return $this->get('user/starred', array( - 'page' => $page - )); + return new Starred($this->client); } } diff --git a/lib/Github/Api/CurrentUser/Starred.php b/lib/Github/Api/CurrentUser/Starred.php new file mode 100644 index 00000000000..54d1bb949ca --- /dev/null +++ b/lib/Github/Api/CurrentUser/Starred.php @@ -0,0 +1,65 @@ + + */ +class Starred extends AbstractApi +{ + /** + * List repositories starred by the authenticated user + * @link https://developer.github.com/v3/activity/starring/ + * + * @param integer $page + * @return array + */ + public function all($page = 1) + { + return $this->get('user/starred', array( + 'page' => $page + )); + } + + /** + * Check that the authenticated user starres a repository + * @link https://developer.github.com/v3/activity/starring/ + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function check($username, $repository) + { + return $this->get('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } + + /** + * Make the authenticated user star a repository + * @link https://developer.github.com/v3/activity/starring/ + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function star($username, $repository) + { + return $this->put('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } + + /** + * Make the authenticated user unstar a repository + * @link https://developer.github.com/v3/activity/starring + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function unstar($username, $repository) + { + return $this->delete('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } +} From 784a087090eae6ff957da53b50afe507789a37c2 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 09:11:26 -0300 Subject: [PATCH 02/11] updated documentation --- doc/users.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/doc/users.md b/doc/users.md index b8a8e09949e..b39da069c83 100644 --- a/doc/users.md +++ b/doc/users.md @@ -113,6 +113,16 @@ Returns an array of followed users. $users = $client->api('user')->watched('ornicar'); ``` +For authenticated user use. + +> Requires [authentication](security.md). + +```php +$users = $client->api('current_user')->watched(); +``` + +Returns an array of watched repos. + ### Get repos that a specific user has starred ```php @@ -124,10 +134,10 @@ For authenticated user use. > Requires [authentication](security.md). ```php -$users = $client->api('current_user')->watched(); +$users = $client->api('current_user')->starred()->all(); ``` -Returns an array of watched repos. +Returns an array of starred repos. ### Get the authenticated user emails From 3bf25e84cbe75f6e65b4f28610b367a03fcc61b4 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 12:28:25 +0000 Subject: [PATCH 03/11] added tests for Starred API --- .../Tests/Api/CurrentUser/StarredTest.php | 74 +++++++++++++++++++ test/Github/Tests/Api/CurrentUserTest.php | 10 +++ 2 files changed, 84 insertions(+) create mode 100644 test/Github/Tests/Api/CurrentUser/StarredTest.php diff --git a/test/Github/Tests/Api/CurrentUser/StarredTest.php b/test/Github/Tests/Api/CurrentUser/StarredTest.php new file mode 100644 index 00000000000..9a4af991559 --- /dev/null +++ b/test/Github/Tests/Api/CurrentUser/StarredTest.php @@ -0,0 +1,74 @@ + 'l3l0/test'), + array('name' => 'cordoval/test') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/starred') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all()); + } + + /** + * @test + */ + public function shouldCheckStar() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->check('l3l0', 'test')); + } + + /** + * @test + */ + public function shouldStarUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->star('l3l0', 'test')); + } + + /** + * @test + */ + public function shouldUnstarUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->unstar('l3l0', 'test')); + } + + protected function getApiClass() + { + return 'Github\Api\CurrentUser\Starred'; + } +} diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index 36316f3c02e..2ef0b920e68 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -133,6 +133,16 @@ public function shouldGetWatchersApiObject() $this->assertInstanceOf('Github\Api\CurrentUser\Watchers', $api->watchers()); } + + /** + * @test + */ + public function shouldGetStarredApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\CurrentUser\Starred', $api->starred()); + } protected function getApiClass() { From 59bdcf7b4c96a1538c1102b829768464e9514ae1 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 15:01:35 +0000 Subject: [PATCH 04/11] improved documentation --- doc/activity.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ doc/index.md | 1 + doc/users.md | 2 ++ 3 files changed, 54 insertions(+) create mode 100644 doc/activity.md diff --git a/doc/activity.md b/doc/activity.md new file mode 100644 index 00000000000..7726509135b --- /dev/null +++ b/doc/activity.md @@ -0,0 +1,51 @@ +## Activity API (incomplete) +[Back to the navigation](index.md) + +Access to Starring and Watching a Repository for authenticated users. +Wrap [GitHub Activity API](https://developer.github.com/v3/activity/). + +> No authentication required. + +### Get repos that a specific user has starred + +```php +$users = $client->api('user')->starred('ornicar'); +``` + +Returns an array of starred repos. + +> Requires [authentication](security.md). + +### Get repos that a authenticated user has starred + +```php +$activity = $client->api('current_user')->starred()->all(); +``` +Returns an array of starred repos. + +### Check if authenticated user has starred a specific repo + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->starred()->check($owner, $repo); +``` +Throws an Exception with code 404 in case that the repo is not starred by the authenticated user or NULL in case that it is starred by the authenticated user. + +### Star a specific repo for authenticated user + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->starred()->star($owner, $repo); +``` +Throws an Exception in case of failure or NULL in case of success. + +### Unstar a specific repo for authenticated user + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->starred()->unstar($owner, $repo); +``` +Throws an Exception in case of failure or NULL in case of success. \ No newline at end of file diff --git a/doc/index.md b/doc/index.md index e278e2c931b..176e5a2b51d 100644 --- a/doc/index.md +++ b/doc/index.md @@ -20,6 +20,7 @@ APIs: * [Assets](repo/assets.md) * [Users](users.md) * [Meta](meta.md) +* [Activity](activity.md) Additional features: diff --git a/doc/users.md b/doc/users.md index b39da069c83..c3e1e85dd8b 100644 --- a/doc/users.md +++ b/doc/users.md @@ -108,6 +108,7 @@ $client->api('current_user')->follow()->unfollow('symfony'); Returns an array of followed users. ### Get repos that a specific user is watching +> See [more](activity.md). ```php $users = $client->api('user')->watched('ornicar'); @@ -124,6 +125,7 @@ $users = $client->api('current_user')->watched(); Returns an array of watched repos. ### Get repos that a specific user has starred +> See [more](activity.md). ```php $users = $client->api('user')->starred('ornicar'); From af276bc115d7bad93acfe01295201d8e5c5ab0ce Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 16:09:06 +0000 Subject: [PATCH 05/11] changed documentation and watch repo api endpoint --- doc/activity.md | 49 +++++++++++++++++++++++-- lib/Github/Api/CurrentUser/Watchers.php | 8 ++-- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/doc/activity.md b/doc/activity.md index 7726509135b..ab1b338ce58 100644 --- a/doc/activity.md +++ b/doc/activity.md @@ -1,10 +1,10 @@ ## Activity API (incomplete) [Back to the navigation](index.md) -Access to Starring and Watching a Repository for authenticated users. +Access to Starring and Watching a Repository for [non] authenticated users. Wrap [GitHub Activity API](https://developer.github.com/v3/activity/). -> No authentication required. +> *** No authentication required. *** ### Get repos that a specific user has starred @@ -14,7 +14,15 @@ $users = $client->api('user')->starred('ornicar'); Returns an array of starred repos. -> Requires [authentication](security.md). +### Get repos that a specific user is watching + +```php +$users = $client->api('user')->watched('ornicar'); +``` + +Returns an array of watched repos. + +> *** Requires [authentication](security.md). *** ### Get repos that a authenticated user has starred @@ -48,4 +56,39 @@ $owner = "KnpLabs"; $repo = "php-github-api"; $activity = $client->api('current_user')->starred()->unstar($owner, $repo); ``` +Throws an Exception in case of failure or NULL in case of success. + + +### Get repos that a authenticated user is watching + +```php +$activity = $client->api('current_user')->watchers()->all(); +``` +Returns an array of watched repos. + +### Check if authenticated user is watching a specific repo + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->watchers()->check($owner, $repo); +``` +Throws an Exception with code 404 in case that the repo is not beeing watched by the authenticated user or NULL in case that it is beeing watched by the authenticated user. + +### Watch a specific repo for authenticated user + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->watchers()->watch($owner, $repo); +``` +Throws an Exception in case of failure or NULL in case of success. + +### Stop watching a specific repo for authenticated user + +```php +$owner = "KnpLabs"; +$repo = "php-github-api"; +$activity = $client->api('current_user')->watchers()->unwatch($owner, $repo); +``` Throws an Exception in case of failure or NULL in case of success. \ No newline at end of file diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index 398ac58536a..07d6e51e0ac 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -19,7 +19,7 @@ class Watchers extends AbstractApi */ public function all($page = 1) { - return $this->get('user/watched', array( + return $this->get('user/subscriptions', array( 'page' => $page )); } @@ -34,7 +34,7 @@ public function all($page = 1) */ public function check($username, $repository) { - return $this->get('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->get('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -47,7 +47,7 @@ public function check($username, $repository) */ public function watch($username, $repository) { - return $this->put('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->put('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); } /** @@ -60,6 +60,6 @@ public function watch($username, $repository) */ public function unwatch($username, $repository) { - return $this->delete('user/watched/'.rawurlencode($username).'/'.rawurlencode($repository)); + return $this->delete('user/subscriptions/'.rawurlencode($username).'/'.rawurlencode($repository)); } } From ab0752a275cbc79315bb0060fb331e4ae4715e52 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 16:18:35 +0000 Subject: [PATCH 06/11] changed current_user watch repo method --- doc/users.md | 2 +- lib/Github/Api/CurrentUser.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/users.md b/doc/users.md index c3e1e85dd8b..d90290a727f 100644 --- a/doc/users.md +++ b/doc/users.md @@ -119,7 +119,7 @@ For authenticated user use. > Requires [authentication](security.md). ```php -$users = $client->api('current_user')->watched(); +$users = $client->api('current_user')->watchers()->all(); ``` Returns an array of watched repos. diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 1ae2f013845..6856d9c1ba0 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -112,7 +112,10 @@ public function watchers() { return new Watchers($this->client); } - + + /** + * @Deprecated + */ public function watched($page = 1) { return $this->get('user/watched', array( From 2ed99b2133a6bd4896ba34dd7988e6c73aa5257a Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 16:30:17 +0000 Subject: [PATCH 07/11] revised comments --- lib/Github/Api/CurrentUser.php | 1 + lib/Github/Api/CurrentUser/Watchers.php | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index 6856d9c1ba0..d4e64348001 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -12,6 +12,7 @@ /** * @link http://developer.github.com/v3/users/ * @author Joseph Bielawski + * @revised Felipe Valtl de Mello */ class CurrentUser extends AbstractApi { diff --git a/lib/Github/Api/CurrentUser/Watchers.php b/lib/Github/Api/CurrentUser/Watchers.php index 07d6e51e0ac..035b78f568e 100644 --- a/lib/Github/Api/CurrentUser/Watchers.php +++ b/lib/Github/Api/CurrentUser/Watchers.php @@ -5,14 +5,15 @@ use Github\Api\AbstractApi; /** - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * @author Joseph Bielawski + * @revised Felipe Valtl de Mello */ class Watchers extends AbstractApi { /** * List repositories watched by the authenticated user - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * * @param integer $page * @return array @@ -26,7 +27,7 @@ public function all($page = 1) /** * Check that the authenticated user watches a repository - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * * @param string $username the user who owns the repo * @param string $repository the name of the repo @@ -39,7 +40,7 @@ public function check($username, $repository) /** * Make the authenticated user watch a repository - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * * @param string $username the user who owns the repo * @param string $repository the name of the repo @@ -52,7 +53,7 @@ public function watch($username, $repository) /** * Make the authenticated user unwatch a repository - * @link http://developer.github.com/v3/repos/watching/ + * @link https://developer.github.com/v3/activity/watching/ * * @param string $username the user who owns the repo * @param string $repository the name of the repo From 3fdd77138da446e0a1a5638aa0295bf4b76f947b Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 16:47:04 +0000 Subject: [PATCH 08/11] corrected watchers test --- test/Github/Tests/Api/CurrentUser/WatchersTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Github/Tests/Api/CurrentUser/WatchersTest.php b/test/Github/Tests/Api/CurrentUser/WatchersTest.php index 15e009f6a08..e2234ed7efb 100644 --- a/test/Github/Tests/Api/CurrentUser/WatchersTest.php +++ b/test/Github/Tests/Api/CurrentUser/WatchersTest.php @@ -19,7 +19,7 @@ public function shouldGetWatchers() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/watched') + ->with('user/subscriptions') ->will($this->returnValue($expectedValue)); $this->assertEquals($expectedValue, $api->all()); @@ -33,7 +33,7 @@ public function shouldCheckWatcher() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('user/watched/l3l0/test') + ->with('user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->check('l3l0', 'test')); @@ -47,7 +47,7 @@ public function shouldWatchUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('put') - ->with('user/watched/l3l0/test') + ->with('user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->watch('l3l0', 'test')); @@ -61,7 +61,7 @@ public function shouldUnwatchUser() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('user/watched/l3l0/test') + ->with('user/subscriptions/l3l0/test') ->will($this->returnValue(null)); $this->assertNull($api->unwatch('l3l0', 'test')); From 3eec9e7540206aee6132c3c3383f5c4b42d12694 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 17 Sep 2014 17:20:02 +0000 Subject: [PATCH 09/11] fix current version break --- doc/activity.md | 8 +- doc/users.md | 2 +- lib/Github/Api/CurrentUser.php | 18 ++++- lib/Github/Api/CurrentUser/Starring.php | 65 ++++++++++++++++ .../Tests/Api/CurrentUser/StarringTest.php | 74 +++++++++++++++++++ test/Github/Tests/Api/CurrentUserTest.php | 2 +- 6 files changed, 159 insertions(+), 10 deletions(-) create mode 100644 lib/Github/Api/CurrentUser/Starring.php create mode 100644 test/Github/Tests/Api/CurrentUser/StarringTest.php diff --git a/doc/activity.md b/doc/activity.md index ab1b338ce58..ca8c74bf3a1 100644 --- a/doc/activity.md +++ b/doc/activity.md @@ -27,7 +27,7 @@ Returns an array of watched repos. ### Get repos that a authenticated user has starred ```php -$activity = $client->api('current_user')->starred()->all(); +$activity = $client->api('current_user')->starring()->all(); ``` Returns an array of starred repos. @@ -36,7 +36,7 @@ Returns an array of starred repos. ```php $owner = "KnpLabs"; $repo = "php-github-api"; -$activity = $client->api('current_user')->starred()->check($owner, $repo); +$activity = $client->api('current_user')->starring()->check($owner, $repo); ``` Throws an Exception with code 404 in case that the repo is not starred by the authenticated user or NULL in case that it is starred by the authenticated user. @@ -45,7 +45,7 @@ Throws an Exception with code 404 in case that the repo is not starred by the au ```php $owner = "KnpLabs"; $repo = "php-github-api"; -$activity = $client->api('current_user')->starred()->star($owner, $repo); +$activity = $client->api('current_user')->starring()->star($owner, $repo); ``` Throws an Exception in case of failure or NULL in case of success. @@ -54,7 +54,7 @@ Throws an Exception in case of failure or NULL in case of success. ```php $owner = "KnpLabs"; $repo = "php-github-api"; -$activity = $client->api('current_user')->starred()->unstar($owner, $repo); +$activity = $client->api('current_user')->starring()->unstar($owner, $repo); ``` Throws an Exception in case of failure or NULL in case of success. diff --git a/doc/users.md b/doc/users.md index d90290a727f..810226af55b 100644 --- a/doc/users.md +++ b/doc/users.md @@ -136,7 +136,7 @@ For authenticated user use. > Requires [authentication](security.md). ```php -$users = $client->api('current_user')->starred()->all(); +$users = $client->api('current_user')->starring()->all(); ``` Returns an array of starred repos. diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index d4e64348001..d69185c320c 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -7,7 +7,7 @@ use Github\Api\CurrentUser\Followers; use Github\Api\CurrentUser\Notifications; use Github\Api\CurrentUser\Watchers; -use Github\Api\CurrentUser\Starred; +use Github\Api\CurrentUser\Starring; /** * @link http://developer.github.com/v3/users/ @@ -123,12 +123,22 @@ public function watched($page = 1) 'page' => $page )); } + + /** + * @return Starring + */ + public function starring() + { + return new Starring($this->client); + } /** - * @return Starred + * @Deprecated */ - public function starred() + public function starred($page = 1) { - return new Starred($this->client); + return $this->get('user/starred', array( + 'page' => $page + )); } } diff --git a/lib/Github/Api/CurrentUser/Starring.php b/lib/Github/Api/CurrentUser/Starring.php new file mode 100644 index 00000000000..97e0b017c9b --- /dev/null +++ b/lib/Github/Api/CurrentUser/Starring.php @@ -0,0 +1,65 @@ + + */ +class Starring extends AbstractApi +{ + /** + * List repositories starred by the authenticated user + * @link https://developer.github.com/v3/activity/starring/ + * + * @param integer $page + * @return array + */ + public function all($page = 1) + { + return $this->get('user/starred', array( + 'page' => $page + )); + } + + /** + * Check that the authenticated user starres a repository + * @link https://developer.github.com/v3/activity/starring/ + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function check($username, $repository) + { + return $this->get('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } + + /** + * Make the authenticated user star a repository + * @link https://developer.github.com/v3/activity/starring/ + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function star($username, $repository) + { + return $this->put('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } + + /** + * Make the authenticated user unstar a repository + * @link https://developer.github.com/v3/activity/starring + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @return array + */ + public function unstar($username, $repository) + { + return $this->delete('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); + } +} diff --git a/test/Github/Tests/Api/CurrentUser/StarringTest.php b/test/Github/Tests/Api/CurrentUser/StarringTest.php new file mode 100644 index 00000000000..c2cba90cfb1 --- /dev/null +++ b/test/Github/Tests/Api/CurrentUser/StarringTest.php @@ -0,0 +1,74 @@ + 'l3l0/test'), + array('name' => 'cordoval/test') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/starred') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all()); + } + + /** + * @test + */ + public function shouldCheckStar() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->check('l3l0', 'test')); + } + + /** + * @test + */ + public function shouldStarUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->star('l3l0', 'test')); + } + + /** + * @test + */ + public function shouldUnstarUser() + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('user/starred/l3l0/test') + ->will($this->returnValue(null)); + + $this->assertNull($api->unstar('l3l0', 'test')); + } + + protected function getApiClass() + { + return 'Github\Api\CurrentUser\Starring'; + } +} diff --git a/test/Github/Tests/Api/CurrentUserTest.php b/test/Github/Tests/Api/CurrentUserTest.php index 2ef0b920e68..902b53957b8 100644 --- a/test/Github/Tests/Api/CurrentUserTest.php +++ b/test/Github/Tests/Api/CurrentUserTest.php @@ -141,7 +141,7 @@ public function shouldGetStarredApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\CurrentUser\Starred', $api->starred()); + $this->assertInstanceOf('Github\Api\CurrentUser\Starring', $api->starring()); } protected function getApiClass() From 65894c482748e2d2750686700a659508b76e512f Mon Sep 17 00:00:00 2001 From: Felipe Date: Thu, 18 Sep 2014 10:48:01 +0000 Subject: [PATCH 10/11] removed unused class and changed docblock --- lib/Github/Api/CurrentUser.php | 4 +- lib/Github/Api/CurrentUser/Starred.php | 65 -------------------------- 2 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 lib/Github/Api/CurrentUser/Starred.php diff --git a/lib/Github/Api/CurrentUser.php b/lib/Github/Api/CurrentUser.php index d69185c320c..6f920668ad7 100644 --- a/lib/Github/Api/CurrentUser.php +++ b/lib/Github/Api/CurrentUser.php @@ -115,7 +115,7 @@ public function watchers() } /** - * @Deprecated + * @Deprecated Use watchers() instead */ public function watched($page = 1) { @@ -133,7 +133,7 @@ public function starring() } /** - * @Deprecated + * @Deprecated Use starring() instead */ public function starred($page = 1) { diff --git a/lib/Github/Api/CurrentUser/Starred.php b/lib/Github/Api/CurrentUser/Starred.php deleted file mode 100644 index 54d1bb949ca..00000000000 --- a/lib/Github/Api/CurrentUser/Starred.php +++ /dev/null @@ -1,65 +0,0 @@ - - */ -class Starred extends AbstractApi -{ - /** - * List repositories starred by the authenticated user - * @link https://developer.github.com/v3/activity/starring/ - * - * @param integer $page - * @return array - */ - public function all($page = 1) - { - return $this->get('user/starred', array( - 'page' => $page - )); - } - - /** - * Check that the authenticated user starres a repository - * @link https://developer.github.com/v3/activity/starring/ - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @return array - */ - public function check($username, $repository) - { - return $this->get('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); - } - - /** - * Make the authenticated user star a repository - * @link https://developer.github.com/v3/activity/starring/ - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @return array - */ - public function star($username, $repository) - { - return $this->put('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); - } - - /** - * Make the authenticated user unstar a repository - * @link https://developer.github.com/v3/activity/starring - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @return array - */ - public function unstar($username, $repository) - { - return $this->delete('user/starred/'.rawurlencode($username).'/'.rawurlencode($repository)); - } -} From 6acfc0f3f557fb3c28a6a6b963e690bb46fd6c06 Mon Sep 17 00:00:00 2001 From: Felipe Date: Thu, 18 Sep 2014 10:55:01 +0000 Subject: [PATCH 11/11] removed test --- .../Tests/Api/CurrentUser/StarredTest.php | 74 ------------------- 1 file changed, 74 deletions(-) delete mode 100644 test/Github/Tests/Api/CurrentUser/StarredTest.php diff --git a/test/Github/Tests/Api/CurrentUser/StarredTest.php b/test/Github/Tests/Api/CurrentUser/StarredTest.php deleted file mode 100644 index 9a4af991559..00000000000 --- a/test/Github/Tests/Api/CurrentUser/StarredTest.php +++ /dev/null @@ -1,74 +0,0 @@ - 'l3l0/test'), - array('name' => 'cordoval/test') - ); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('user/starred') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->all()); - } - - /** - * @test - */ - public function shouldCheckStar() - { - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('user/starred/l3l0/test') - ->will($this->returnValue(null)); - - $this->assertNull($api->check('l3l0', 'test')); - } - - /** - * @test - */ - public function shouldStarUser() - { - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('put') - ->with('user/starred/l3l0/test') - ->will($this->returnValue(null)); - - $this->assertNull($api->star('l3l0', 'test')); - } - - /** - * @test - */ - public function shouldUnstarUser() - { - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('user/starred/l3l0/test') - ->will($this->returnValue(null)); - - $this->assertNull($api->unstar('l3l0', 'test')); - } - - protected function getApiClass() - { - return 'Github\Api\CurrentUser\Starred'; - } -}