From 017ec1bf757c877de09225f9ab3b023ccb893dee Mon Sep 17 00:00:00 2001 From: Jeroen Thora Date: Sun, 20 Nov 2016 19:09:09 +0100 Subject: [PATCH] Reworked projects api --- doc/README.md | 6 +- doc/{repo => project}/cards.md | 16 ++-- doc/{repo => project}/columns.md | 16 ++-- doc/{repo => project}/projects.md | 15 +++- lib/Github/Api/Organization/Projects.php | 23 ++++++ lib/Github/Api/Project/AbstractProjectApi.php | 41 ++++++++++ lib/Github/Api/Project/Cards.php | 56 ++++++++++++++ lib/Github/Api/Project/Columns.php | 69 +++++++++++++++++ lib/Github/Api/Repository/Cards.php | 56 -------------- lib/Github/Api/Repository/Columns.php | 69 ----------------- lib/Github/Api/Repository/Projects.php | 37 +-------- lib/Github/Client.php | 6 ++ .../Tests/Api/Organization/ProjectsTest.php | 64 ++++++++++++++++ .../Api/{Repository => Project}/CardsTest.php | 30 ++++---- .../{Repository => Project}/ColumnsTest.php | 36 ++++----- .../Github/Tests/Api/Project/ProjectsTest.php | 76 +++++++++++++++++++ .../Tests/Api/Repository/ProjectsTest.php | 61 +-------------- 17 files changed, 405 insertions(+), 272 deletions(-) rename doc/{repo => project}/cards.md (69%) rename doc/{repo => project}/columns.md (51%) rename doc/{repo => project}/projects.md (55%) create mode 100644 lib/Github/Api/Organization/Projects.php create mode 100644 lib/Github/Api/Project/AbstractProjectApi.php create mode 100644 lib/Github/Api/Project/Cards.php create mode 100644 lib/Github/Api/Project/Columns.php delete mode 100644 lib/Github/Api/Repository/Cards.php delete mode 100644 lib/Github/Api/Repository/Columns.php create mode 100644 test/Github/Tests/Api/Organization/ProjectsTest.php rename test/Github/Tests/Api/{Repository => Project}/CardsTest.php (65%) rename test/Github/Tests/Api/{Repository => Project}/ColumnsTest.php (68%) create mode 100644 test/Github/Tests/Api/Project/ProjectsTest.php diff --git a/doc/README.md b/doc/README.md index b86b1289907..02dd0c2cb5a 100644 --- a/doc/README.md +++ b/doc/README.md @@ -14,15 +14,15 @@ APIs: * [Organization](organization.md) * [Members](organization/members.md) * [Teams](organization/teams.md) +* [Projects](project/projects.md) + * [Columns](project/columns.md) + * [Cards](project/cards.md) * [Pull Requests](pull_requests.md) * [Comments](pull_request/comments.md) * [Rate Limits](rate_limits.md) * [Repositories](repos.md) * [Contents](repo/contents.md) * [Deployments](repo/deployments.md) - * [Projects](repo/projects.md) - * [Columns](repo/columns.md) - * [Cards](repo/cards.md) * [Releases](repo/releases.md) * [Assets](repo/assets.md) * [Stargazers](repo/stargazers.md) diff --git a/doc/repo/cards.md b/doc/project/cards.md similarity index 69% rename from doc/repo/cards.md rename to doc/project/cards.md index baed1aa83be..b66707e6779 100644 --- a/doc/repo/cards.md +++ b/doc/project/cards.md @@ -4,6 +4,10 @@ This api is currently only available to developers in Early Access. To access the API during the Early Access period, you must provide a custom media type in the Accept header. +Both repositories and organisations have projects. The api is only different for getting all project or retrieving a single project. +All the example use the repository projects column card api but this also works form the organization api (`$client->api('org_projects')->columns()->cards()`) + + ```php $client->api('repo')->projects()->columns()->cards()->configure(); ``` @@ -11,13 +15,13 @@ $client->api('repo')->projects()->columns()->cards()->configure(); ### List all cards of a column ```php -$cards = $client->api('repo')->projects()->columns()->cards()->all('twbs', 'bootstrap', $columnId); +$cards = $client->api('repo')->projects()->columns()->cards()->all($columnId); ``` ### List one card ```php -$card = $client->api('repo')->projects()->columns()->cards()->show('twbs', 'bootstrap', $cardId); +$card = $client->api('repo')->projects()->columns()->cards()->show($cardId); ``` ### Create a card @@ -25,7 +29,7 @@ $card = $client->api('repo')->projects()->columns()->cards()->show('twbs', 'boot > Requires [authentication](../security.md). ```php -$card = $client->api('repo')->projects()->columns()->cards()->create('twbs', 'bootstrap', $columnId, array('content_type' => 'Issue', 'content_id' => '452')); +$card = $client->api('repo')->projects()->columns()->cards()->create($columnId, array('content_type' => 'Issue', 'content_id' => '452')); ``` ### Edit a card @@ -33,7 +37,7 @@ $card = $client->api('repo')->projects()->columns()->cards()->create('twbs', 'bo > Requires [authentication](../security.md). ```php -$card = $client->api('repo')->project()->columns()->cards()->update('twbs', 'bootstrap', $cardId, array('note' => 'card note')); +$card = $client->api('repo')->project()->columns()->cards()->update($cardId, array('note' => 'card note')); ``` ### Remove a card @@ -41,7 +45,7 @@ $card = $client->api('repo')->project()->columns()->cards()->update('twbs', 'boo > Requires [authentication](../security.md). ```php -$card = $client->api('repo')->projects()->columns()->cards()->deleteCard('twbs', 'bootstrap', $cardId); +$card = $client->api('repo')->projects()->columns()->cards()->deleteCard($cardId); ``` ### Move a card @@ -49,5 +53,5 @@ $card = $client->api('repo')->projects()->columns()->cards()->deleteCard('twbs', > Requires [authentication](../security.md). ```php -$card = $client->api('repo')->projects()->columns()->cards()->move('twbs', 'bootstrap', $cardId, array('position' => 'top)); +$card = $client->api('repo')->projects()->columns()->cards()->move($cardId, array('position' => 'top)); ``` diff --git a/doc/repo/columns.md b/doc/project/columns.md similarity index 51% rename from doc/repo/columns.md rename to doc/project/columns.md index 94263efd9fd..2f4a990942d 100644 --- a/doc/repo/columns.md +++ b/doc/project/columns.md @@ -4,6 +4,10 @@ This api is currently only available to developers in Early Access. To access the API during the Early Access period, you must provide a custom media type in the Accept header. +Both repositories and organisations have projects. The api is only different for getting all project or retrieving a single project. +All the example use the repository projects column api but this also works form the organization api (`$client->api('org_projects')->columns()`) + + ```php $client->api('repo')->projects()->columns()->configure(); ``` @@ -11,13 +15,13 @@ $client->api('repo')->projects()->columns()->configure(); ### List all columns of a project ```php -$columns = $client->api('repo')->projects()->columns()->all('twbs', 'bootstrap', $projectId); +$columns = $client->api('repo')->projects()->columns()->all($projectId); ``` ### List one column ```php -$column = $client->api('repo')->projects()->columns()->show('twbs', 'bootstrap', $columnId); +$column = $client->api('repo')->projects()->columns()->show($columnId); ``` ### Create a column @@ -25,7 +29,7 @@ $column = $client->api('repo')->projects()->columns()->show('twbs', 'bootstrap', > Requires [authentication](../security.md). ```php -$column = $client->api('repo')->projects()->columns()->create('twbs', 'bootstrap', $projectId, array('name' => 'Column name')); +$column = $client->api('repo')->projects()->columns()->create($projectId, array('name' => 'Column name')); ``` ### Edit a column @@ -33,7 +37,7 @@ $column = $client->api('repo')->projects()->columns()->create('twbs', 'bootstrap > Requires [authentication](../security.md). ```php -$column = $client->api('repo')->project()->columns()->update('twbs', 'bootstrap', $columnId, array('name' => 'New name')); +$column = $client->api('repo')->project()->columns()->update($columnId, array('name' => 'New name')); ``` ### Remove a column @@ -41,7 +45,7 @@ $column = $client->api('repo')->project()->columns()->update('twbs', 'bootstrap' > Requires [authentication](../security.md). ```php -$column = $client->api('repo')->projects()->columns()->deleteColumn('twbs', 'bootstrap', $columnId); +$column = $client->api('repo')->projects()->columns()->deleteColumn($columnId); ``` ### Move a column @@ -49,5 +53,5 @@ $column = $client->api('repo')->projects()->columns()->deleteColumn('twbs', 'boo > Requires [authentication](../security.md). ```php -$column = $client->api('repo')->projects()->columns()->move('twbs', 'bootstrap', $columnId, array('position' => 'first)); +$column = $client->api('repo')->projects()->columns()->move($columnId, array('position' => 'first)); ``` diff --git a/doc/repo/projects.md b/doc/project/projects.md similarity index 55% rename from doc/repo/projects.md rename to doc/project/projects.md index 2743973b73c..5763e0060e7 100644 --- a/doc/repo/projects.md +++ b/doc/project/projects.md @@ -1,9 +1,12 @@ ## Repo / Projects API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) +[Back to the "Repos API"](../) | [Back to the navigation](../README.md) This api is currently only available to developers in Early Access. To access the API during the Early Access period, you must provide a custom media type in the Accept header. +Both repositories and organisations have projects. The api is only different for gettings all or a single project. +All the example use the repository projects api but this also works form the organization api (`$client->api('org_projects')`) + ```php $client->api('repo')->projects()->configure(); ``` @@ -12,12 +15,16 @@ $client->api('repo')->projects()->configure(); ```php $projects = $client->api('repo')->projects()->all('twbs', 'bootstrap'); + +//or + +$projects = $client->api('org_projects')->all('twbs'); ``` ### List one project ```php -$project = $client->api('repo')->projects()->show('twbs', 'bootstrap', $projectId); +$project = $client->api('repo')->projects()->show($projectId); ``` ### Create a project @@ -33,7 +40,7 @@ $project = $client->api('repo')->projects()->create('twbs', 'bootstrap', array(' > Requires [authentication](../security.md). ```php -$project = $client->api('repo')->project()->update('twbs', 'bootstrap', $projectId, array('name' => 'New name')); +$project = $client->api('repo')->project()->update($projectId, array('name' => 'New name')); ``` ### Remove a project @@ -41,5 +48,5 @@ $project = $client->api('repo')->project()->update('twbs', 'bootstrap', $project > Requires [authentication](../security.md). ```php -$project = $client->api('repo')->projects()->deleteProject('twbs', 'bootstrap', $projectId); +$project = $client->api('repo')->projects()->deleteProject($projectId); ``` diff --git a/lib/Github/Api/Organization/Projects.php b/lib/Github/Api/Organization/Projects.php new file mode 100644 index 00000000000..dcff9c86c98 --- /dev/null +++ b/lib/Github/Api/Organization/Projects.php @@ -0,0 +1,23 @@ +get('/orgs/'.rawurlencode($organization).'/projects', array_merge(array('page' => 1), $params)); + } + + public function create($organization, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException(array('name')); + } + + return $this->post('/orgs/'.rawurlencode($organization).'/projects', $params); + } +} diff --git a/lib/Github/Api/Project/AbstractProjectApi.php b/lib/Github/Api/Project/AbstractProjectApi.php new file mode 100644 index 00000000000..55bc733424f --- /dev/null +++ b/lib/Github/Api/Project/AbstractProjectApi.php @@ -0,0 +1,41 @@ +acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + } + + public function show($id, array $params = array()) + { + return $this->get('/projects/' . rawurlencode($id), array_merge(array('page' => 1), $params)); + } + + public function update($id, array $params) + { + return $this->patch('/projects/'.rawurlencode($id), $params); + } + + public function deleteProject($id) + { + return $this->delete('/projects/'.rawurlencode($id)); + } + + public function columns() + { + return new Columns($this->client); + } +} diff --git a/lib/Github/Api/Project/Cards.php b/lib/Github/Api/Project/Cards.php new file mode 100644 index 00000000000..65765b75907 --- /dev/null +++ b/lib/Github/Api/Project/Cards.php @@ -0,0 +1,56 @@ +acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + } + + public function all($columnId, array $params = array()) + { + return $this->get('/projects/columns/' . rawurlencode($columnId) . '/cards', array_merge(array('page' => 1), $params)); + } + + public function show($id) + { + return $this->get('/projects/columns/cards/'.rawurlencode($id)); + } + + public function create($columnId, array $params) + { + return $this->post('/projects/columns/' . rawurlencode($columnId) . '/cards', $params); + } + + public function update($id, array $params) + { + return $this->patch('/projects/columns/cards/' . rawurlencode($id), $params); + } + + public function deleteCard($id) + { + return $this->delete('/projects/columns/cards/'.rawurlencode($id)); + } + + public function move($id, array $params) + { + if (!isset($params['position'])) { + throw new MissingArgumentException(array('position')); + } + + return $this->post('/projects/columns/cards/' . rawurlencode($id) . '/moves', $params); + } +} diff --git a/lib/Github/Api/Project/Columns.php b/lib/Github/Api/Project/Columns.php new file mode 100644 index 00000000000..16b9f25c327 --- /dev/null +++ b/lib/Github/Api/Project/Columns.php @@ -0,0 +1,69 @@ +acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; + } + + public function all($projectId, array $params = array()) + { + return $this->get('/projects/' . rawurlencode($projectId) . '/columns', array_merge(array('page' => 1), $params)); + } + + public function show($id) + { + return $this->get('/projects/columns/'.rawurlencode($id)); + } + + public function create($projectId, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException(array('name')); + } + + return $this->post('/projects/' . rawurlencode($projectId) . '/columns', $params); + } + + public function update($id, array $params) + { + if (!isset($params['name'])) { + throw new MissingArgumentException(array('name')); + } + + return $this->patch('/projects/columns/' . rawurlencode($id), $params); + } + + public function deleteColumn($id) + { + return $this->delete('/projects/columns/'.rawurlencode($id)); + } + + public function move($id, array $params) + { + if (!isset($params['position'])) { + throw new MissingArgumentException(array('position')); + } + + return $this->post('/projects/columns/' . rawurlencode($id) . '/moves', $params); + } + + public function cards() + { + return new Cards($this->client); + } +} diff --git a/lib/Github/Api/Repository/Cards.php b/lib/Github/Api/Repository/Cards.php deleted file mode 100644 index e772ca97328..00000000000 --- a/lib/Github/Api/Repository/Cards.php +++ /dev/null @@ -1,56 +0,0 @@ -acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; - } - - public function all($username, $repository, $columnId, array $params = array()) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($columnId) . '/cards', array_merge(array('page' => 1), $params)); - } - - public function show($username, $repository, $id) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/'.rawurlencode($id)); - } - - public function create($username, $repository, $columnId, array $params) - { - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($columnId) . '/cards', $params); - } - - public function update($username, $repository, $id, array $params) - { - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/' . rawurlencode($id), $params); - } - - public function deleteCard($username, $repository, $id) - { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/'.rawurlencode($id)); - } - - public function move($username, $repository, $id, array $params) - { - if (!isset($params['position'])) { - throw new MissingArgumentException(array('position')); - } - - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/cards/' . rawurlencode($id) . '/moves', $params); - } -} diff --git a/lib/Github/Api/Repository/Columns.php b/lib/Github/Api/Repository/Columns.php deleted file mode 100644 index 1b4e016a87b..00000000000 --- a/lib/Github/Api/Repository/Columns.php +++ /dev/null @@ -1,69 +0,0 @@ -acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; - } - - public function all($username, $repository, $projectId, array $params = array()) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($projectId) . '/columns', array_merge(array('page' => 1), $params)); - } - - public function show($username, $repository, $id) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/'.rawurlencode($id)); - } - - public function create($username, $repository, $projectId, array $params) - { - if (!isset($params['name'])) { - throw new MissingArgumentException(array('name')); - } - - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($projectId) . '/columns', $params); - } - - public function update($username, $repository, $id, array $params) - { - if (!isset($params['name'])) { - throw new MissingArgumentException(array('name')); - } - - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($id), $params); - } - - public function deleteColumn($username, $repository, $id) - { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/'.rawurlencode($id)); - } - - public function move($username, $repository, $id, array $params) - { - if (!isset($params['position'])) { - throw new MissingArgumentException(array('position')); - } - - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/columns/' . rawurlencode($id) . '/moves', $params); - } - - public function cards() - { - return new Cards($this->client); - } -} diff --git a/lib/Github/Api/Repository/Projects.php b/lib/Github/Api/Repository/Projects.php index 1b791a90be4..279a1d45f92 100644 --- a/lib/Github/Api/Repository/Projects.php +++ b/lib/Github/Api/Repository/Projects.php @@ -2,34 +2,16 @@ namespace Github\Api\Repository; -use Github\Api\AbstractApi; -use Github\Api\AcceptHeaderTrait; +use Github\Api\Project\AbstractProjectApi; use Github\Exception\MissingArgumentException; -class Projects extends AbstractApi +class Projects extends AbstractProjectApi { - use AcceptHeaderTrait; - - /** - * Configure the accept header for Early Access to the projects api - * - * @see https://developer.github.com/v3/repos/projects/#projects - */ - public function configure() - { - $this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json'; - } - public function all($username, $repository, array $params = array()) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', array_merge(array('page' => 1), $params)); } - public function show($username, $repository, $id, array $params = array()) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/' . rawurlencode($id), array_merge(array('page' => 1), $params)); - } - public function create($username, $repository, array $params) { if (!isset($params['name'])) { @@ -38,19 +20,4 @@ public function create($username, $repository, array $params) return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects', $params); } - - public function update($username, $repository, $id, array $params) - { - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/'.rawurlencode($id), $params); - } - - public function deleteProject($username, $repository, $id) - { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/projects/'.rawurlencode($id)); - } - - public function columns() - { - return new Columns($this->client); - } } diff --git a/lib/Github/Client.php b/lib/Github/Client.php index b074db5a14a..25e8915c323 100644 --- a/lib/Github/Client.php +++ b/lib/Github/Client.php @@ -233,6 +233,12 @@ public function api($name) case 'organizations': $api = new Api\Organization($this); break; + case 'org_project': + case 'org_projects': + case 'organization_project': + case 'organization_projects': + $api = new Api\Organization\Projects($this); + break; case 'pr': case 'pullRequest': diff --git a/test/Github/Tests/Api/Organization/ProjectsTest.php b/test/Github/Tests/Api/Organization/ProjectsTest.php new file mode 100644 index 00000000000..1415949a343 --- /dev/null +++ b/test/Github/Tests/Api/Organization/ProjectsTest.php @@ -0,0 +1,64 @@ + 'Test project 1')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/orgs/KnpLabs/projects') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs')); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateWithoutName() + { + $data = array(); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', $data); + } + + /** + * @test + */ + public function shouldCreateColumn() + { + $expectedValue = array('project1data'); + $data = array('name' => 'Project 1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/orgs/KnpLabs/projects', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', $data)); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Organization\Projects::class; + } +} diff --git a/test/Github/Tests/Api/Repository/CardsTest.php b/test/Github/Tests/Api/Project/CardsTest.php similarity index 65% rename from test/Github/Tests/Api/Repository/CardsTest.php rename to test/Github/Tests/Api/Project/CardsTest.php index d4795b802f1..0b68310274f 100644 --- a/test/Github/Tests/Api/Repository/CardsTest.php +++ b/test/Github/Tests/Api/Project/CardsTest.php @@ -1,6 +1,6 @@ getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/projects/columns/123/cards') + ->with('/projects/columns/123/cards') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->all(123)); } /** @@ -32,10 +32,10 @@ public function shouldShowCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123') + ->with('/projects/columns/cards/123') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->show(123)); } /** @@ -49,10 +49,10 @@ public function shouldCreateCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/projects/columns/1234/cards', $data) + ->with('/projects/columns/1234/cards', $data) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', '1234', $data)); + $this->assertEquals($expectedValue, $api->create('1234', $data)); } /** @@ -66,10 +66,10 @@ public function shouldUpdateCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123', $data) + ->with('/projects/columns/cards/123', $data) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); + $this->assertEquals($expectedValue, $api->update(123, $data)); } /** @@ -82,10 +82,10 @@ public function shouldRemoveCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123') + ->with('/projects/columns/cards/123') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->deleteCard('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->deleteCard(123)); } /** @@ -100,7 +100,7 @@ public function shouldNotMoveWithoutPosition() $api->expects($this->never()) ->method('post'); - $api->move('KnpLabs', 'php-github-api', '123', $data); + $api->move('123', $data); } /** @@ -114,10 +114,10 @@ public function shouldMoveCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/projects/columns/cards/123/moves') + ->with('/projects/columns/cards/123/moves') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->move('KnpLabs', 'php-github-api', 123, $data)); + $this->assertEquals($expectedValue, $api->move(123, $data)); } /** @@ -125,6 +125,6 @@ public function shouldMoveCard() */ protected function getApiClass() { - return \Github\Api\Repository\Cards::class; + return \Github\Api\Project\Cards::class; } } diff --git a/test/Github/Tests/Api/Repository/ColumnsTest.php b/test/Github/Tests/Api/Project/ColumnsTest.php similarity index 68% rename from test/Github/Tests/Api/Repository/ColumnsTest.php rename to test/Github/Tests/Api/Project/ColumnsTest.php index b12c0706cf2..cb244623095 100644 --- a/test/Github/Tests/Api/Repository/ColumnsTest.php +++ b/test/Github/Tests/Api/Project/ColumnsTest.php @@ -1,6 +1,6 @@ getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/projects/123/columns') + ->with('/projects/123/columns') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->all(123)); } /** @@ -32,10 +32,10 @@ public function shouldShowColumn() $api = $this->getApiMock(); $api->expects($this->once()) ->method('get') - ->with('/repos/KnpLabs/php-github-api/projects/columns/123') + ->with('/projects/columns/123') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->show(123)); } /** @@ -50,7 +50,7 @@ public function shouldNotCreateWithoutName() $api->expects($this->never()) ->method('post'); - $api->create('KnpLabs', 'php-github-api', '123', $data); + $api->create('123', $data); } /** @@ -64,10 +64,10 @@ public function shouldCreateColumn() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/projects/123/columns', $data) + ->with('/projects/123/columns', $data) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', 123, $data)); + $this->assertEquals($expectedValue, $api->create(123, $data)); } /** @@ -82,7 +82,7 @@ public function shouldNotUpdateWithoutName() $api->expects($this->never()) ->method('post'); - $api->update('KnpLabs', 'php-github-api', '123', $data); + $api->update('123', $data); } /** @@ -96,10 +96,10 @@ public function shouldUpdateColumn() $api = $this->getApiMock(); $api->expects($this->once()) ->method('patch') - ->with('/repos/KnpLabs/php-github-api/projects/columns/123', $data) + ->with('/projects/columns/123', $data) ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); + $this->assertEquals($expectedValue, $api->update(123, $data)); } /** @@ -112,10 +112,10 @@ public function shouldRemoveCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('delete') - ->with('/repos/KnpLabs/php-github-api/projects/columns/123') + ->with('/projects/columns/123') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->deleteColumn('KnpLabs', 'php-github-api', 123)); + $this->assertEquals($expectedValue, $api->deleteColumn(123)); } /** @@ -130,7 +130,7 @@ public function shouldNotMoveWithoutPosition() $api->expects($this->never()) ->method('post'); - $api->move('KnpLabs', 'php-github-api', '123', $data); + $api->move('123', $data); } /** @@ -144,10 +144,10 @@ public function shouldMoveCard() $api = $this->getApiMock(); $api->expects($this->once()) ->method('post') - ->with('/repos/KnpLabs/php-github-api/projects/columns/123/moves') + ->with('/projects/columns/123/moves') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->move('KnpLabs', 'php-github-api', 123, $data)); + $this->assertEquals($expectedValue, $api->move(123, $data)); } /** @@ -157,7 +157,7 @@ public function shouldGetCardsApiObject() { $api = $this->getApiMock(); - $this->assertInstanceOf('Github\Api\Repository\Cards', $api->cards()); + $this->assertInstanceOf('Github\Api\Project\Cards', $api->cards()); } /** @@ -165,6 +165,6 @@ public function shouldGetCardsApiObject() */ protected function getApiClass() { - return \Github\Api\Repository\Columns::class; + return \Github\Api\Project\Columns::class; } } diff --git a/test/Github/Tests/Api/Project/ProjectsTest.php b/test/Github/Tests/Api/Project/ProjectsTest.php new file mode 100644 index 00000000000..3278b6b0ee1 --- /dev/null +++ b/test/Github/Tests/Api/Project/ProjectsTest.php @@ -0,0 +1,76 @@ + 'Test project 1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/projects/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show(123)); + } + + /** + * @test + */ + public function shouldUpdateProject() + { + $expectedValue = array('project1data'); + $data = array('name' => 'Project 1 update'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/projects/123', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update(123, $data)); + } + + /** + * @test + */ + public function shouldRemoveProject() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/projects/123') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->deleteProject(123)); + } + + /** + * @test + */ + public function shouldGetColumnsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Project\Columns', $api->columns()); + } + + /** + * @return string + */ + protected function getApiClass() + { + return AbstractProjectApi::class; + } +} diff --git a/test/Github/Tests/Api/Repository/ProjectsTest.php b/test/Github/Tests/Api/Repository/ProjectsTest.php index d82b7bbe4dd..2b0c50d2cf0 100644 --- a/test/Github/Tests/Api/Repository/ProjectsTest.php +++ b/test/Github/Tests/Api/Repository/ProjectsTest.php @@ -22,22 +22,6 @@ public function shouldGetAllRepositoryProjects() $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); } - /** - * @test - */ - public function shouldShowProject() - { - $expectedValue = array('name' => 'Test project 1'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/projects/123') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 123)); - } - /** * @test * @expectedException \Github\Exception\MissingArgumentException @@ -58,7 +42,7 @@ public function shouldNotCreateWithoutName() */ public function shouldCreateColumn() { - $expectedValue = array('column1data'); + $expectedValue = array('project1data'); $data = array('name' => 'Project 1'); $api = $this->getApiMock(); @@ -70,49 +54,6 @@ public function shouldCreateColumn() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } - /** - * @test - */ - public function shouldUpdateProject() - { - $expectedValue = array('project1data'); - $data = array('name' => 'Project 1 update'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('patch') - ->with('/repos/KnpLabs/php-github-api/projects/123', $data) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 123, $data)); - } - - /** - * @test - */ - public function shouldRemoveProject() - { - $expectedValue = array('someOutput'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/repos/KnpLabs/php-github-api/projects/123') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->deleteProject('KnpLabs', 'php-github-api', 123)); - } - - /** - * @test - */ - public function shouldGetColumnsApiObject() - { - $api = $this->getApiMock(); - - $this->assertInstanceOf('Github\Api\Repository\Columns', $api->columns()); - } - /** * @return string */