Skip to content

Commit

Permalink
Project sorting tests and saving group member test
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Humphrey committed Feb 23, 2015
1 parent eadb8d7 commit fde7d55
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
36 changes: 35 additions & 1 deletion test/Gitlab/Tests/Api/GroupsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,30 @@ public function shouldCreateGroup()
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('groups', array('name' => 'A new group', 'path' => 'a-new-group'))
->with('groups', array('name' => 'A new group', 'path' => 'a-new-group', 'description' => null))
->will($this->returnValue($expectedArray))
;

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

/**
* @test
*/
public function shouldCreateGroupWithDescription()
{
$expectedArray = array('id' => 1, 'name' => 'A new group');

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('groups', array('name' => 'A new group', 'path' => 'a-new-group', 'description' => 'Description'))
->will($this->returnValue($expectedArray))
;

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

/**
* @test
*/
Expand Down Expand Up @@ -132,6 +149,23 @@ public function shouldAddMember()
$this->assertEquals($expectedArray, $api->addMember(1, 2, 3));
}

/**
* @test
*/
public function shouldSaveMember()
{
$expectedArray = array('id' => 1, 'name' => 'Matt');

$api = $this->getApiMock();
$api->expects($this->once())
->method('put')
->with('groups/1/members/2', array('access_level' => 4))
->will($this->returnValue($expectedArray))
;

$this->assertEquals($expectedArray, $api->saveMember(1, 2, 4));
}

/**
* @test
*/
Expand Down
23 changes: 18 additions & 5 deletions test/Gitlab/Tests/Api/ProjectsTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace Gitlab\Tests\Api;

use Gitlab\Api\AbstractApi;
use Gitlab\Api\Projects;

class ProjectsTest extends TestCase
{
Expand All @@ -13,7 +14,19 @@ public function shouldGetAllProjects()

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

$this->assertEquals($expectedArray, $api->all(1, 10));
$this->assertEquals($expectedArray, $api->all());
}

/**
* @test
*/
public function shouldGetAllProjectsSortedByName()
{
$expectedArray = $this->getMultipleProjectsData();

$api = $this->getMultipleProjectsRequestMock('projects/all', $expectedArray, 1, 5, 'name', 'asc');

$this->assertEquals($expectedArray, $api->all(1, 5, 'name'));
}

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

Expand Down Expand Up @@ -66,7 +79,7 @@ public function shouldSearchProjects()

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

$this->assertEquals($expectedArray, $api->search('a project', 1, 10));
$this->assertEquals($expectedArray, $api->search('a project'));
}

/**
Expand Down Expand Up @@ -703,12 +716,12 @@ public function shouldRemoveService()
$this->assertEquals($expectedBool, $api->removeService(1, 'hipchat'));
}

protected function getMultipleProjectsRequestMock($path, $expectedArray = array(), $page = 1, $per_page = 10)
protected function getMultipleProjectsRequestMock($path, $expectedArray = array(), $page = 1, $per_page = 20, $order_by = 'created_at', $sort = 'asc')
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with($path, array('page' => $page, 'per_page' => $per_page))
->with($path, array('page' => $page, 'per_page' => $per_page, 'order_by' => $order_by, 'sort' => $sort))
->will($this->returnValue($expectedArray))
;

Expand Down

0 comments on commit fde7d55

Please sign in to comment.