Skip to content

Commit fde7d55

Browse files
author
Matt Humphrey
committed
Project sorting tests and saving group member test
1 parent eadb8d7 commit fde7d55

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

test/Gitlab/Tests/Api/GroupsTest.php

+35-1
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,30 @@ public function shouldCreateGroup()
7171
$api = $this->getApiMock();
7272
$api->expects($this->once())
7373
->method('post')
74-
->with('groups', array('name' => 'A new group', 'path' => 'a-new-group'))
74+
->with('groups', array('name' => 'A new group', 'path' => 'a-new-group', 'description' => null))
7575
->will($this->returnValue($expectedArray))
7676
;
7777

7878
$this->assertEquals($expectedArray, $api->create('A new group', 'a-new-group'));
7979
}
8080

81+
/**
82+
* @test
83+
*/
84+
public function shouldCreateGroupWithDescription()
85+
{
86+
$expectedArray = array('id' => 1, 'name' => 'A new group');
87+
88+
$api = $this->getApiMock();
89+
$api->expects($this->once())
90+
->method('post')
91+
->with('groups', array('name' => 'A new group', 'path' => 'a-new-group', 'description' => 'Description'))
92+
->will($this->returnValue($expectedArray))
93+
;
94+
95+
$this->assertEquals($expectedArray, $api->create('A new group', 'a-new-group', 'Description'));
96+
}
97+
8198
/**
8299
* @test
83100
*/
@@ -132,6 +149,23 @@ public function shouldAddMember()
132149
$this->assertEquals($expectedArray, $api->addMember(1, 2, 3));
133150
}
134151

152+
/**
153+
* @test
154+
*/
155+
public function shouldSaveMember()
156+
{
157+
$expectedArray = array('id' => 1, 'name' => 'Matt');
158+
159+
$api = $this->getApiMock();
160+
$api->expects($this->once())
161+
->method('put')
162+
->with('groups/1/members/2', array('access_level' => 4))
163+
->will($this->returnValue($expectedArray))
164+
;
165+
166+
$this->assertEquals($expectedArray, $api->saveMember(1, 2, 4));
167+
}
168+
135169
/**
136170
* @test
137171
*/

test/Gitlab/Tests/Api/ProjectsTest.php

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php namespace Gitlab\Tests\Api;
22

33
use Gitlab\Api\AbstractApi;
4+
use Gitlab\Api\Projects;
45

56
class ProjectsTest extends TestCase
67
{
@@ -13,7 +14,19 @@ public function shouldGetAllProjects()
1314

1415
$api = $this->getMultipleProjectsRequestMock('projects/all', $expectedArray);
1516

16-
$this->assertEquals($expectedArray, $api->all(1, 10));
17+
$this->assertEquals($expectedArray, $api->all());
18+
}
19+
20+
/**
21+
* @test
22+
*/
23+
public function shouldGetAllProjectsSortedByName()
24+
{
25+
$expectedArray = $this->getMultipleProjectsData();
26+
27+
$api = $this->getMultipleProjectsRequestMock('projects/all', $expectedArray, 1, 5, 'name', 'asc');
28+
29+
$this->assertEquals($expectedArray, $api->all(1, 5, 'name'));
1730
}
1831

1932
/**
@@ -26,7 +39,7 @@ public function shouldNotNeedPaginationWhenGettingProjects()
2639
$api = $this->getApiMock();
2740
$api->expects($this->once())
2841
->method('get')
29-
->with('projects/all', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE))
42+
->with('projects/all', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE, 'order_by' => Projects::ORDER_BY, 'sort' => Projects::SORT))
3043
->will($this->returnValue($expectedArray))
3144
;
3245

@@ -66,7 +79,7 @@ public function shouldSearchProjects()
6679

6780
$api = $this->getMultipleProjectsRequestMock('projects/search/a+project', $expectedArray);
6881

69-
$this->assertEquals($expectedArray, $api->search('a project', 1, 10));
82+
$this->assertEquals($expectedArray, $api->search('a project'));
7083
}
7184

7285
/**
@@ -703,12 +716,12 @@ public function shouldRemoveService()
703716
$this->assertEquals($expectedBool, $api->removeService(1, 'hipchat'));
704717
}
705718

706-
protected function getMultipleProjectsRequestMock($path, $expectedArray = array(), $page = 1, $per_page = 10)
719+
protected function getMultipleProjectsRequestMock($path, $expectedArray = array(), $page = 1, $per_page = 20, $order_by = 'created_at', $sort = 'asc')
707720
{
708721
$api = $this->getApiMock();
709722
$api->expects($this->once())
710723
->method('get')
711-
->with($path, array('page' => $page, 'per_page' => $per_page))
724+
->with($path, array('page' => $page, 'per_page' => $per_page, 'order_by' => $order_by, 'sort' => $sort))
712725
->will($this->returnValue($expectedArray))
713726
;
714727

0 commit comments

Comments
 (0)