Add method to check if an API exists for a given name

This commit is contained in:
Alejandro Celaya
2024-11-07 09:55:06 +01:00
parent 6f95acc202
commit 4c1ff72438
5 changed files with 46 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ use Cake\Chronos\Chronos;
use Doctrine\ORM\EntityManager;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
@@ -176,4 +177,15 @@ class ApiKeyServiceTest extends TestCase
yield 'first api key' => [ApiKey::create()];
yield 'existing api keys' => [null];
}
#[Test]
#[TestWith([0, false])]
#[TestWith([1, true])]
#[TestWith([27, true])]
public function existsWithNameCountsEntriesInRepository(int $count, bool $expected): void
{
$name = 'the_key';
$this->repo->expects($this->once())->method('count')->with(['name' => $name])->willReturn($count);
self::assertEquals($this->service->existsWithName($name), $expected);
}
}