Skip to content

Commit f3c4d8f

Browse files
Jakub Nowakm1guelpf
authored andcommitted
Added tests for impersonation tokens filter
1 parent 773c755 commit f3c4d8f

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

lib/Gitlab/Api/Users.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public function email($id)
260260
* @param array $params
261261
* @return mixed
262262
*/
263-
public function userImpersonationTokens($user_id, $params = [])
263+
public function userImpersonationTokens($user_id, array $params = [])
264264
{
265265
if (count($params)) {
266266
$resolver = $this->createOptionsResolver();
@@ -270,7 +270,7 @@ public function userImpersonationTokens($user_id, $params = [])
270270
;
271271
}
272272

273-
return $this->get('users/'.$this->encodePath($user_id).'/impersonation_tokens', $resolver->resolve($params));
273+
return $this->get('users/'.$this->encodePath($user_id).'/impersonation_tokens', count($params) ? $resolver->resolve($params) : []);
274274
}
275275

276276
/**

test/Gitlab/Tests/Api/UsersTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,44 @@ public function shouldDeleteImpersonationTokenForUser()
477477
$this->assertEquals($expectedBool, $api->removeImpersonationToken(1, 1));
478478
}
479479

480+
/**
481+
* @test
482+
*/
483+
public function shouldGetCurrentUserActiveImpersonationTokens()
484+
{
485+
$expectedArray = array(
486+
array('id' => 1, 'name' => 'A Name', 'revoked' => true),
487+
);
488+
489+
$api = $this->getApiMock();
490+
$api->expects($this->once())
491+
->method('get')
492+
->with('users/1/impersonation_tokens')
493+
->will($this->returnValue($expectedArray))
494+
;
495+
496+
$this->assertEquals($expectedArray, $api->userImpersonationTokens(1, ['state' => 'active']));
497+
}
498+
499+
/**
500+
* @test
501+
*/
502+
public function shouldGetCurrentUserInactiveImpersonationTokens()
503+
{
504+
$expectedArray = array(
505+
array('id' => 2, 'name' => 'A Name', 'revoked' => false),
506+
);
507+
508+
$api = $this->getApiMock();
509+
$api->expects($this->once())
510+
->method('get')
511+
->with('users/1/impersonation_tokens')
512+
->will($this->returnValue($expectedArray))
513+
;
514+
515+
$this->assertEquals($expectedArray, $api->userImpersonationTokens(1, ['state' => 'inactive']));
516+
}
517+
480518
protected function getApiClass()
481519
{
482520
return 'Gitlab\Api\Users';

0 commit comments

Comments
 (0)