Skip to content

Commit 92633d1

Browse files
committed
Merge pull request #1 from YevKov/master
Unit tests added for Github\Api\Search
2 parents bb2b30e + a7e3946 commit 92633d1

File tree

3 files changed

+233
-0
lines changed

3 files changed

+233
-0
lines changed

doc/search.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Search API
2+
[Back to the navigation](index.md)
3+
4+
Searching repositories, code, issues and users.
5+
Wrap [GitHub Search API](http://developer.github.com/v3/search/). All methods are described on that page.
6+
7+
### Search repositories
8+
9+
```php
10+
$repos = $client->api('search')->repositories('github language:php');
11+
```
12+
13+
Returns a list of repositories found by such criteria.
14+
15+
### Search code
16+
17+
```php
18+
$repos = $client->api('search')->code('@todo language:php');
19+
```
20+
21+
Returns a list of files found by such criteria (containing "@todo" and language==php).
22+
23+
### Search issues
24+
25+
```php
26+
$repos = $client->api('search')->issues('bug language:php');
27+
```
28+
29+
Returns a list of issues found by such criteria.
30+
31+
### Search users
32+
33+
```php
34+
$repos = $client->api('search')->users('location:Amsterdam language:php');
35+
```
36+
37+
Returns a list of users found by such criteria.
38+
39+
### Sorting results
40+
41+
You can sort results using 2-3 arguments.
42+
43+
```php
44+
$repos = $client->api('repo')->repositories('...', 'created', 'asc');
45+
$repos = $client->api('repo')->code('...........', 'indexed', 'desc');
46+
$repos = $client->api('repo')->issues('.........', 'comments', 'asc');
47+
$repos = $client->api('repo')->users('..........', 'followers', 'asc');
48+
```

test/Github/Tests/Api/SearchTest.php

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
<?php
2+
3+
namespace Github\Tests\Api;
4+
5+
class SearchTest extends TestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function shouldSearchRepositoriesByQuery()
11+
{
12+
$expectedArray = array(array('total_count' => '0'));
13+
14+
$api = $this->getApiMock();
15+
16+
$api->expects($this->once())
17+
->method('get')
18+
->with(
19+
'/search/repositories',
20+
array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc')
21+
)
22+
->will($this->returnValue($expectedArray));
23+
24+
$this->assertEquals($expectedArray, $api->repositories('query text'));
25+
}
26+
27+
/**
28+
* @test
29+
*/
30+
public function shouldSearchRepositoriesRegardingSortAndOrder()
31+
{
32+
$expectedArray = array(array('total_count' => '0'));
33+
34+
$api = $this->getApiMock();
35+
36+
$api->expects($this->once())
37+
->method('get')
38+
->with(
39+
'/search/repositories',
40+
array('q' => 'query text', 'sort' => 'created', 'order' => 'asc')
41+
)
42+
->will($this->returnValue($expectedArray));
43+
44+
$this->assertEquals(
45+
$expectedArray,
46+
$api->repositories('query text', 'created', 'asc')
47+
);
48+
}
49+
50+
/**
51+
* @test
52+
*/
53+
public function shouldSearchIssuesByQuery()
54+
{
55+
$expectedArray = array(array('total_count' => '0'));
56+
57+
$api = $this->getApiMock();
58+
59+
$api->expects($this->once())
60+
->method('get')
61+
->with(
62+
'/search/issues',
63+
array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc')
64+
)
65+
->will($this->returnValue($expectedArray));
66+
67+
$this->assertEquals($expectedArray, $api->issues('query text'));
68+
}
69+
70+
/**
71+
* @test
72+
*/
73+
public function shouldSearchIssuesRegardingSortAndOrder()
74+
{
75+
$expectedArray = array(array('total_count' => '0'));
76+
77+
$api = $this->getApiMock();
78+
79+
$api->expects($this->once())
80+
->method('get')
81+
->with(
82+
'/search/issues',
83+
array('q' => 'query text', 'sort' => 'created', 'order' => 'asc')
84+
)
85+
->will($this->returnValue($expectedArray));
86+
87+
$this->assertEquals(
88+
$expectedArray,
89+
$api->issues('query text', 'created', 'asc')
90+
);
91+
}
92+
93+
/**
94+
* @test
95+
*/
96+
public function shouldSearchCodeByQuery()
97+
{
98+
$expectedArray = array(array('total_count' => '0'));
99+
100+
$api = $this->getApiMock();
101+
102+
$api->expects($this->once())
103+
->method('get')
104+
->with(
105+
'/search/code',
106+
array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc')
107+
)
108+
->will($this->returnValue($expectedArray));
109+
110+
$this->assertEquals($expectedArray, $api->code('query text'));
111+
}
112+
113+
/**
114+
* @test
115+
*/
116+
public function shouldSearchCodeRegardingSortAndOrder()
117+
{
118+
$expectedArray = array(array('total_count' => '0'));
119+
120+
$api = $this->getApiMock();
121+
122+
$api->expects($this->once())
123+
->method('get')
124+
->with(
125+
'/search/code',
126+
array('q' => 'query text', 'sort' => 'created', 'order' => 'asc')
127+
)
128+
->will($this->returnValue($expectedArray));
129+
130+
$this->assertEquals(
131+
$expectedArray,
132+
$api->code('query text', 'created', 'asc')
133+
);
134+
}
135+
136+
/**
137+
* @test
138+
*/
139+
public function shouldSearchUsersByQuery()
140+
{
141+
$expectedArray = array(array('total_count' => '0'));
142+
143+
$api = $this->getApiMock();
144+
145+
$api->expects($this->once())
146+
->method('get')
147+
->with(
148+
'/search/users',
149+
array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc')
150+
)
151+
->will($this->returnValue($expectedArray));
152+
153+
$this->assertEquals($expectedArray, $api->users('query text'));
154+
}
155+
156+
/**
157+
* @test
158+
*/
159+
public function shouldSearchUsersRegardingSortAndOrder()
160+
{
161+
$expectedArray = array(array('total_count' => '0'));
162+
163+
$api = $this->getApiMock();
164+
165+
$api->expects($this->once())
166+
->method('get')
167+
->with(
168+
'/search/users',
169+
array('q' => 'query text', 'sort' => 'created', 'order' => 'asc')
170+
)
171+
->will($this->returnValue($expectedArray));
172+
173+
$this->assertEquals(
174+
$expectedArray,
175+
$api->users('query text', 'created', 'asc')
176+
);
177+
}
178+
179+
protected function getApiClass()
180+
{
181+
return 'Github\Api\Search';
182+
}
183+
}

test/Github/Tests/ClientTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ public function getApiClassesProvider()
186186
array('repository', 'Github\Api\Repo'),
187187
array('repositories', 'Github\Api\Repo'),
188188

189+
array('search', 'Github\Api\Search'),
190+
189191
array('pr', 'Github\Api\PullRequest'),
190192
array('pullRequest', 'Github\Api\PullRequest'),
191193
array('pull_request', 'Github\Api\PullRequest'),

0 commit comments

Comments
 (0)