Skip to content

Commit 78c9c49

Browse files
committed
use OptionsResolver in ProjectNamespaces api
1 parent f1c3bb6 commit 78c9c49

File tree

3 files changed

+15
-61
lines changed

3 files changed

+15
-61
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ Use the `deployKeys`, `deployKey`, `addDeployKey`, `deleteDeployKey`, `removeDep
5858
* The `builds` method have been removed. Use `Gitlab\Api\Jobs::all` instead.
5959
* The `build` method have been removed. Use `Gitlab\Api\Jobs::show` instead.
6060

61+
## `Gitlab\Api\ProjectNamespaces` changes
62+
63+
* The `search` method have been removed. Use `all` method instead.
64+
* The `all` method now take a single argument which is an associative array of query string parameters.
65+
6166
## `Gitlab\Api\Repositories` changes
6267

6368
* The `commits` page argument now start from 1 instead of 0.

lib/Gitlab/Api/ProjectNamespaces.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,18 @@
33
class ProjectNamespaces extends AbstractApi
44
{
55
/**
6-
* @param int $page
7-
* @param int $per_page
6+
* @param array $parameters (
7+
*
8+
* @var string $search Returns a list of namespaces the user is authorized to see based on the search criteria.
9+
* )
10+
*
811
* @return mixed
912
*/
10-
public function all($page = 1, $per_page = self::PER_PAGE)
13+
public function all(array $parameters = [])
1114
{
12-
return $this->get('namespaces', array(
13-
'page' => $page,
14-
'per_page' => $per_page
15-
));
16-
}
15+
$resolver = $this->createOptionsResolver();
16+
$resolver->setDefined('search');
1717

18-
/**
19-
* @param string $terms
20-
* @param int $page
21-
* @param int $per_page
22-
* @return mixed
23-
*/
24-
public function search($terms, $page = 1, $per_page = self::PER_PAGE)
25-
{
26-
return $this->get('namespaces', array(
27-
'search' => $terms,
28-
'page' => $page,
29-
'per_page' => $per_page
30-
));
18+
return $this->get('namespaces', $resolver->resolve($parameters));
3119
}
3220
}

test/Gitlab/Tests/Api/ProjectNamespacesTest.php

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,51 +17,12 @@ public function shouldGetAllNamespaces()
1717
$api = $this->getApiMock();
1818
$api->expects($this->once())
1919
->method('get')
20-
->with('namespaces', array('page' => 1, 'per_page' => 10))
21-
->will($this->returnValue($expectedArray))
22-
;
23-
24-
$this->assertEquals($expectedArray, $api->all(1, 10));
25-
}
26-
27-
/**
28-
* @test
29-
*/
30-
public function shouldNotNeedPaginationWhenGettingNamespaces()
31-
{
32-
$expectedArray = array(
33-
array('id' => 1, 'name' => 'bespokes'),
34-
array('id' => 2, 'name' => 'internal')
35-
);
36-
37-
$api = $this->getApiMock();
38-
$api->expects($this->once())
39-
->method('get')
40-
->with('namespaces', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE))
20+
->with('namespaces', array())
4121
->will($this->returnValue($expectedArray))
4222
;
4323

4424
$this->assertEquals($expectedArray, $api->all());
4525
}
46-
/**
47-
* @test
48-
*/
49-
public function shouldSearchNamespaces()
50-
{
51-
$expectedArray = array(
52-
array('id' => 1, 'name' => 'bespokes'),
53-
array('id' => 2, 'name' => 'internal')
54-
);
55-
56-
$api = $this->getApiMock();
57-
$api->expects($this->once())
58-
->method('get')
59-
->with('namespaces', array('search' => 'term', 'page' => 1, 'per_page' => 10))
60-
->will($this->returnValue($expectedArray))
61-
;
62-
63-
$this->assertEquals($expectedArray, $api->search('term', 1, 10));
64-
}
6526

6627
protected function getApiClass()
6728
{

0 commit comments

Comments
 (0)