Created chainIpLocationResolver

This commit is contained in:
Alejandro Celaya
2018-11-11 13:18:21 +01:00
parent d152e2ef9a
commit fd6d180eba
47 changed files with 288 additions and 176 deletions

View File

@@ -57,7 +57,7 @@ class AuthenticateActionTest extends TestCase
public function properApiKeyReturnsTokenInResponse()
{
$this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->setId('5'))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'apiKey' => 'foo',
@@ -75,7 +75,7 @@ class AuthenticateActionTest extends TestCase
public function invalidApiKeyReturnsErrorResponse()
{
$this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->disable())
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'apiKey' => 'foo',

View File

@@ -56,7 +56,7 @@ class CreateShortUrlActionTest extends TestCase
->willReturn(
(new ShortUrl(''))->setShortCode('abc123')
)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
@@ -73,7 +73,7 @@ class CreateShortUrlActionTest extends TestCase
{
$this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'), Argument::cetera())
->willThrow(InvalidUrlException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
@@ -95,7 +95,7 @@ class CreateShortUrlActionTest extends TestCase
null,
'foo',
Argument::cetera()
)->willThrow(NonUniqueSlugException::class)->shouldBeCalledTimes(1);
)->willThrow(NonUniqueSlugException::class)->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',
@@ -113,7 +113,7 @@ class CreateShortUrlActionTest extends TestCase
{
$this->urlShortener->urlToShortCode(Argument::type(Uri::class), Argument::type('array'), Argument::cetera())
->willThrow(Exception::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar',

View File

@@ -43,7 +43,7 @@ class DeleteShortUrlActionTest extends TestCase
$resp = $this->action->handle(ServerRequestFactory::fromGlobals());
$this->assertEquals(204, $resp->getStatusCode());
$deleteByShortCode->shouldHaveBeenCalledTimes(1);
$deleteByShortCode->shouldHaveBeenCalledOnce();
}
/**
@@ -60,7 +60,7 @@ class DeleteShortUrlActionTest extends TestCase
$this->assertEquals($statusCode, $resp->getStatusCode());
$this->assertEquals($error, $payload['error']);
$deleteByShortCode->shouldHaveBeenCalledTimes(1);
$deleteByShortCode->shouldHaveBeenCalledOnce();
}
public function provideExceptions(): array

View File

@@ -45,7 +45,7 @@ class EditShortUrlTagsActionTest extends TestCase
{
$shortCode = 'abc123';
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')
@@ -61,7 +61,7 @@ class EditShortUrlTagsActionTest extends TestCase
{
$shortCode = 'abc123';
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willReturn(new ShortUrl(''))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')

View File

@@ -40,7 +40,7 @@ class ListShortUrlsActionTest extends TestCase
{
$page = 3;
$this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,
@@ -55,7 +55,7 @@ class ListShortUrlsActionTest extends TestCase
{
$page = 3;
$this->service->listShortUrls($page, null, [], null)->willThrow(Exception::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([
'page' => $page,

View File

@@ -40,7 +40,7 @@ class ResolveShortUrlActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request);
@@ -56,7 +56,7 @@ class ResolveShortUrlActionTest extends TestCase
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willReturn(
new ShortUrl('http://domain.com/foo/bar')
)->shouldBeCalledTimes(1);
)->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request);
@@ -71,7 +71,7 @@ class ResolveShortUrlActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request);
@@ -86,7 +86,7 @@ class ResolveShortUrlActionTest extends TestCase
{
$shortCode = 'abc123';
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(Exception::class)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request);

View File

@@ -39,7 +39,7 @@ class GetVisitsActionTest extends TestCase
{
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willReturn([])
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
$this->assertEquals(200, $response->getStatusCode());
@@ -53,7 +53,7 @@ class GetVisitsActionTest extends TestCase
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willThrow(
InvalidArgumentException::class
)->shouldBeCalledTimes(1);
)->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
$this->assertEquals(404, $response->getStatusCode());
@@ -67,7 +67,7 @@ class GetVisitsActionTest extends TestCase
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, Argument::type(DateRange::class))->willThrow(
Exception::class
)->shouldBeCalledTimes(1);
)->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode));
$this->assertEquals(500, $response->getStatusCode());
@@ -81,7 +81,7 @@ class GetVisitsActionTest extends TestCase
$shortCode = 'abc123';
$this->visitsTracker->info($shortCode, new DateRange(null, Chronos::parse('2016-01-01 00:00:00')))
->willReturn([])
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)

View File

@@ -37,7 +37,7 @@ class ApiKeyHeaderPluginTest extends TestCase
{
$apiKey = 'abc-ABC';
$check = $this->apiKeyService->check($apiKey)->willReturn(false);
$check->shouldBeCalledTimes(1);
$check->shouldBeCalledOnce();
$this->expectException(VerifyAuthenticationException::class);
$this->expectExceptionMessage('Provided API key does not exist or is invalid');
@@ -55,7 +55,7 @@ class ApiKeyHeaderPluginTest extends TestCase
$this->plugin->verify($this->createRequest($apiKey));
$check->shouldHaveBeenCalledTimes(1);
$check->shouldHaveBeenCalledOnce();
}
/**

View File

@@ -90,7 +90,7 @@ class AuthorizationHeaderPluginTest extends TestCase
$this->plugin->verify($request);
$jwtVerify->shouldHaveBeenCalledTimes(1);
$jwtVerify->shouldHaveBeenCalledOnce();
}
/**
@@ -107,7 +107,7 @@ class AuthorizationHeaderPluginTest extends TestCase
$this->plugin->verify($request);
$jwtVerify->shouldHaveBeenCalledTimes(1);
$jwtVerify->shouldHaveBeenCalledOnce();
}
/**
@@ -126,6 +126,6 @@ class AuthorizationHeaderPluginTest extends TestCase
$this->assertTrue($response->hasHeader(AuthorizationHeaderPlugin::HEADER_NAME));
$this->assertEquals('Bearer DEF-def', $response->getHeaderLine(AuthorizationHeaderPlugin::HEADER_NAME));
$jwtRefresh->shouldHaveBeenCalledTimes(1);
$jwtRefresh->shouldHaveBeenCalledOnce();
}
}

View File

@@ -64,7 +64,7 @@ class RequestToAuthPluginTest extends TestCase
$this->requestToPlugin->fromRequest($request);
$getPlugin->shouldHaveBeenCalledTimes(1);
$getPlugin->shouldHaveBeenCalledOnce();
}
public function provideHeaders(): array

View File

@@ -68,7 +68,7 @@ class AuthenticationMiddlewareTest extends TestCase
$this->middleware->process($request, $handler->reveal());
$handle->shouldHaveBeenCalledTimes(1);
$handle->shouldHaveBeenCalledOnce();
$fromRequest->shouldNotHaveBeenCalled();
}
@@ -116,7 +116,7 @@ class AuthenticationMiddlewareTest extends TestCase
'Expected one of the following authentication headers, but none were provided, ["%s"]',
implode('", "', RequestToHttpAuthPlugin::SUPPORTED_AUTH_HEADERS)
), $payload['message']);
$fromRequest->shouldHaveBeenCalledTimes(1);
$fromRequest->shouldHaveBeenCalledOnce();
}
public function provideExceptions(): array
@@ -150,8 +150,8 @@ class AuthenticationMiddlewareTest extends TestCase
$this->assertEquals('the_error', $payload['error']);
$this->assertEquals('the_message', $payload['message']);
$verify->shouldHaveBeenCalledTimes(1);
$fromRequest->shouldHaveBeenCalledTimes(1);
$verify->shouldHaveBeenCalledOnce();
$fromRequest->shouldHaveBeenCalledOnce();
}
/**
@@ -176,10 +176,10 @@ class AuthenticationMiddlewareTest extends TestCase
$response = $this->middleware->process($request, $handler->reveal());
$this->assertSame($response, $newResponse);
$verify->shouldHaveBeenCalledTimes(1);
$update->shouldHaveBeenCalledTimes(1);
$handle->shouldHaveBeenCalledTimes(1);
$fromRequest->shouldHaveBeenCalledTimes(1);
$verify->shouldHaveBeenCalledOnce();
$update->shouldHaveBeenCalledOnce();
$handle->shouldHaveBeenCalledOnce();
$fromRequest->shouldHaveBeenCalledOnce();
}
private function getDummyMiddleware(): MiddlewareInterface

View File

@@ -38,7 +38,7 @@ class BodyParserMiddlewareTest extends TestCase
$this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1);
$process->shouldHaveBeenCalledOnce();
}
/**
@@ -70,7 +70,7 @@ class BodyParserMiddlewareTest extends TestCase
$this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1);
$process->shouldHaveBeenCalledOnce();
}
/**
@@ -101,6 +101,6 @@ class BodyParserMiddlewareTest extends TestCase
$this->middleware->process($request, $delegate->reveal());
$process->shouldHaveBeenCalledTimes(1);
$process->shouldHaveBeenCalledOnce();
}
}

View File

@@ -34,7 +34,7 @@ class CrossDomainMiddlewareTest extends TestCase
public function nonCrossDomainRequestsAreNotAffected()
{
$originalResponse = new Response();
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1);
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce();
$response = $this->middleware->process(ServerRequestFactory::fromGlobals(), $this->delegate->reveal());
$this->assertSame($originalResponse, $response);
@@ -50,7 +50,7 @@ class CrossDomainMiddlewareTest extends TestCase
public function anyRequestIncludesTheAllowAccessHeader()
{
$originalResponse = new Response();
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1);
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce();
$response = $this->middleware->process(
ServerRequestFactory::fromGlobals()->withHeader('Origin', 'local'),
@@ -70,7 +70,7 @@ class CrossDomainMiddlewareTest extends TestCase
{
$originalResponse = new Response();
$request = ServerRequestFactory::fromGlobals()->withMethod('OPTIONS')->withHeader('Origin', 'local');
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldbeCalledTimes(1);
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce();
$response = $this->middleware->process($request, $this->delegate->reveal());
$this->assertNotSame($originalResponse, $response);

View File

@@ -45,6 +45,6 @@ class ShortCodePathMiddlewareTest extends TestCase
$this->middleware->process($request->reveal(), $this->requestHandler->reveal());
$withUri->shouldHaveBeenCalledTimes(1);
$withUri->shouldHaveBeenCalledOnce();
}
}

View File

@@ -34,8 +34,8 @@ class ApiKeyServiceTest extends TestCase
*/
public function keyIsProperlyCreated()
{
$this->em->flush()->shouldBeCalledTimes(1);
$this->em->persist(Argument::type(ApiKey::class))->shouldBeCalledTimes(1);
$this->em->flush()->shouldBeCalledOnce();
$this->em->persist(Argument::type(ApiKey::class))->shouldBeCalledOnce();
$key = $this->service->create();
$this->assertNull($key->getExpirationDate());
@@ -46,8 +46,8 @@ class ApiKeyServiceTest extends TestCase
*/
public function keyIsProperlyCreatedWithExpirationDate()
{
$this->em->flush()->shouldBeCalledTimes(1);
$this->em->persist(Argument::type(ApiKey::class))->shouldBeCalledTimes(1);
$this->em->flush()->shouldBeCalledOnce();
$this->em->persist(Argument::type(ApiKey::class))->shouldBeCalledOnce();
$date = Chronos::parse('2030-01-01');
$key = $this->service->create($date);
@@ -61,7 +61,7 @@ class ApiKeyServiceTest extends TestCase
{
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn(null)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->assertFalse($this->service->check('12345'));
@@ -76,7 +76,7 @@ class ApiKeyServiceTest extends TestCase
$key->disable();
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn($key)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->assertFalse($this->service->check('12345'));
@@ -90,7 +90,7 @@ class ApiKeyServiceTest extends TestCase
$key = new ApiKey(Chronos::now()->subDay());
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn($key)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->assertFalse($this->service->check('12345'));
@@ -103,7 +103,7 @@ class ApiKeyServiceTest extends TestCase
{
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn(new ApiKey())
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->assertTrue($this->service->check('12345'));
@@ -117,7 +117,7 @@ class ApiKeyServiceTest extends TestCase
{
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn(null)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->service->disable('12345');
@@ -131,10 +131,10 @@ class ApiKeyServiceTest extends TestCase
$key = new ApiKey();
$repo = $this->prophesize(EntityRepository::class);
$repo->findOneBy(['key' => '12345'])->willReturn($key)
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->em->flush()->shouldBeCalledTimes(1);
$this->em->flush()->shouldBeCalledOnce();
$this->assertTrue($key->isEnabled());
$returnedKey = $this->service->disable('12345');
@@ -149,7 +149,7 @@ class ApiKeyServiceTest extends TestCase
{
$repo = $this->prophesize(EntityRepository::class);
$repo->findBy([])->willReturn([])
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->service->listKeys();
@@ -162,7 +162,7 @@ class ApiKeyServiceTest extends TestCase
{
$repo = $this->prophesize(EntityRepository::class);
$repo->findBy(['enabled' => true])->willReturn([])
->shouldBeCalledTimes(1);
->shouldBeCalledOnce();
$this->em->getRepository(ApiKey::class)->willReturn($repo->reveal());
$this->service->listKeys(true);