Skip to content

Commit de9322c

Browse files
yunwuxinacrobat
authored andcommitted
Add support for Pages API (#824)
* Add support for Pages API * Apply fixes from StyleCI * fixed * Apply fixes from StyleCI
1 parent a21dbd7 commit de9322c

File tree

3 files changed

+216
-0
lines changed

3 files changed

+216
-0
lines changed

lib/Github/Api/Repo.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Github\Api\Repository\Forks;
1313
use Github\Api\Repository\Hooks;
1414
use Github\Api\Repository\Labels;
15+
use Github\Api\Repository\Pages;
1516
use Github\Api\Repository\Projects;
1617
use Github\Api\Repository\Protection;
1718
use Github\Api\Repository\Releases;
@@ -607,6 +608,11 @@ public function traffic()
607608
return new Traffic($this->client);
608609
}
609610

611+
public function pages()
612+
{
613+
return new Pages($this->client);
614+
}
615+
610616
/**
611617
* @param string $username
612618
* @param string $repository

lib/Github/Api/Repository/Pages.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Github\Api\Repository;
4+
5+
use Github\Api\AbstractApi;
6+
use Github\Api\AcceptHeaderTrait;
7+
8+
/**
9+
* @link https://developer.github.com/v3/repos/pages/
10+
*
11+
* @author yunwuxin <tzzhangyajun@qq.com>
12+
*/
13+
class Pages extends AbstractApi
14+
{
15+
use AcceptHeaderTrait;
16+
17+
public function show($username, $repository)
18+
{
19+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages');
20+
}
21+
22+
public function enable($username, $repository, array $params = [])
23+
{
24+
$this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json';
25+
26+
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages', $params);
27+
}
28+
29+
public function disable($username, $repository)
30+
{
31+
$this->acceptHeaderValue = 'application/vnd.github.switcheroo-preview+json';
32+
33+
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages');
34+
}
35+
36+
public function update($username, $repository, array $params = [])
37+
{
38+
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages', $params);
39+
}
40+
41+
public function requestBuild($username, $repository)
42+
{
43+
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds');
44+
}
45+
46+
public function builds($username, $repository)
47+
{
48+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds');
49+
}
50+
51+
public function showLatestBuild($username, $repository)
52+
{
53+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds/latest');
54+
}
55+
56+
public function showBuild($username, $repository, $id)
57+
{
58+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/pages/builds/'.rawurlencode($id));
59+
}
60+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Repository;
4+
5+
use Github\Api\Repository\Pages;
6+
use Github\Tests\Api\TestCase;
7+
use PHPUnit\Framework\MockObject\MockObject;
8+
9+
/**
10+
* Class PagesTest.
11+
*
12+
* @method Pages|MockObject getApiMock()
13+
*/
14+
class PagesTest extends TestCase
15+
{
16+
/**
17+
* @test
18+
*/
19+
public function shouldGetPagesInfo()
20+
{
21+
$expectedValue = ['status' => 'built'];
22+
23+
$api = $this->getApiMock();
24+
$api->expects($this->once())
25+
->method('get')
26+
->with('/repos/KnpLabs/php-github-api/pages')
27+
->will($this->returnValue($expectedValue));
28+
29+
$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api'));
30+
}
31+
32+
/**
33+
* @test
34+
*/
35+
public function shouldEnablePages()
36+
{
37+
$params = [
38+
'source' => [
39+
'branch' => 'master',
40+
'path' => '/path',
41+
],
42+
];
43+
44+
$api = $this->getApiMock();
45+
$api->expects($this->once())
46+
->method('post')
47+
->with('/repos/KnpLabs/php-github-api/pages', $params);
48+
49+
$api->enable('KnpLabs', 'php-github-api', $params);
50+
}
51+
52+
/**
53+
* @test
54+
*/
55+
public function shouldDisablePages()
56+
{
57+
$api = $this->getApiMock();
58+
$api->expects($this->once())
59+
->method('delete')
60+
->with('/repos/KnpLabs/php-github-api/pages');
61+
62+
$api->disable('KnpLabs', 'php-github-api');
63+
}
64+
65+
/**
66+
* @test
67+
*/
68+
public function shouldUpdatePages()
69+
{
70+
$params = [
71+
'source' => 'master /docs',
72+
];
73+
74+
$api = $this->getApiMock();
75+
$api->expects($this->once())
76+
->method('put')
77+
->with('/repos/KnpLabs/php-github-api/pages', $params);
78+
79+
$api->update('KnpLabs', 'php-github-api', $params);
80+
}
81+
82+
/**
83+
* @test
84+
*/
85+
public function shouldRequestPagesBuild()
86+
{
87+
$api = $this->getApiMock();
88+
$api->expects($this->once())
89+
->method('post')
90+
->with('/repos/KnpLabs/php-github-api/pages/builds');
91+
92+
$api->requestBuild('KnpLabs', 'php-github-api');
93+
}
94+
95+
/**
96+
* @test
97+
*/
98+
public function shouldGetAllPagesBuilds()
99+
{
100+
$expectedValue = [['status' => 'built']];
101+
102+
$api = $this->getApiMock();
103+
$api->expects($this->once())
104+
->method('get')
105+
->with('/repos/KnpLabs/php-github-api/pages/builds')
106+
->will($this->returnValue($expectedValue));
107+
108+
$this->assertEquals($expectedValue, $api->builds('KnpLabs', 'php-github-api'));
109+
}
110+
111+
/**
112+
* @test
113+
*/
114+
public function shouldGetLatestPagesBuild()
115+
{
116+
$expectedValue = ['status' => 'built'];
117+
118+
$api = $this->getApiMock();
119+
$api->expects($this->once())
120+
->method('get')
121+
->with('/repos/KnpLabs/php-github-api/pages/builds/latest')
122+
->will($this->returnValue($expectedValue));
123+
124+
$this->assertEquals($expectedValue, $api->showLatestBuild('KnpLabs', 'php-github-api'));
125+
}
126+
127+
/**
128+
* @test
129+
*/
130+
public function showGetOnePagesBuild()
131+
{
132+
$expectedValue = ['status' => 'built'];
133+
134+
$api = $this->getApiMock();
135+
$api->expects($this->once())
136+
->method('get')
137+
->with('/repos/KnpLabs/php-github-api/pages/builds/some')
138+
->will($this->returnValue($expectedValue));
139+
140+
$this->assertEquals($expectedValue, $api->showBuild('KnpLabs', 'php-github-api', 'some'));
141+
}
142+
143+
/**
144+
* @return string
145+
*/
146+
protected function getApiClass()
147+
{
148+
return \Github\Api\Repository\Pages::class;
149+
}
150+
}

0 commit comments

Comments
 (0)