mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-22 08:56:42 -06:00
Add unit test for ApiKeyService::createInitial
This commit is contained in:
parent
b0ec0601c1
commit
ec839183e8
@ -15,6 +15,7 @@ use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Repository\ApiKeyRepositoryInterface;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
use Shlinkio\Shlink\Rest\Service\ApiKeyService;
|
||||
|
||||
@ -22,12 +23,12 @@ class ApiKeyServiceTest extends TestCase
|
||||
{
|
||||
private ApiKeyService $service;
|
||||
private MockObject & EntityManager $em;
|
||||
private MockObject & EntityRepository $repo;
|
||||
private MockObject & ApiKeyRepositoryInterface $repo;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->em = $this->createMock(EntityManager::class);
|
||||
$this->repo = $this->createMock(EntityRepository::class);
|
||||
$this->repo = $this->createMock(ApiKeyRepositoryInterface::class);
|
||||
$this->service = new ApiKeyService($this->em);
|
||||
}
|
||||
|
||||
@ -150,4 +151,21 @@ class ApiKeyServiceTest extends TestCase
|
||||
|
||||
self::assertEquals($expectedApiKeys, $result);
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideInitialApiKeys')]
|
||||
public function createInitialDelegatesToRepository(?ApiKey $apiKey): void
|
||||
{
|
||||
$this->repo->expects($this->once())->method('createInitialApiKey')->with('the_key')->willReturn($apiKey);
|
||||
$this->em->method('getRepository')->with(ApiKey::class)->willReturn($this->repo);
|
||||
|
||||
$result = $this->service->createInitial('the_key');
|
||||
|
||||
self::assertSame($result, $apiKey);
|
||||
}
|
||||
|
||||
public static function provideInitialApiKeys(): iterable
|
||||
{
|
||||
yield 'first api key' => [ApiKey::create()];
|
||||
yield 'existing api keys' => [null];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user