Added db test for ApiKeyRepository

This commit is contained in:
Alejandro Celaya
2022-09-11 12:18:04 +02:00
parent 0e54ed691d
commit eed7b6e565
2 changed files with 32 additions and 0 deletions

View File

@@ -92,6 +92,7 @@
"ShlinkioCliTest\\Shlink\\CLI\\": "module/CLI/test-cli",
"ShlinkioTest\\Shlink\\Rest\\": "module/Rest/test",
"ShlinkioApiTest\\Shlink\\Rest\\": "module/Rest/test-api",
"ShlinkioDbTest\\Shlink\\Rest\\": "module/Rest/test-db",
"ShlinkioTest\\Shlink\\Core\\": "module/Core/test",
"ShlinkioDbTest\\Shlink\\Core\\": "module/Core/test-db"
},

View File

@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace ShlinkioDbTest\Shlink\Rest\ApiKey\Repository;
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);
}
/** @test */
public function initialApiKeyIsCreatedOnlyOfNoApiKeysExistYet(): void
{
self::assertCount(0, $this->repo->findAll());
$this->repo->createInitialApiKey('initial_value');
self::assertCount(1, $this->repo->findAll());
self::assertCount(1, $this->repo->findBy(['key' => 'initial_value']));
$this->repo->createInitialApiKey('another_one');
self::assertCount(1, $this->repo->findAll());
self::assertCount(0, $this->repo->findBy(['key' => 'another_one']));
}
}