mirror of
https://github.com/shlinkio/shlink.git
synced 2026-02-28 12:13:13 +08:00
Ensure auto-generated name API keys do not throw duplicated name
This commit is contained in:
@@ -78,7 +78,23 @@ class ApiKeyServiceTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function exceptionIsThrownWhileCreatingIfNameIsInUse(): void
|
||||
public function autoGeneratedNameIsRegeneratedIfAlreadyExists(): void
|
||||
{
|
||||
$callCount = 0;
|
||||
$this->repo->expects($this->exactly(3))->method('nameExists')->with(
|
||||
$this->isType('string'),
|
||||
)->willReturnCallback(function () use (&$callCount): bool {
|
||||
$callCount++;
|
||||
return $callCount < 3;
|
||||
});
|
||||
$this->em->expects($this->once())->method('flush');
|
||||
$this->em->expects($this->once())->method('persist')->with($this->isInstanceOf(ApiKey::class));
|
||||
|
||||
$this->service->create(ApiKeyMeta::create());
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function exceptionIsThrownWhileCreatingIfExplicitlyProvidedNameIsInUse(): void
|
||||
{
|
||||
$this->repo->expects($this->once())->method('nameExists')->with('the_name')->willReturn(true);
|
||||
$this->em->expects($this->never())->method('flush');
|
||||
|
||||
Reference in New Issue
Block a user