Skip to content

Commit 64d7ab8

Browse files
omarlopesinom1guelpf
authored andcommitted
Add method to obtain project users
1 parent 49bf790 commit 64d7ab8

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/Gitlab/Api/Projects.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,24 @@ public function hook($project_id, $hook_id)
386386
return $this->get($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)));
387387
}
388388

389+
/**
390+
* Get project users.
391+
*
392+
* See https://docs.gitlab.com/ee/api/projects.html#get-project-users for more info.
393+
*
394+
* @param int $project_id
395+
* Project id.
396+
* @param array $parameters
397+
* Url parameters.
398+
*
399+
* @return array
400+
* List of project users.
401+
*/
402+
public function users($project_id, array $parameters = [])
403+
{
404+
return $this->get($this->getProjectPath($project_id, 'users'), $parameters);
405+
}
406+
389407
/**
390408
* Get project issues.
391409
*

test/Gitlab/Tests/Api/ProjectsTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,24 @@ public function shouldGetProjectIssues()
287287
$this->assertEquals($expectedArray, $api->issues(1));
288288
}
289289

290+
/**
291+
* Check we can request project issues.
292+
*
293+
* @test
294+
*/
295+
public function shouldGetProjectUsers()
296+
{
297+
$expectedArray = $this->getProjectUsersExpectedArray();
298+
299+
$api = $this->getApiMock();
300+
$api->expects($this->once())
301+
->method('get')
302+
->with('projects/1/users')
303+
->will($this->returnValue($expectedArray));
304+
305+
$this->assertEquals($expectedArray, $api->users(1));
306+
}
307+
290308
/**
291309
* Check we can request project issues with query parameters.
292310
*
@@ -379,6 +397,24 @@ public function getProjectIssuesExpectedArray()
379397
];
380398
}
381399

400+
/**
401+
* Get expected array for tests which check project users method.
402+
*
403+
* @return array
404+
*/
405+
public function getProjectUsersExpectedArray() {
406+
return [
407+
[
408+
'id' => 1,
409+
'name' => 'John Doe',
410+
'username' => 'john.doe',
411+
'state' => 'active',
412+
'avatar_url' => 'https://example.com',
413+
'web_url' => 'gitlab.com/john.doe',
414+
],
415+
];
416+
}
417+
382418
/**
383419
* @test
384420
*/

0 commit comments

Comments
 (0)