Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add support for Pages API * Apply fixes from StyleCI * fixed * Apply fixes from StyleCI
- Loading branch information
Showing
3 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Github\Api\Repository; | ||
|
||
use Github\Api\AbstractApi; | ||
use Github\Api\AcceptHeaderTrait; | ||
|
||
/** | ||
* @link https://developer.github.com/v3/repos/pages/ | ||
* | ||
* @author yunwuxin <tzzhangyajun@qq.com> | ||
*/ | ||
class Pages extends AbstractApi | ||
{ | ||
use AcceptHeaderTrait; | ||
|
||
public function show($username, $repository) | ||
{ | ||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages'); | ||
} | ||
|
||
public function enable($username, $repository, array $params = []) | ||
{ | ||
$this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json'; | ||
|
||
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages', $params); | ||
} | ||
|
||
public function disable($username, $repository) | ||
{ | ||
$this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json'; | ||
|
||
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages'); | ||
} | ||
|
||
public function update($username, $repository, array $params = []) | ||
{ | ||
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages', $params); | ||
} | ||
|
||
public function requestBuild($username, $repository) | ||
{ | ||
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds'); | ||
} | ||
|
||
public function builds($username, $repository) | ||
{ | ||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds'); | ||
} | ||
|
||
public function showLatestBuild($username, $repository) | ||
{ | ||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds/latest'); | ||
} | ||
|
||
public function showBuild($username, $repository, $id) | ||
{ | ||
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds/'.rawurlencode($id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
|
||
namespace Github\Tests\Api\Repository; | ||
|
||
use Github\Api\Repository\Pages; | ||
use Github\Tests\Api\TestCase; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
|
||
/** | ||
* Class PagesTest. | ||
* | ||
* @method Pages|MockObject getApiMock() | ||
*/ | ||
class PagesTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function shouldGetPagesInfo() | ||
{ | ||
$expectedValue = ['status' => 'built']; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/repos/KnpLabs/php-github-api/pages') | ||
->will($this->returnValue($expectedValue)); | ||
|
||
$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldEnablePages() | ||
{ | ||
$params = [ | ||
'source' => [ | ||
'branch' => 'master', | ||
'path' => '/path', | ||
], | ||
]; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('post') | ||
->with('/repos/KnpLabs/php-github-api/pages', $params); | ||
|
||
$api->enable('KnpLabs', 'php-github-api', $params); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldDisablePages() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('delete') | ||
->with('/repos/KnpLabs/php-github-api/pages'); | ||
|
||
$api->disable('KnpLabs', 'php-github-api'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldUpdatePages() | ||
{ | ||
$params = [ | ||
'source' => 'master /docs', | ||
]; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('put') | ||
->with('/repos/KnpLabs/php-github-api/pages', $params); | ||
|
||
$api->update('KnpLabs', 'php-github-api', $params); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldRequestPagesBuild() | ||
{ | ||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('post') | ||
->with('/repos/KnpLabs/php-github-api/pages/builds'); | ||
|
||
$api->requestBuild('KnpLabs', 'php-github-api'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldGetAllPagesBuilds() | ||
{ | ||
$expectedValue = [['status' => 'built']]; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/repos/KnpLabs/php-github-api/pages/builds') | ||
->will($this->returnValue($expectedValue)); | ||
|
||
$this->assertEquals($expectedValue, $api->builds('KnpLabs', 'php-github-api')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function shouldGetLatestPagesBuild() | ||
{ | ||
$expectedValue = ['status' => 'built']; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/repos/KnpLabs/php-github-api/pages/builds/latest') | ||
->will($this->returnValue($expectedValue)); | ||
|
||
$this->assertEquals($expectedValue, $api->showLatestBuild('KnpLabs', 'php-github-api')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function showGetOnePagesBuild() | ||
{ | ||
$expectedValue = ['status' => 'built']; | ||
|
||
$api = $this->getApiMock(); | ||
$api->expects($this->once()) | ||
->method('get') | ||
->with('/repos/KnpLabs/php-github-api/pages/builds/some') | ||
->will($this->returnValue($expectedValue)); | ||
|
||
$this->assertEquals($expectedValue, $api->showBuild('KnpLabs', 'php-github-api', 'some')); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getApiClass() | ||
{ | ||
return \Github\Api\Repository\Pages::class; | ||
} | ||
} |