Skip to content

Commit ed79bf4

Browse files
committed
Repo::all method
1 parent d04c463 commit ed79bf4

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

lib/Github/Api/Repo.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ public function find($keyword, array $params = array())
3939
return $this->get('legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params));
4040
}
4141

42+
/**
43+
* List all public repositories.
44+
*
45+
* @link https://developer.github.com/v3/repos/#list-all-public-repositories
46+
*
47+
* @param int|null $id The integer ID of the last Repository that you’ve seen.
48+
*
49+
* @return array list of users found
50+
*/
51+
public function all($id = null)
52+
{
53+
if (!is_int($id)) {
54+
return $this->get('repositories');
55+
}
56+
return $this->get('repositories?since=' . rawurldecode($id));
57+
}
58+
4259
/**
4360
* Get the last year of commit activity for a repository grouped by week.
4461
*

test/Github/Tests/Api/RepoTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,48 @@ public function shouldPaginateFoundRepositories()
5858
$this->assertEquals($expectedArray, $api->find('php', array('start_page' => 2)));
5959
}
6060

61+
/**
62+
* @test
63+
*/
64+
public function shouldGetAllRepositories()
65+
{
66+
$expectedArray = array(
67+
array('id' => 1, 'name' => 'dummy project'),
68+
array('id' => 2, 'name' => 'awesome another project'),
69+
array('id' => 3, 'name' => 'fork of php'),
70+
array('id' => 4, 'name' => 'fork of php-cs'),
71+
);
72+
73+
$api = $this->getApiMock();
74+
$api->expects($this->once())
75+
->method('get')
76+
->with('repositories')
77+
->will($this->returnValue($expectedArray));
78+
79+
$this->assertEquals($expectedArray, $api->all());
80+
}
81+
82+
/**
83+
* @test
84+
*/
85+
public function shouldGetAllRepositoriesStartingIndex()
86+
{
87+
$expectedArray = array(
88+
array('id' => 1, 'name' => 'dummy project'),
89+
array('id' => 2, 'name' => 'awesome another project'),
90+
array('id' => 3, 'name' => 'fork of php'),
91+
array('id' => 4, 'name' => 'fork of php-cs'),
92+
);
93+
94+
$api = $this->getApiMock();
95+
$api->expects($this->once())
96+
->method('get')
97+
->with('repositories?since=2')
98+
->will($this->returnValue($expectedArray));
99+
100+
$this->assertEquals($expectedArray, $api->all(2));
101+
}
102+
61103
/**
62104
* @test
63105
*/

0 commit comments

Comments
 (0)