Skip to content

Commit 041a823

Browse files
mash1tradutopala
authored andcommitted
1 parent 8425a4b commit 041a823

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

lib/Gitlab/Api/Users.php

+17
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,21 @@ public function removeUserKey($user_id, $key_id)
207207
{
208208
return $this->delete('users/'.$this->encodePath($user_id).'/keys/'.$this->encodePath($key_id));
209209
}
210+
211+
/**
212+
* @return mixed
213+
*/
214+
public function emails()
215+
{
216+
return $this->get('user/emails');
217+
}
218+
219+
/**
220+
* @param $id
221+
* @return mixed
222+
*/
223+
public function email($id)
224+
{
225+
return $this->get('user/emails/'.$this->encodePath($id));
226+
}
210227
}

test/Gitlab/Tests/Api/UsersTest.php

+35
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,41 @@ public function shouldAttemptLogin()
417417
$this->assertEquals($expectedArray, $api->login('matt', 'password'));
418418
}
419419

420+
/**
421+
* @test
422+
*/
423+
public function shouldGetUserEmails()
424+
{
425+
$expectedArray = array(
426+
array('id' => 1, 'email' => '[email protected]'),
427+
array('id' => 2, 'email' => '[email protected]'),
428+
);
429+
430+
$api = $this->getApiMock();
431+
$api->expects($this->once())
432+
->method('get')
433+
->with('user/emails')
434+
->will($this->returnValue($expectedArray));
435+
436+
$this->assertEquals($expectedArray, $api->emails());
437+
}
438+
439+
/**
440+
* @test
441+
*/
442+
public function shouldGetSpecificUserEmail()
443+
{
444+
$expectedArray = array('id' => 1, 'email' => '[email protected]');
445+
446+
$api = $this->getApiMock();
447+
$api->expects($this->once())
448+
->method('get')
449+
->with('user/emails/1')
450+
->will($this->returnValue($expectedArray));
451+
452+
$this->assertEquals($expectedArray, $api->email(1));
453+
}
454+
420455
protected function getApiClass()
421456
{
422457
return 'Gitlab\Api\Users';

0 commit comments

Comments
 (0)