mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 15:23:12 +08:00
Lock transaction to avoid race conditions when renaming an API key
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace ShlinkioDbTest\Shlink\Rest\ApiKey\Repository;
|
||||
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Repository\ApiKeyRepository;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
use Shlinkio\Shlink\TestUtils\DbTest\DatabaseTestCase;
|
||||
@@ -29,4 +30,14 @@ class ApiKeyRepositoryTest extends DatabaseTestCase
|
||||
self::assertCount(1, $this->repo->findAll());
|
||||
self::assertCount(0, $this->repo->findBy(['key' => ApiKey::hashKey('another_one')]));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function nameExistsReturnsExpectedResult(): void
|
||||
{
|
||||
$this->getEntityManager()->persist(ApiKey::fromMeta(ApiKeyMeta::fromParams(name: 'foo')));
|
||||
$this->getEntityManager()->flush();
|
||||
|
||||
self::assertTrue($this->repo->nameExists('foo'));
|
||||
self::assertFalse($this->repo->nameExists('bar'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user