Added used API key to request

This commit is contained in:
Alejandro Celaya
2020-11-08 11:28:27 +01:00
parent 598f2d8622
commit 90551ff3bc
12 changed files with 87 additions and 44 deletions

View File

@@ -59,7 +59,10 @@ class ApiKeyServiceTest extends TestCase
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
self::assertFalse($this->service->check('12345'));
$result = $this->service->check('12345');
self::assertFalse($result->isValid());
self::assertSame($invalidKey, $result->apiKey());
}
public function provideInvalidApiKeys(): iterable
@@ -72,12 +75,17 @@ class ApiKeyServiceTest extends TestCase
/** @test */
public function checkReturnsTrueWhenConditionsAreFavorable(): void
{
$apiKey = new ApiKey();
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn(new ApiKey())
$repo->findOneBy(['key' => '12345'])->willReturn($apiKey)
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
self::assertTrue($this->service->check('12345'));
$result = $this->service->check('12345');
self::assertTrue($result->isValid());
self::assertSame($apiKey, $result->apiKey());
}
/** @test */