Skip to content

Commit

Permalink
Add support for Pages API (#824)
Browse files Browse the repository at this point in the history
* Add support for Pages API

* Apply fixes from StyleCI

* fixed

* Apply fixes from StyleCI
  • Loading branch information
yunwuxin authored and acrobat committed Nov 1, 2019
1 parent a21dbd7 commit de9322c
Show file tree
Hide file tree
Showing 3 changed files with 216 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Github/Api/Repo.php
Expand Up @@ -12,6 +12,7 @@
use Github\Api\Repository\Forks;
use Github\Api\Repository\Hooks;
use Github\Api\Repository\Labels;
use Github\Api\Repository\Pages;
use Github\Api\Repository\Projects;
use Github\Api\Repository\Protection;
use Github\Api\Repository\Releases;
Expand Down Expand Up @@ -607,6 +608,11 @@ public function traffic()
return new Traffic($this->client);
}

public function pages()
{
return new Pages($this->client);
}

/**
* @param string $username
* @param string $repository
Expand Down
60 changes: 60 additions & 0 deletions lib/Github/Api/Repository/Pages.php
@@ -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));
}
}
150 changes: 150 additions & 0 deletions test/Github/Tests/Api/Repository/PagesTest.php
@@ -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;
}
}

0 comments on commit de9322c

Please sign in to comment.