mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Updated to coding standard v2.1
This commit is contained in:
@@ -25,7 +25,7 @@ class HealthActionTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function passResponseIsReturnedWhenConnectionSucceeds()
|
||||
public function passResponseIsReturnedWhenConnectionSucceeds(): void
|
||||
{
|
||||
$ping = $this->conn->ping()->willReturn(true);
|
||||
|
||||
@@ -45,7 +45,7 @@ class HealthActionTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function failResponseIsReturnedWhenConnectionFails()
|
||||
public function failResponseIsReturnedWhenConnectionFails(): void
|
||||
{
|
||||
$ping = $this->conn->ping()->willReturn(false);
|
||||
|
||||
@@ -65,7 +65,7 @@ class HealthActionTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function failResponseIsReturnedWhenConnectionThrowsException()
|
||||
public function failResponseIsReturnedWhenConnectionThrowsException(): void
|
||||
{
|
||||
$ping = $this->conn->ping()->willThrow(Exception::class);
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class CreateShortUrlActionTest extends TestCase
|
||||
$shorten = $this->urlShortener->urlToShortCode(
|
||||
Argument::type(Uri::class),
|
||||
Argument::type('array'),
|
||||
$expectedMeta
|
||||
$expectedMeta,
|
||||
)->willReturn($shortUrl);
|
||||
|
||||
$request = ServerRequestFactory::fromGlobals()->withParsedBody($body);
|
||||
|
||||
@@ -25,7 +25,7 @@ class DeleteShortUrlActionTest extends TestCase
|
||||
/** @test */
|
||||
public function emptyResponseIsReturnedIfProperlyDeleted(): void
|
||||
{
|
||||
$deleteByShortCode = $this->service->deleteByShortCode(Argument::any())->will(function () {
|
||||
$deleteByShortCode = $this->service->deleteByShortCode(Argument::any())->will(function (): void {
|
||||
});
|
||||
|
||||
$resp = $this->action->handle(new ServerRequest());
|
||||
|
||||
@@ -44,7 +44,7 @@ class EditShortUrlActionTest extends TestCase
|
||||
'maxVisits' => 5,
|
||||
]);
|
||||
$updateMeta = $this->shortUrlService->updateMetadataByShortCode(Argument::cetera())->willReturn(
|
||||
new ShortUrl('')
|
||||
new ShortUrl(''),
|
||||
);
|
||||
|
||||
$resp = $this->action->handle($request);
|
||||
|
||||
@@ -39,7 +39,7 @@ class EditShortUrlTagsActionTest extends TestCase
|
||||
|
||||
$response = $this->action->handle(
|
||||
(new ServerRequest())->withAttribute('shortCode', 'abc123')
|
||||
->withParsedBody(['tags' => []])
|
||||
->withParsedBody(['tags' => []]),
|
||||
);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class ListShortUrlsActionTest extends TestCase
|
||||
$expectedSearchTerm,
|
||||
$expectedTags,
|
||||
$expectedOrderBy,
|
||||
$expectedDateRange
|
||||
$expectedDateRange,
|
||||
)->willReturn(new Paginator(new ArrayAdapter()));
|
||||
|
||||
/** @var JsonResponse $response */
|
||||
|
||||
@@ -29,7 +29,7 @@ class ResolveShortUrlActionTest extends TestCase
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->urlShortener->shortCodeToUrl($shortCode, null)->willReturn(
|
||||
new ShortUrl('http://domain.com/foo/bar')
|
||||
new ShortUrl('http://domain.com/foo/bar'),
|
||||
)->shouldBeCalledOnce();
|
||||
|
||||
$request = (new ServerRequest())->withAttribute('shortCode', $shortCode);
|
||||
|
||||
@@ -34,7 +34,7 @@ class SingleStepCreateShortUrlActionTest extends TestCase
|
||||
[
|
||||
'schema' => 'http',
|
||||
'hostname' => 'foo.com',
|
||||
]
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ class SingleStepCreateShortUrlActionTest extends TestCase
|
||||
return $argument;
|
||||
}),
|
||||
[],
|
||||
ShortUrlMeta::createEmpty()
|
||||
ShortUrlMeta::createEmpty(),
|
||||
)->willReturn(new ShortUrl(''));
|
||||
|
||||
$resp = $this->action->handle($request);
|
||||
|
||||
@@ -25,7 +25,7 @@ class ListTagsActionTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function returnsDataFromService()
|
||||
public function returnsDataFromService(): void
|
||||
{
|
||||
$listTags = $this->tagService->listTags()->willReturn([new Tag('foo'), new Tag('bar')]);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class GetVisitsActionTest extends TestCase
|
||||
{
|
||||
$shortCode = 'abc123';
|
||||
$this->visitsTracker->info($shortCode, Argument::type(VisitsParams::class))->willReturn(
|
||||
new Paginator(new ArrayAdapter([]))
|
||||
new Paginator(new ArrayAdapter([])),
|
||||
)->shouldBeCalledOnce();
|
||||
|
||||
$response = $this->action->handle((new ServerRequest())->withAttribute('shortCode', $shortCode));
|
||||
@@ -46,7 +46,7 @@ class GetVisitsActionTest extends TestCase
|
||||
$this->visitsTracker->info($shortCode, new VisitsParams(
|
||||
new DateRange(null, Chronos::parse('2016-01-01 00:00:00')),
|
||||
3,
|
||||
10
|
||||
10,
|
||||
))
|
||||
->willReturn(new Paginator(new ArrayAdapter([])))
|
||||
->shouldBeCalledOnce();
|
||||
@@ -57,7 +57,7 @@ class GetVisitsActionTest extends TestCase
|
||||
'endDate' => '2016-01-01 00:00:00',
|
||||
'page' => '3',
|
||||
'itemsPerPage' => '10',
|
||||
])
|
||||
]),
|
||||
);
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class ApiKeyHeaderPluginTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function verifyThrowsExceptionWhenApiKeyIsNotValid()
|
||||
public function verifyThrowsExceptionWhenApiKeyIsNotValid(): void
|
||||
{
|
||||
$apiKey = 'abc-ABC';
|
||||
$check = $this->apiKeyService->check($apiKey)->willReturn(false);
|
||||
@@ -38,7 +38,7 @@ class ApiKeyHeaderPluginTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function verifyDoesNotThrowExceptionWhenApiKeyIsValid()
|
||||
public function verifyDoesNotThrowExceptionWhenApiKeyIsValid(): void
|
||||
{
|
||||
$apiKey = 'abc-ABC';
|
||||
$check = $this->apiKeyService->check($apiKey)->willReturn(true);
|
||||
@@ -49,7 +49,7 @@ class ApiKeyHeaderPluginTest extends TestCase
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function updateReturnsResponseAsIs()
|
||||
public function updateReturnsResponseAsIs(): void
|
||||
{
|
||||
$apiKey = 'abc-ABC';
|
||||
$response = new Response();
|
||||
|
||||
@@ -35,7 +35,7 @@ class RequestToAuthPluginTest extends TestCase
|
||||
$this->expectException(MissingAuthenticationException::class);
|
||||
$this->expectExceptionMessage(sprintf(
|
||||
'Expected one of the following authentication headers, ["%s"], but none were provided',
|
||||
implode('", "', RequestToHttpAuthPlugin::SUPPORTED_AUTH_HEADERS)
|
||||
implode('", "', RequestToHttpAuthPlugin::SUPPORTED_AUTH_HEADERS),
|
||||
));
|
||||
|
||||
$this->requestToPlugin->fromRequest($request);
|
||||
|
||||
@@ -56,11 +56,11 @@ class NotifyVisitToWebHooksTest extends TestCase
|
||||
$requestAsync = $this->httpClient->requestAsync(
|
||||
RequestMethodInterface::METHOD_POST,
|
||||
Argument::type('string'),
|
||||
Argument::type('array')
|
||||
Argument::type('array'),
|
||||
)->willReturn(new FulfilledPromise(''));
|
||||
$logWarning = $this->logger->warning(
|
||||
'Tried to notify webhooks for visit with id "{visitId}", but it does not exist.',
|
||||
['visitId' => '1']
|
||||
['visitId' => '1'],
|
||||
);
|
||||
|
||||
$this->createListener(['foo', 'bar'])(new VisitLocated('1'));
|
||||
@@ -90,7 +90,7 @@ class NotifyVisitToWebHooksTest extends TestCase
|
||||
Assert::assertArrayHasKey('visit', $requestOptions[RequestOptions::JSON]);
|
||||
|
||||
return $requestOptions;
|
||||
})
|
||||
}),
|
||||
)->will(function (array $args) use ($invalidWebhooks) {
|
||||
[, $webhook] = $args;
|
||||
$e = new Exception('');
|
||||
@@ -105,7 +105,7 @@ class NotifyVisitToWebHooksTest extends TestCase
|
||||
Assert::assertArrayHasKey('e', $extra);
|
||||
|
||||
return $extra;
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
$this->createListener($webhooks)(new VisitLocated('1'));
|
||||
@@ -123,7 +123,7 @@ class NotifyVisitToWebHooksTest extends TestCase
|
||||
$this->logger->reveal(),
|
||||
$webhooks,
|
||||
[],
|
||||
new AppOptions(['name' => 'Shlink', 'version' => '1.2.3'])
|
||||
new AppOptions(['name' => 'Shlink', 'version' => '1.2.3']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ class MissingAuthenticationExceptionTest extends TestCase
|
||||
{
|
||||
$expectedMessage = sprintf(
|
||||
'Expected one of the following authentication headers, ["%s"], but none were provided',
|
||||
implode('", "', $expectedTypes)
|
||||
implode('", "', $expectedTypes),
|
||||
);
|
||||
|
||||
$e = MissingAuthenticationException::fromExpectedTypes($expectedTypes);
|
||||
|
||||
@@ -38,7 +38,7 @@ class AuthenticationMiddlewareTest extends TestCase
|
||||
$this->middleware = new AuthenticationMiddleware(
|
||||
$this->requestToPlugin->reveal(),
|
||||
[HealthAction::class],
|
||||
$this->logger->reveal()
|
||||
$this->logger->reveal(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class AuthenticationMiddlewareTest extends TestCase
|
||||
$handler = $this->prophesize(RequestHandlerInterface::class);
|
||||
$handle = $handler->handle($request)->willReturn(new Response());
|
||||
$fromRequest = $this->requestToPlugin->fromRequest(Argument::any())->willReturn(
|
||||
$this->prophesize(AuthenticationPluginInterface::class)->reveal()
|
||||
$this->prophesize(AuthenticationPluginInterface::class)->reveal(),
|
||||
);
|
||||
|
||||
$this->middleware->process($request, $handler->reveal());
|
||||
@@ -67,17 +67,17 @@ class AuthenticationMiddlewareTest extends TestCase
|
||||
yield 'with no route result' => [new ServerRequest()];
|
||||
yield 'with failure route result' => [(new ServerRequest())->withAttribute(
|
||||
RouteResult::class,
|
||||
RouteResult::fromRouteFailure([RequestMethodInterface::METHOD_GET])
|
||||
RouteResult::fromRouteFailure([RequestMethodInterface::METHOD_GET]),
|
||||
)];
|
||||
yield 'with whitelisted route' => [(new ServerRequest())->withAttribute(
|
||||
RouteResult::class,
|
||||
RouteResult::fromRoute(
|
||||
new Route('foo', $dummyMiddleware, Route::HTTP_METHOD_ANY, HealthAction::class)
|
||||
)
|
||||
new Route('foo', $dummyMiddleware, Route::HTTP_METHOD_ANY, HealthAction::class),
|
||||
),
|
||||
)];
|
||||
yield 'with OPTIONS method' => [(new ServerRequest())->withAttribute(
|
||||
RouteResult::class,
|
||||
RouteResult::fromRoute(new Route('bar', $dummyMiddleware), [])
|
||||
RouteResult::fromRoute(new Route('bar', $dummyMiddleware), []),
|
||||
)->withMethod(RequestMethodInterface::METHOD_OPTIONS)];
|
||||
}
|
||||
|
||||
@@ -87,11 +87,11 @@ class AuthenticationMiddlewareTest extends TestCase
|
||||
$newResponse = new Response();
|
||||
$request = (new ServerRequest())->withAttribute(
|
||||
RouteResult::class,
|
||||
RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), [])
|
||||
RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), []),
|
||||
);
|
||||
$plugin = $this->prophesize(AuthenticationPluginInterface::class);
|
||||
|
||||
$verify = $plugin->verify($request)->will(function () {
|
||||
$verify = $plugin->verify($request)->will(function (): void {
|
||||
});
|
||||
$update = $plugin->update($request, Argument::type(ResponseInterface::class))->willReturn($newResponse);
|
||||
$fromRequest = $this->requestToPlugin->fromRequest(Argument::any())->willReturn($plugin->reveal());
|
||||
|
||||
@@ -90,7 +90,7 @@ class BodyParserMiddlewareTest extends TestCase
|
||||
], $req->getParsedBody());
|
||||
|
||||
return new Response();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
$this->middleware->process($request, $delegate->reveal());
|
||||
@@ -118,7 +118,7 @@ class BodyParserMiddlewareTest extends TestCase
|
||||
], $req->getParsedBody());
|
||||
|
||||
return new Response();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
$this->middleware->process($request, $delegate->reveal());
|
||||
|
||||
@@ -54,7 +54,7 @@ class CrossDomainMiddlewareTest extends TestCase
|
||||
|
||||
$response = $this->middleware->process(
|
||||
(new ServerRequest())->withHeader('Origin', 'local'),
|
||||
$this->handler->reveal()
|
||||
$this->handler->reveal(),
|
||||
);
|
||||
$this->assertNotSame($originalResponse, $response);
|
||||
|
||||
@@ -63,7 +63,7 @@ class CrossDomainMiddlewareTest extends TestCase
|
||||
$this->assertEquals('local', $response->getHeaderLine('Access-Control-Allow-Origin'));
|
||||
$this->assertEquals(
|
||||
Authentication\Plugin\ApiKeyHeaderPlugin::HEADER_NAME,
|
||||
$response->getHeaderLine('Access-Control-Expose-Headers')
|
||||
$response->getHeaderLine('Access-Control-Expose-Headers'),
|
||||
);
|
||||
$this->assertArrayNotHasKey('Access-Control-Allow-Methods', $headers);
|
||||
$this->assertArrayNotHasKey('Access-Control-Max-Age', $headers);
|
||||
@@ -88,7 +88,7 @@ class CrossDomainMiddlewareTest extends TestCase
|
||||
$this->assertEquals('local', $response->getHeaderLine('Access-Control-Allow-Origin'));
|
||||
$this->assertEquals(
|
||||
Authentication\Plugin\ApiKeyHeaderPlugin::HEADER_NAME,
|
||||
$response->getHeaderLine('Access-Control-Expose-Headers')
|
||||
$response->getHeaderLine('Access-Control-Expose-Headers'),
|
||||
);
|
||||
$this->assertArrayHasKey('Access-Control-Allow-Methods', $headers);
|
||||
$this->assertEquals('1000', $response->getHeaderLine('Access-Control-Max-Age'));
|
||||
@@ -120,8 +120,8 @@ class CrossDomainMiddlewareTest extends TestCase
|
||||
yield 'with failed route result' => [RouteResult::fromRouteFailure(['POST', 'GET']), 'POST,GET'];
|
||||
yield 'with success route result' => [
|
||||
RouteResult::fromRoute(
|
||||
new Route('/', middleware(function () {
|
||||
}), ['DELETE', 'PATCH', 'PUT'])
|
||||
new Route('/', middleware(function (): void {
|
||||
}), ['DELETE', 'PATCH', 'PUT']),
|
||||
),
|
||||
'DELETE,PATCH,PUT',
|
||||
];
|
||||
|
||||
@@ -49,7 +49,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase
|
||||
}
|
||||
|
||||
$handle = $this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn(
|
||||
new JsonResponse(['shortUrl' => 'http://doma.in/foo'])
|
||||
new JsonResponse(['shortUrl' => 'http://doma.in/foo']),
|
||||
);
|
||||
|
||||
$response = $this->middleware->process($request, $this->requestHandler->reveal());
|
||||
@@ -80,7 +80,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase
|
||||
$request = (new ServerRequest())->withQueryParams(['format' => 'txt']);
|
||||
|
||||
$handle = $this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn(
|
||||
new JsonResponse($json)
|
||||
new JsonResponse($json),
|
||||
);
|
||||
|
||||
$response = $this->middleware->process($request, $this->requestHandler->reveal());
|
||||
|
||||
@@ -16,10 +16,8 @@ use Shlinkio\Shlink\Rest\Service\ApiKeyService;
|
||||
|
||||
class ApiKeyServiceTest extends TestCase
|
||||
{
|
||||
/** @var ApiKeyService */
|
||||
private $service;
|
||||
/** @var ObjectProphecy */
|
||||
private $em;
|
||||
private ApiKeyService $service;
|
||||
private ObjectProphecy $em;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user