mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 01:33:11 +08:00
Fix merge conflicts
This commit is contained in:
@@ -6,7 +6,6 @@ namespace ShlinkioTest\Shlink\Rest\Service;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
@@ -15,6 +14,7 @@ use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
|
||||
use Shlinkio\Shlink\Core\Domain\Entity\Domain;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition;
|
||||
use Shlinkio\Shlink\Rest\ApiKey\Repository\ApiKeyRepositoryInterface;
|
||||
use Shlinkio\Shlink\Rest\Entity\ApiKey;
|
||||
use Shlinkio\Shlink\Rest\Service\ApiKeyService;
|
||||
|
||||
@@ -22,12 +22,12 @@ class ApiKeyServiceTest extends TestCase
|
||||
{
|
||||
private ApiKeyService $service;
|
||||
private MockObject & EntityManager $em;
|
||||
private MockObject & EntityRepository $repo;
|
||||
private MockObject & ApiKeyRepositoryInterface $repo;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->em = $this->createMock(EntityManager::class);
|
||||
$this->repo = $this->createMock(EntityRepository::class);
|
||||
$this->repo = $this->createMock(ApiKeyRepositoryInterface::class);
|
||||
$this->service = new ApiKeyService($this->em);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,9 @@ class ApiKeyServiceTest extends TestCase
|
||||
$this->em->expects($this->once())->method('flush');
|
||||
$this->em->expects($this->once())->method('persist')->with($this->isInstanceOf(ApiKey::class));
|
||||
|
||||
$key = $this->service->create($date, $name, ...$roles);
|
||||
$key = $this->service->create(
|
||||
ApiKeyMeta::fromParams(name: $name, expirationDate: $date, roleDefinitions: $roles),
|
||||
);
|
||||
|
||||
self::assertEquals($date, $key->getExpirationDate());
|
||||
self::assertEquals($name, $key->name());
|
||||
@@ -81,7 +83,9 @@ class ApiKeyServiceTest extends TestCase
|
||||
{
|
||||
yield 'non-existent api key' => [null];
|
||||
yield 'disabled api key' => [ApiKey::create()->disable()];
|
||||
yield 'expired api key' => [ApiKey::fromMeta(ApiKeyMeta::withExpirationDate(Chronos::now()->subDays(1)))];
|
||||
yield 'expired api key' => [
|
||||
ApiKey::fromMeta(ApiKeyMeta::fromParams(expirationDate: Chronos::now()->subDays(1))),
|
||||
];
|
||||
}
|
||||
|
||||
#[Test]
|
||||
@@ -144,8 +148,25 @@ class ApiKeyServiceTest extends TestCase
|
||||
$this->repo->expects($this->once())->method('findBy')->with(['enabled' => true])->willReturn($expectedApiKeys);
|
||||
$this->em->method('getRepository')->with(ApiKey::class)->willReturn($this->repo);
|
||||
|
||||
$result = $this->service->listKeys(true);
|
||||
$result = $this->service->listKeys(enabledOnly: true);
|
||||
|
||||
self::assertEquals($expectedApiKeys, $result);
|
||||
}
|
||||
|
||||
#[Test, DataProvider('provideInitialApiKeys')]
|
||||
public function createInitialDelegatesToRepository(?ApiKey $apiKey): void
|
||||
{
|
||||
$this->repo->expects($this->once())->method('createInitialApiKey')->with('the_key')->willReturn($apiKey);
|
||||
$this->em->method('getRepository')->with(ApiKey::class)->willReturn($this->repo);
|
||||
|
||||
$result = $this->service->createInitial('the_key');
|
||||
|
||||
self::assertSame($result, $apiKey);
|
||||
}
|
||||
|
||||
public static function provideInitialApiKeys(): iterable
|
||||
{
|
||||
yield 'first api key' => [ApiKey::create()];
|
||||
yield 'existing api keys' => [null];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user