2022-09-11 05:18:04 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioDbTest\Shlink\Rest\ApiKey\Repository;
|
|
|
|
|
2023-02-09 13:42:18 -06:00
|
|
|
use PHPUnit\Framework\Attributes\Test;
|
2022-09-11 05:18:04 -05:00
|
|
|
use Shlinkio\Shlink\Rest\ApiKey\Repository\ApiKeyRepository;
|
|
|
|
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
|
|
|
use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase;
|
|
|
|
|
|
|
|
class ApiKeyRepositoryTest extends DatabaseTestCase
|
|
|
|
{
|
|
|
|
private ApiKeyRepository $repo;
|
|
|
|
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
$this->repo = $this->getEntityManager()->getRepository(ApiKey::class);
|
|
|
|
}
|
|
|
|
|
2023-02-09 13:42:18 -06:00
|
|
|
#[Test]
|
2022-09-11 05:18:04 -05:00
|
|
|
public function initialApiKeyIsCreatedOnlyOfNoApiKeysExistYet(): void
|
|
|
|
{
|
|
|
|
self::assertCount(0, $this->repo->findAll());
|
2023-09-21 02:29:59 -05:00
|
|
|
self::assertNotNull($this->repo->createInitialApiKey('initial_value'));
|
2022-09-11 05:18:04 -05:00
|
|
|
self::assertCount(1, $this->repo->findAll());
|
|
|
|
self::assertCount(1, $this->repo->findBy(['key' => 'initial_value']));
|
2023-09-21 02:29:59 -05:00
|
|
|
self::assertNull($this->repo->createInitialApiKey('another_one'));
|
2022-09-11 05:18:04 -05:00
|
|
|
self::assertCount(1, $this->repo->findAll());
|
|
|
|
self::assertCount(0, $this->repo->findBy(['key' => 'another_one']));
|
|
|
|
}
|
|
|
|
}
|