repo = $this->getEntityManager()->getRepository(ApiKey::class); } #[Test] public function initialApiKeyIsCreatedOnlyOfNoApiKeysExistYet(): void { self::assertCount(0, $this->repo->findAll()); self::assertNotNull($this->repo->createInitialApiKey('initial_value')); self::assertCount(1, $this->repo->findAll()); self::assertCount(1, $this->repo->findBy(['key' => ApiKey::hashKey('initial_value')])); self::assertNull($this->repo->createInitialApiKey('another_one')); 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')); } }