mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Added method to ApiKeyService to list api keys
This commit is contained in:
parent
74777c2234
commit
dd1bc49b79
3 changed files with 46 additions and 0 deletions
|
@ -82,4 +82,16 @@ class ApiKeyService implements ApiKeyServiceInterface
|
|||
$this->em->flush();
|
||||
return $apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all existing appi keys
|
||||
*
|
||||
* @param bool $enabledOnly Tells if only enabled keys should be returned
|
||||
* @return ApiKey[]
|
||||
*/
|
||||
public function listKeys($enabledOnly = false)
|
||||
{
|
||||
$conditions = $enabledOnly ? ['enabled' => true] : [];
|
||||
return $this->em->getRepository(ApiKey::class)->findBy($conditions);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,4 +28,12 @@ interface ApiKeyServiceInterface
|
|||
* @return ApiKey
|
||||
*/
|
||||
public function disable($key);
|
||||
|
||||
/**
|
||||
* Lists all existing appi keys
|
||||
*
|
||||
* @param bool $enabledOnly Tells if only enabled keys should be returned
|
||||
* @return ApiKey[]
|
||||
*/
|
||||
public function listKeys($enabledOnly = false);
|
||||
}
|
||||
|
|
|
@ -139,4 +139,30 @@ class ApiKeyServiceTest extends TestCase
|
|||
$this->assertFalse($key->isEnabled());
|
||||
$this->assertSame($key, $returnedKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function listFindsAllApiKeys()
|
||||
{
|
||||
$repo = $this->prophesize(EntityRepository::class);
|
||||
$repo->findBy([])->willReturn([])
|
||||
->shouldBeCalledTimes(1);
|
||||
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
|
||||
|
||||
$this->service->listKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function listEnabledFindsOnlyEnabledApiKeys()
|
||||
{
|
||||
$repo = $this->prophesize(EntityRepository::class);
|
||||
$repo->findBy(['enabled' => true])->willReturn([])
|
||||
->shouldBeCalledTimes(1);
|
||||
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
|
||||
|
||||
$this->service->listKeys(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue