From 32070b1fa706f0aed9c25563852294fcbd996542 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 25 Dec 2018 23:01:30 +0100 Subject: [PATCH] Do not use ServerRequestFactory::fromGlobals in tests --- .../CloseDbConnectionMiddlewareTest.php | 4 ++-- .../test/Middleware/LocaleMiddlewareTest.php | 8 ++++---- module/Core/test/Action/PixelActionTest.php | 4 ++-- module/Core/test/Action/PreviewActionTest.php | 11 ++++------ module/Core/test/Action/QrCodeActionTest.php | 14 ++++--------- .../Core/test/Action/RedirectActionTest.php | 10 +++++----- .../Middleware/QrCodeCacheMiddlewareTest.php | 11 +++------- .../test/Response/NotFoundHandlerTest.php | 4 ++-- .../test/Action/AuthenticateActionTest.php | 8 ++++---- .../ShortUrl/CreateShortUrlActionTest.php | 12 +++++------ .../ShortUrl/DeleteShortUrlActionTest.php | 6 +++--- .../ShortUrl/EditShortUrlActionTest.php | 20 +++++++++---------- .../ShortUrl/EditShortUrlTagsActionTest.php | 12 +++++------ .../ShortUrl/ListShortUrlsActionTest.php | 6 +++--- .../ShortUrl/ResolveShortUrlActionTest.php | 10 +++++----- .../SingleStepCreateShortUrlActionTest.php | 8 ++++---- .../test/Action/Tag/CreateTagsActionTest.php | 4 ++-- .../test/Action/Tag/DeleteTagsActionTest.php | 4 ++-- .../test/Action/Tag/ListTagsActionTest.php | 4 ++-- .../test/Action/Tag/UpdateTagActionTest.php | 8 ++++---- .../test/Action/Visit/GetVisitsActionTest.php | 18 ++++++++--------- .../Plugin/ApiKeyHeaderPluginTest.php | 4 ++-- .../Plugin/AuthorizationHeaderPluginTest.php | 12 +++++------ .../RequestToAuthPluginTest.php | 6 +++--- .../JsonErrorResponseGeneratorTest.php | 6 +++--- .../AuthenticationMiddlewareTest.php | 16 +++++++-------- .../Middleware/BodyParserMiddlewareTest.php | 14 ++++++------- .../Middleware/CrossDomainMiddlewareTest.php | 8 ++++---- .../Middleware/PathVersionMiddlewareTest.php | 6 +++--- ...ortUrlContentNegotiationMiddlewareTest.php | 8 ++++---- 30 files changed, 126 insertions(+), 140 deletions(-) diff --git a/module/Common/test/Middleware/CloseDbConnectionMiddlewareTest.php b/module/Common/test/Middleware/CloseDbConnectionMiddlewareTest.php index 36bdff87..35cd6fe0 100644 --- a/module/Common/test/Middleware/CloseDbConnectionMiddlewareTest.php +++ b/module/Common/test/Middleware/CloseDbConnectionMiddlewareTest.php @@ -10,7 +10,7 @@ use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Common\Middleware\CloseDbConnectionMiddleware; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class CloseDbConnectionMiddlewareTest extends TestCase { @@ -34,7 +34,7 @@ class CloseDbConnectionMiddlewareTest extends TestCase */ public function connectionIsClosedWhenMiddlewareIsProcessed() { - $req = ServerRequestFactory::fromGlobals(); + $req = new ServerRequest(); $resp = new Response(); $conn = $this->prophesize(Connection::class); diff --git a/module/Common/test/Middleware/LocaleMiddlewareTest.php b/module/Common/test/Middleware/LocaleMiddlewareTest.php index 535e767e..2329d915 100644 --- a/module/Common/test/Middleware/LocaleMiddlewareTest.php +++ b/module/Common/test/Middleware/LocaleMiddlewareTest.php @@ -6,7 +6,7 @@ namespace ShlinkioTest\Shlink\Common\Middleware; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Common\Middleware\LocaleMiddleware; use ShlinkioTest\Shlink\Common\Util\TestUtils; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use Zend\I18n\Translator\Translator; class LocaleMiddlewareTest extends TestCase @@ -28,7 +28,7 @@ class LocaleMiddlewareTest extends TestCase public function whenNoHeaderIsPresentLocaleIsNotChanged() { $this->assertEquals('ru', $this->translator->getLocale()); - $this->middleware->process(ServerRequestFactory::fromGlobals(), TestUtils::createReqHandlerMock()->reveal()); + $this->middleware->process(new ServerRequest(), TestUtils::createReqHandlerMock()->reveal()); $this->assertEquals('ru', $this->translator->getLocale()); } @@ -38,7 +38,7 @@ class LocaleMiddlewareTest extends TestCase public function whenTheHeaderIsPresentLocaleIsChanged() { $this->assertEquals('ru', $this->translator->getLocale()); - $request = ServerRequestFactory::fromGlobals()->withHeader('Accept-Language', 'es'); + $request = (new ServerRequest())->withHeader('Accept-Language', 'es'); $this->middleware->process($request, TestUtils::createReqHandlerMock()->reveal()); $this->assertEquals('es', $this->translator->getLocale()); } @@ -53,7 +53,7 @@ class LocaleMiddlewareTest extends TestCase $this->assertEquals('ru', $this->translator->getLocale()); - $request = ServerRequestFactory::fromGlobals()->withHeader('Accept-Language', $lang); + $request = (new ServerRequest())->withHeader('Accept-Language', $lang); $this->middleware->process($request, $handler->reveal()); $this->assertEquals($expected, $this->translator->getLocale()); } diff --git a/module/Core/test/Action/PixelActionTest.php b/module/Core/test/Action/PixelActionTest.php index 65d5ce9d..363a6a88 100644 --- a/module/Core/test/Action/PixelActionTest.php +++ b/module/Core/test/Action/PixelActionTest.php @@ -14,7 +14,7 @@ use Shlinkio\Shlink\Core\Options\AppOptions; use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\VisitsTracker; use ShlinkioTest\Shlink\Common\Util\TestUtils; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class PixelActionTest extends TestCase { @@ -48,7 +48,7 @@ class PixelActionTest extends TestCase )->shouldBeCalledOnce(); $this->visitTracker->track(Argument::cetera())->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); + $request = (new ServerRequest())->withAttribute('shortCode', $shortCode); $response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal()); $this->assertInstanceOf(PixelResponse::class, $response); diff --git a/module/Core/test/Action/PreviewActionTest.php b/module/Core/test/Action/PreviewActionTest.php index 7517f177..ec935433 100644 --- a/module/Core/test/Action/PreviewActionTest.php +++ b/module/Core/test/Action/PreviewActionTest.php @@ -17,7 +17,7 @@ use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Service\UrlShortener; use ShlinkioTest\Shlink\Common\Util\TestUtils; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use const FILEINFO_MIME; use function filesize; @@ -49,10 +49,7 @@ class PreviewActionTest extends TestCase $delegate->handle(Argument::cetera())->shouldBeCalledOnce() ->willReturn(new Response()); - $this->action->process( - ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), - $delegate->reveal() - ); + $this->action->process((new ServerRequest())->withAttribute('shortCode', $shortCode), $delegate->reveal()); } /** @@ -68,7 +65,7 @@ class PreviewActionTest extends TestCase $this->previewGenerator->generatePreview($url)->willReturn($path)->shouldBeCalledOnce(); $resp = $this->action->process( - ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), + (new ServerRequest())->withAttribute('shortCode', $shortCode), TestUtils::createReqHandlerMock()->reveal() ); @@ -89,7 +86,7 @@ class PreviewActionTest extends TestCase $process = $delegate->handle(Argument::any())->willReturn(new Response()); $this->action->process( - ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), + (new ServerRequest())->withAttribute('shortCode', $shortCode), $delegate->reveal() ); diff --git a/module/Core/test/Action/QrCodeActionTest.php b/module/Core/test/Action/QrCodeActionTest.php index 68e2507d..d3e0e924 100644 --- a/module/Core/test/Action/QrCodeActionTest.php +++ b/module/Core/test/Action/QrCodeActionTest.php @@ -15,7 +15,7 @@ use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Service\UrlShortener; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use Zend\Expressive\Router\RouterInterface; class QrCodeActionTest extends TestCase @@ -46,10 +46,7 @@ class QrCodeActionTest extends TestCase $delegate = $this->prophesize(RequestHandlerInterface::class); $process = $delegate->handle(Argument::any())->willReturn(new Response()); - $this->action->process( - ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), - $delegate->reveal() - ); + $this->action->process((new ServerRequest())->withAttribute('shortCode', $shortCode), $delegate->reveal()); $process->shouldHaveBeenCalledOnce(); } @@ -66,10 +63,7 @@ class QrCodeActionTest extends TestCase /** @var MethodProphecy $process */ $process = $delegate->handle(Argument::any())->willReturn(new Response()); - $this->action->process( - ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), - $delegate->reveal() - ); + $this->action->process((new ServerRequest())->withAttribute('shortCode', $shortCode), $delegate->reveal()); $process->shouldHaveBeenCalledOnce(); } @@ -85,7 +79,7 @@ class QrCodeActionTest extends TestCase $delegate = $this->prophesize(RequestHandlerInterface::class); $resp = $this->action->process( - ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), + (new ServerRequest())->withAttribute('shortCode', $shortCode), $delegate->reveal() ); diff --git a/module/Core/test/Action/RedirectActionTest.php b/module/Core/test/Action/RedirectActionTest.php index e9608c2f..57f69d52 100644 --- a/module/Core/test/Action/RedirectActionTest.php +++ b/module/Core/test/Action/RedirectActionTest.php @@ -15,7 +15,7 @@ use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\VisitsTracker; use ShlinkioTest\Shlink\Common\Util\TestUtils; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class RedirectActionTest extends TestCase { @@ -54,7 +54,7 @@ class RedirectActionTest extends TestCase ->shouldBeCalledOnce(); $this->visitTracker->track(Argument::cetera())->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); + $request = (new ServerRequest())->withAttribute('shortCode', $shortCode); $response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal()); $this->assertInstanceOf(Response\RedirectResponse::class, $response); @@ -76,7 +76,7 @@ class RedirectActionTest extends TestCase $handler = $this->prophesize(RequestHandlerInterface::class); $handle = $handler->handle(Argument::any())->willReturn(new Response()); - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); + $request = (new ServerRequest())->withAttribute('shortCode', $shortCode); $this->action->process($request, $handler->reveal()); $handle->shouldHaveBeenCalledOnce(); @@ -98,7 +98,7 @@ class RedirectActionTest extends TestCase $this->notFoundOptions->enableRedirection = true; $this->notFoundOptions->redirectTo = 'https://shlink.io'; - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); + $request = (new ServerRequest())->withAttribute('shortCode', $shortCode); $resp = $this->action->process($request, $handler->reveal()); $this->assertEquals(302, $resp->getStatusCode()); @@ -119,7 +119,7 @@ class RedirectActionTest extends TestCase ->shouldBeCalledOnce(); $this->visitTracker->track(Argument::cetera())->shouldNotBeCalled(); - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode) + $request = (new ServerRequest())->withAttribute('shortCode', $shortCode) ->withQueryParams(['foobar' => true]); $response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal()); diff --git a/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php b/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php index c67ff13d..e9f9cbed 100644 --- a/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php +++ b/module/Core/test/Middleware/QrCodeCacheMiddlewareTest.php @@ -10,7 +10,7 @@ use Prophecy\Argument; use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Core\Middleware\QrCodeCacheMiddleware; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use Zend\Diactoros\Uri; class QrCodeCacheMiddlewareTest extends TestCase @@ -34,9 +34,7 @@ class QrCodeCacheMiddlewareTest extends TestCase $delegate = $this->prophesize(RequestHandlerInterface::class); $delegate->handle(Argument::any())->willReturn(new Response())->shouldBeCalledOnce(); - $this->middleware->process(ServerRequestFactory::fromGlobals()->withUri( - new Uri('/foo/bar') - ), $delegate->reveal()); + $this->middleware->process((new ServerRequest())->withUri(new Uri('/foo/bar')), $delegate->reveal()); $this->assertTrue($this->cache->contains('/foo/bar')); } @@ -51,10 +49,7 @@ class QrCodeCacheMiddlewareTest extends TestCase $this->cache->save('/foo', ['body' => 'the body', 'content-type' => 'image/png']); $delegate = $this->prophesize(RequestHandlerInterface::class); - $resp = $this->middleware->process( - ServerRequestFactory::fromGlobals()->withUri($uri), - $delegate->reveal() - ); + $resp = $this->middleware->process((new ServerRequest())->withUri($uri), $delegate->reveal()); $this->assertFalse($isCalled); $resp->getBody()->rewind(); diff --git a/module/Core/test/Response/NotFoundHandlerTest.php b/module/Core/test/Response/NotFoundHandlerTest.php index dbfcd63a..4bf34664 100644 --- a/module/Core/test/Response/NotFoundHandlerTest.php +++ b/module/Core/test/Response/NotFoundHandlerTest.php @@ -9,7 +9,7 @@ use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\Response\NotFoundHandler; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use Zend\Expressive\Template\TemplateRendererInterface; class NotFoundHandlerTest extends TestCase @@ -35,7 +35,7 @@ class NotFoundHandlerTest extends TestCase */ public function properResponseTypeIsReturned(string $expectedResponse, string $accept, int $renderCalls) { - $request = ServerRequestFactory::fromGlobals()->withHeader('Accept', $accept); + $request = (new ServerRequest())->withHeader('Accept', $accept); /** @var MethodProphecy $render */ $render = $this->renderer->render(Argument::cetera())->willReturn(''); diff --git a/module/Rest/test/Action/AuthenticateActionTest.php b/module/Rest/test/Action/AuthenticateActionTest.php index e90690e6..5ce5a313 100644 --- a/module/Rest/test/Action/AuthenticateActionTest.php +++ b/module/Rest/test/Action/AuthenticateActionTest.php @@ -10,7 +10,7 @@ use Shlinkio\Shlink\Rest\Action\AuthenticateAction; use Shlinkio\Shlink\Rest\Authentication\JWTService; use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Service\ApiKeyService; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use function strpos; class AuthenticateActionTest extends TestCase @@ -36,7 +36,7 @@ class AuthenticateActionTest extends TestCase */ public function notProvidingAuthDataReturnsError() { - $resp = $this->action->handle(ServerRequestFactory::fromGlobals()); + $resp = $this->action->handle(new ServerRequest()); $this->assertEquals(400, $resp->getStatusCode()); } @@ -48,7 +48,7 @@ class AuthenticateActionTest extends TestCase $this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->setId('5')) ->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withParsedBody([ + $request = (new ServerRequest())->withParsedBody([ 'apiKey' => 'foo', ]); $response = $this->action->handle($request); @@ -66,7 +66,7 @@ class AuthenticateActionTest extends TestCase $this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->disable()) ->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withParsedBody([ + $request = (new ServerRequest())->withParsedBody([ 'apiKey' => 'foo', ]); $response = $this->action->handle($request); diff --git a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php index db834b3b..cc9a06a2 100644 --- a/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/CreateShortUrlActionTest.php @@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException; use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Rest\Action\ShortUrl\CreateShortUrlAction; use Shlinkio\Shlink\Rest\Util\RestUtils; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use Zend\Diactoros\Uri; use function strpos; @@ -38,7 +38,7 @@ class CreateShortUrlActionTest extends TestCase */ public function missingLongUrlParamReturnsError() { - $response = $this->action->handle(ServerRequestFactory::fromGlobals()); + $response = $this->action->handle(new ServerRequest()); $this->assertEquals(400, $response->getStatusCode()); } @@ -53,7 +53,7 @@ class CreateShortUrlActionTest extends TestCase ) ->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withParsedBody([ + $request = (new ServerRequest())->withParsedBody([ 'longUrl' => 'http://www.domain.com/foo/bar', ]); $response = $this->action->handle($request); @@ -70,7 +70,7 @@ class CreateShortUrlActionTest extends TestCase ->willThrow(InvalidUrlException::class) ->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withParsedBody([ + $request = (new ServerRequest())->withParsedBody([ 'longUrl' => 'http://www.domain.com/foo/bar', ]); $response = $this->action->handle($request); @@ -92,7 +92,7 @@ class CreateShortUrlActionTest extends TestCase Argument::cetera() )->willThrow(NonUniqueSlugException::class)->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withParsedBody([ + $request = (new ServerRequest())->withParsedBody([ 'longUrl' => 'http://www.domain.com/foo/bar', 'customSlug' => 'foo', ]); @@ -110,7 +110,7 @@ class CreateShortUrlActionTest extends TestCase ->willThrow(Exception::class) ->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withParsedBody([ + $request = (new ServerRequest())->withParsedBody([ 'longUrl' => 'http://www.domain.com/foo/bar', ]); $response = $this->action->handle($request); diff --git a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php index bf43c4c1..725da352 100644 --- a/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/DeleteShortUrlActionTest.php @@ -12,7 +12,7 @@ use Shlinkio\Shlink\Rest\Action\ShortUrl\DeleteShortUrlAction; use Shlinkio\Shlink\Rest\Util\RestUtils; use Throwable; use Zend\Diactoros\Response\JsonResponse; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class DeleteShortUrlActionTest extends TestCase { @@ -35,7 +35,7 @@ class DeleteShortUrlActionTest extends TestCase $deleteByShortCode = $this->service->deleteByShortCode(Argument::any())->will(function () { }); - $resp = $this->action->handle(ServerRequestFactory::fromGlobals()); + $resp = $this->action->handle(new ServerRequest()); $this->assertEquals(204, $resp->getStatusCode()); $deleteByShortCode->shouldHaveBeenCalledOnce(); @@ -50,7 +50,7 @@ class DeleteShortUrlActionTest extends TestCase $deleteByShortCode = $this->service->deleteByShortCode(Argument::any())->willThrow($e); /** @var JsonResponse $resp */ - $resp = $this->action->handle(ServerRequestFactory::fromGlobals()); + $resp = $this->action->handle(new ServerRequest()); $payload = $resp->getPayload(); $this->assertEquals($statusCode, $resp->getStatusCode()); diff --git a/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php index 0206e1bd..9f4832b5 100644 --- a/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/EditShortUrlActionTest.php @@ -12,7 +12,7 @@ use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlAction; use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response\JsonResponse; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class EditShortUrlActionTest extends TestCase { @@ -32,7 +32,7 @@ class EditShortUrlActionTest extends TestCase */ public function invalidDataReturnsError() { - $request = ServerRequestFactory::fromGlobals()->withParsedBody([ + $request = (new ServerRequest())->withParsedBody([ 'maxVisits' => 'invalid', ]); @@ -50,10 +50,10 @@ class EditShortUrlActionTest extends TestCase */ public function incorrectShortCodeReturnsError() { - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') - ->withParsedBody([ - 'maxVisits' => 5, - ]); + $request = (new ServerRequest())->withAttribute('shortCode', 'abc123') + ->withParsedBody([ + 'maxVisits' => 5, + ]); $updateMeta = $this->shortUrlService->updateMetadataByShortCode(Argument::cetera())->willThrow( InvalidShortCodeException::class ); @@ -73,10 +73,10 @@ class EditShortUrlActionTest extends TestCase */ public function correctShortCodeReturnsSuccess() { - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') - ->withParsedBody([ - 'maxVisits' => 5, - ]); + $request = (new ServerRequest())->withAttribute('shortCode', 'abc123') + ->withParsedBody([ + 'maxVisits' => 5, + ]); $updateMeta = $this->shortUrlService->updateMetadataByShortCode(Argument::cetera())->willReturn( new ShortUrl('') ); diff --git a/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php b/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php index 24a26a7a..006dd83d 100644 --- a/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/EditShortUrlTagsActionTest.php @@ -9,7 +9,7 @@ use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Service\ShortUrlService; use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlTagsAction; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class EditShortUrlTagsActionTest extends TestCase { @@ -29,7 +29,7 @@ class EditShortUrlTagsActionTest extends TestCase */ public function notProvidingTagsReturnsError() { - $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')); + $response = $this->action->handle((new ServerRequest())->withAttribute('shortCode', 'abc123')); $this->assertEquals(400, $response->getStatusCode()); } @@ -43,8 +43,8 @@ class EditShortUrlTagsActionTest extends TestCase ->shouldBeCalledOnce(); $response = $this->action->handle( - ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') - ->withParsedBody(['tags' => []]) + (new ServerRequest())->withAttribute('shortCode', 'abc123') + ->withParsedBody(['tags' => []]) ); $this->assertEquals(404, $response->getStatusCode()); } @@ -59,8 +59,8 @@ class EditShortUrlTagsActionTest extends TestCase ->shouldBeCalledOnce(); $response = $this->action->handle( - ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') - ->withParsedBody(['tags' => []]) + (new ServerRequest())->withAttribute('shortCode', 'abc123') + ->withParsedBody(['tags' => []]) ); $this->assertEquals(200, $response->getStatusCode()); } diff --git a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php index a4baaf13..397de2c8 100644 --- a/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ListShortUrlsActionTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\Service\ShortUrlService; use Shlinkio\Shlink\Rest\Action\ShortUrl\ListShortUrlsAction; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use Zend\Paginator\Adapter\ArrayAdapter; use Zend\Paginator\Paginator; @@ -37,7 +37,7 @@ class ListShortUrlsActionTest extends TestCase $this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter())) ->shouldBeCalledOnce(); - $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([ + $response = $this->action->handle((new ServerRequest())->withQueryParams([ 'page' => $page, ])); $this->assertEquals(200, $response->getStatusCode()); @@ -52,7 +52,7 @@ class ListShortUrlsActionTest extends TestCase $this->service->listShortUrls($page, null, [], null)->willThrow(Exception::class) ->shouldBeCalledOnce(); - $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([ + $response = $this->action->handle((new ServerRequest())->withQueryParams([ 'page' => $page, ])); $this->assertEquals(500, $response->getStatusCode()); diff --git a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php index 7acd606c..e1229e81 100644 --- a/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/ResolveShortUrlActionTest.php @@ -12,7 +12,7 @@ use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Rest\Action\ShortUrl\ResolveShortUrlAction; use Shlinkio\Shlink\Rest\Util\RestUtils; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use function strpos; class ResolveShortUrlActionTest extends TestCase @@ -37,7 +37,7 @@ class ResolveShortUrlActionTest extends TestCase $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class) ->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); + $request = (new ServerRequest())->withAttribute('shortCode', $shortCode); $response = $this->action->handle($request); $this->assertEquals(404, $response->getStatusCode()); $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_ARGUMENT_ERROR) > 0); @@ -53,7 +53,7 @@ class ResolveShortUrlActionTest extends TestCase new ShortUrl('http://domain.com/foo/bar') )->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); + $request = (new ServerRequest())->withAttribute('shortCode', $shortCode); $response = $this->action->handle($request); $this->assertEquals(200, $response->getStatusCode()); $this->assertTrue(strpos($response->getBody()->getContents(), 'http://domain.com/foo/bar') > 0); @@ -68,7 +68,7 @@ class ResolveShortUrlActionTest extends TestCase $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class) ->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); + $request = (new ServerRequest())->withAttribute('shortCode', $shortCode); $response = $this->action->handle($request); $this->assertEquals(400, $response->getStatusCode()); $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_SHORTCODE_ERROR) > 0); @@ -83,7 +83,7 @@ class ResolveShortUrlActionTest extends TestCase $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(Exception::class) ->shouldBeCalledOnce(); - $request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); + $request = (new ServerRequest())->withAttribute('shortCode', $shortCode); $response = $this->action->handle($request); $this->assertEquals(500, $response->getStatusCode()); $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0); diff --git a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php index cf5bf4ad..2735e633 100644 --- a/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php +++ b/module/Rest/test/Action/ShortUrl/SingleStepCreateShortUrlActionTest.php @@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; use Shlinkio\Shlink\Rest\Action\ShortUrl\SingleStepCreateShortUrlAction; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Zend\Diactoros\Response\JsonResponse; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class SingleStepCreateShortUrlActionTest extends TestCase { @@ -44,7 +44,7 @@ class SingleStepCreateShortUrlActionTest extends TestCase */ public function errorResponseIsReturnedIfInvalidApiKeyIsProvided() { - $request = ServerRequestFactory::fromGlobals()->withQueryParams(['apiKey' => 'abc123']); + $request = (new ServerRequest())->withQueryParams(['apiKey' => 'abc123']); $findApiKey = $this->apiKeyService->check('abc123')->willReturn(false); /** @var JsonResponse $resp */ @@ -62,7 +62,7 @@ class SingleStepCreateShortUrlActionTest extends TestCase */ public function errorResponseIsReturnedIfNoUrlIsProvided() { - $request = ServerRequestFactory::fromGlobals()->withQueryParams(['apiKey' => 'abc123']); + $request = (new ServerRequest())->withQueryParams(['apiKey' => 'abc123']); $findApiKey = $this->apiKeyService->check('abc123')->willReturn(true); /** @var JsonResponse $resp */ @@ -80,7 +80,7 @@ class SingleStepCreateShortUrlActionTest extends TestCase */ public function properDataIsPassedWhenGeneratingShortCode() { - $request = ServerRequestFactory::fromGlobals()->withQueryParams([ + $request = (new ServerRequest())->withQueryParams([ 'apiKey' => 'abc123', 'longUrl' => 'http://foobar.com', ]); diff --git a/module/Rest/test/Action/Tag/CreateTagsActionTest.php b/module/Rest/test/Action/Tag/CreateTagsActionTest.php index a3c7871f..9094cbfd 100644 --- a/module/Rest/test/Action/Tag/CreateTagsActionTest.php +++ b/module/Rest/test/Action/Tag/CreateTagsActionTest.php @@ -9,7 +9,7 @@ use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Rest\Action\Tag\CreateTagsAction; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class CreateTagsActionTest extends TestCase { @@ -31,7 +31,7 @@ class CreateTagsActionTest extends TestCase */ public function processDelegatesIntoService($tags) { - $request = ServerRequestFactory::fromGlobals()->withParsedBody(['tags' => $tags]); + $request = (new ServerRequest())->withParsedBody(['tags' => $tags]); /** @var MethodProphecy $deleteTags */ $deleteTags = $this->tagService->createTags($tags ?: [])->willReturn(new ArrayCollection()); diff --git a/module/Rest/test/Action/Tag/DeleteTagsActionTest.php b/module/Rest/test/Action/Tag/DeleteTagsActionTest.php index b8b47da0..03869339 100644 --- a/module/Rest/test/Action/Tag/DeleteTagsActionTest.php +++ b/module/Rest/test/Action/Tag/DeleteTagsActionTest.php @@ -8,7 +8,7 @@ use Prophecy\Prophecy\MethodProphecy; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Rest\Action\Tag\DeleteTagsAction; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class DeleteTagsActionTest extends TestCase { @@ -30,7 +30,7 @@ class DeleteTagsActionTest extends TestCase */ public function processDelegatesIntoService($tags) { - $request = ServerRequestFactory::fromGlobals()->withQueryParams(['tags' => $tags]); + $request = (new ServerRequest())->withQueryParams(['tags' => $tags]); /** @var MethodProphecy $deleteTags */ $deleteTags = $this->tagService->deleteTags($tags ?: []); diff --git a/module/Rest/test/Action/Tag/ListTagsActionTest.php b/module/Rest/test/Action/Tag/ListTagsActionTest.php index fa26a83c..8004c550 100644 --- a/module/Rest/test/Action/Tag/ListTagsActionTest.php +++ b/module/Rest/test/Action/Tag/ListTagsActionTest.php @@ -9,7 +9,7 @@ use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Rest\Action\Tag\ListTagsAction; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use function Shlinkio\Shlink\Common\json_decode; class ListTagsActionTest extends TestCase @@ -33,7 +33,7 @@ class ListTagsActionTest extends TestCase /** @var MethodProphecy $listTags */ $listTags = $this->tagService->listTags()->willReturn([new Tag('foo'), new Tag('bar')]); - $resp = $this->action->handle(ServerRequestFactory::fromGlobals()); + $resp = $this->action->handle(new ServerRequest()); $this->assertEquals([ 'tags' => [ diff --git a/module/Rest/test/Action/Tag/UpdateTagActionTest.php b/module/Rest/test/Action/Tag/UpdateTagActionTest.php index a5649fa2..cd6f88b6 100644 --- a/module/Rest/test/Action/Tag/UpdateTagActionTest.php +++ b/module/Rest/test/Action/Tag/UpdateTagActionTest.php @@ -10,7 +10,7 @@ use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Rest\Action\Tag\UpdateTagAction; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class UpdateTagActionTest extends TestCase { @@ -32,7 +32,7 @@ class UpdateTagActionTest extends TestCase */ public function whenInvalidParamsAreProvidedAnErrorIsReturned(array $bodyParams) { - $request = ServerRequestFactory::fromGlobals()->withParsedBody($bodyParams); + $request = (new ServerRequest())->withParsedBody($bodyParams); $resp = $this->action->handle($request); $this->assertEquals(400, $resp->getStatusCode()); @@ -52,7 +52,7 @@ class UpdateTagActionTest extends TestCase */ public function requestingInvalidTagReturnsError() { - $request = ServerRequestFactory::fromGlobals()->withParsedBody([ + $request = (new ServerRequest())->withParsedBody([ 'oldName' => 'foo', 'newName' => 'bar', ]); @@ -70,7 +70,7 @@ class UpdateTagActionTest extends TestCase */ public function correctInvocationRenamesTag() { - $request = ServerRequestFactory::fromGlobals()->withParsedBody([ + $request = (new ServerRequest())->withParsedBody([ 'oldName' => 'foo', 'newName' => 'bar', ]); diff --git a/module/Rest/test/Action/Visit/GetVisitsActionTest.php b/module/Rest/test/Action/Visit/GetVisitsActionTest.php index 9b2756f4..b9a8a0b5 100644 --- a/module/Rest/test/Action/Visit/GetVisitsActionTest.php +++ b/module/Rest/test/Action/Visit/GetVisitsActionTest.php @@ -12,7 +12,7 @@ use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Service\VisitsTracker; use Shlinkio\Shlink\Rest\Action\Visit\GetVisitsAction; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use Zend\Paginator\Adapter\ArrayAdapter; use Zend\Paginator\Paginator; @@ -39,7 +39,7 @@ class GetVisitsActionTest extends TestCase new Paginator(new ArrayAdapter([])) )->shouldBeCalledOnce(); - $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)); + $response = $this->action->handle((new ServerRequest())->withAttribute('shortCode', $shortCode)); $this->assertEquals(200, $response->getStatusCode()); } @@ -53,7 +53,7 @@ class GetVisitsActionTest extends TestCase InvalidArgumentException::class )->shouldBeCalledOnce(); - $response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)); + $response = $this->action->handle((new ServerRequest())->withAttribute('shortCode', $shortCode)); $this->assertEquals(404, $response->getStatusCode()); } @@ -72,12 +72,12 @@ class GetVisitsActionTest extends TestCase ->shouldBeCalledOnce(); $response = $this->action->handle( - ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode) - ->withQueryParams([ - 'endDate' => '2016-01-01 00:00:00', - 'page' => '3', - 'itemsPerPage' => '10', - ]) + (new ServerRequest())->withAttribute('shortCode', $shortCode) + ->withQueryParams([ + 'endDate' => '2016-01-01 00:00:00', + 'page' => '3', + 'itemsPerPage' => '10', + ]) ); $this->assertEquals(200, $response->getStatusCode()); } diff --git a/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php b/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php index 952eb755..7bce54d7 100644 --- a/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php +++ b/module/Rest/test/Authentication/Plugin/ApiKeyHeaderPluginTest.php @@ -10,7 +10,7 @@ use Shlinkio\Shlink\Rest\Authentication\Plugin\ApiKeyHeaderPlugin; use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class ApiKeyHeaderPluginTest extends TestCase { @@ -68,6 +68,6 @@ class ApiKeyHeaderPluginTest extends TestCase private function createRequest(string $apiKey): ServerRequestInterface { - return ServerRequestFactory::fromGlobals()->withHeader(ApiKeyHeaderPlugin::HEADER_NAME, $apiKey); + return (new ServerRequest())->withHeader(ApiKeyHeaderPlugin::HEADER_NAME, $apiKey); } } diff --git a/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php b/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php index 80b0dc93..ce0d9234 100644 --- a/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php +++ b/module/Rest/test/Authentication/Plugin/AuthorizationHeaderPluginTest.php @@ -9,7 +9,7 @@ use Shlinkio\Shlink\Rest\Authentication\JWTServiceInterface; use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthorizationHeaderPlugin; use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use function sprintf; class AuthorizationHeaderPluginTest extends TestCase @@ -31,7 +31,7 @@ class AuthorizationHeaderPluginTest extends TestCase public function verifyAnAuthorizationWithoutBearerTypeThrowsException() { $authToken = 'ABC-abc'; - $request = ServerRequestFactory::fromGlobals()->withHeader( + $request = (new ServerRequest())->withHeader( AuthorizationHeaderPlugin::HEADER_NAME, $authToken ); @@ -51,7 +51,7 @@ class AuthorizationHeaderPluginTest extends TestCase public function verifyAnAuthorizationWithWrongTypeThrowsException() { $authToken = 'Basic ABC-abc'; - $request = ServerRequestFactory::fromGlobals()->withHeader( + $request = (new ServerRequest())->withHeader( AuthorizationHeaderPlugin::HEADER_NAME, $authToken ); @@ -70,7 +70,7 @@ class AuthorizationHeaderPluginTest extends TestCase public function verifyAnExpiredTokenThrowsException() { $authToken = 'Bearer ABC-abc'; - $request = ServerRequestFactory::fromGlobals()->withHeader( + $request = (new ServerRequest())->withHeader( AuthorizationHeaderPlugin::HEADER_NAME, $authToken ); @@ -94,7 +94,7 @@ class AuthorizationHeaderPluginTest extends TestCase public function verifyValidTokenDoesNotThrowException() { $authToken = 'Bearer ABC-abc'; - $request = ServerRequestFactory::fromGlobals()->withHeader( + $request = (new ServerRequest())->withHeader( AuthorizationHeaderPlugin::HEADER_NAME, $authToken ); @@ -111,7 +111,7 @@ class AuthorizationHeaderPluginTest extends TestCase public function updateReturnsAnUpdatedResponseWithNewJwt() { $authToken = 'Bearer ABC-abc'; - $request = ServerRequestFactory::fromGlobals()->withHeader( + $request = (new ServerRequest())->withHeader( AuthorizationHeaderPlugin::HEADER_NAME, $authToken ); diff --git a/module/Rest/test/Authentication/RequestToAuthPluginTest.php b/module/Rest/test/Authentication/RequestToAuthPluginTest.php index 3b3b80b5..cadaf2e5 100644 --- a/module/Rest/test/Authentication/RequestToAuthPluginTest.php +++ b/module/Rest/test/Authentication/RequestToAuthPluginTest.php @@ -11,7 +11,7 @@ use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthenticationPluginInterface; use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthorizationHeaderPlugin; use Shlinkio\Shlink\Rest\Authentication\RequestToHttpAuthPlugin; use Shlinkio\Shlink\Rest\Exception\NoAuthenticationException; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use function implode; use function sprintf; @@ -33,7 +33,7 @@ class RequestToAuthPluginTest extends TestCase */ public function exceptionIsFoundWhenNoneOfTheSupportedMethodsIsFound() { - $request = ServerRequestFactory::fromGlobals(); + $request = new ServerRequest(); $this->expectException(NoAuthenticationException::class); $this->expectExceptionMessage(sprintf( @@ -50,7 +50,7 @@ class RequestToAuthPluginTest extends TestCase */ public function properPluginIsFetchedWhenAnyAuthTypeIsFound(array $headers, string $expectedHeader) { - $request = ServerRequestFactory::fromGlobals(); + $request = new ServerRequest(); foreach ($headers as $header => $value) { $request = $request->withHeader($header, $value); } diff --git a/module/Rest/test/ErrorHandler/JsonErrorResponseGeneratorTest.php b/module/Rest/test/ErrorHandler/JsonErrorResponseGeneratorTest.php index e7895ae5..0690586d 100644 --- a/module/Rest/test/ErrorHandler/JsonErrorResponseGeneratorTest.php +++ b/module/Rest/test/ErrorHandler/JsonErrorResponseGeneratorTest.php @@ -6,7 +6,7 @@ namespace ShlinkioTest\Shlink\Rest\ErrorHandler; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Rest\ErrorHandler\JsonErrorResponseGenerator; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class JsonErrorResponseGeneratorTest extends TestCase { @@ -23,7 +23,7 @@ class JsonErrorResponseGeneratorTest extends TestCase */ public function noErrorStatusReturnsInternalServerError() { - $response = $this->errorHandler->__invoke(null, ServerRequestFactory::fromGlobals(), new Response()); + $response = $this->errorHandler->__invoke(null, new ServerRequest(), new Response()); $this->assertInstanceOf(Response\JsonResponse::class, $response); $this->assertEquals(500, $response->getStatusCode()); } @@ -35,7 +35,7 @@ class JsonErrorResponseGeneratorTest extends TestCase { $response = $this->errorHandler->__invoke( null, - ServerRequestFactory::fromGlobals(), + new ServerRequest(), (new Response())->withStatus(405) ); $this->assertInstanceOf(Response\JsonResponse::class, $response); diff --git a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php index 2d1c6075..d553e680 100644 --- a/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php +++ b/module/Rest/test/Middleware/AuthenticationMiddlewareTest.php @@ -22,7 +22,7 @@ use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException; use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use Zend\Expressive\Router\Route; use Zend\Expressive\Router\RouteResult; use function implode; @@ -68,18 +68,18 @@ class AuthenticationMiddlewareTest extends TestCase $dummyMiddleware = $this->getDummyMiddleware(); return [ - 'with no route result' => [ServerRequestFactory::fromGlobals()], - 'with failure route result' => [ServerRequestFactory::fromGlobals()->withAttribute( + 'with no route result' => [new ServerRequest()], + 'with failure route result' => [(new ServerRequest())->withAttribute( RouteResult::class, RouteResult::fromRouteFailure([RequestMethodInterface::METHOD_GET]) )], - 'with whitelisted route' => [ServerRequestFactory::fromGlobals()->withAttribute( + 'with whitelisted route' => [(new ServerRequest())->withAttribute( RouteResult::class, RouteResult::fromRoute( new Route('foo', $dummyMiddleware, Route::HTTP_METHOD_ANY, AuthenticateAction::class) ) )], - 'with OPTIONS method' => [ServerRequestFactory::fromGlobals()->withAttribute( + 'with OPTIONS method' => [(new ServerRequest())->withAttribute( RouteResult::class, RouteResult::fromRoute(new Route('bar', $dummyMiddleware), []) )->withMethod(RequestMethodInterface::METHOD_OPTIONS)], @@ -92,7 +92,7 @@ class AuthenticationMiddlewareTest extends TestCase */ public function errorIsReturnedWhenNoValidAuthIsProvided($e) { - $request = ServerRequestFactory::fromGlobals()->withAttribute( + $request = (new ServerRequest())->withAttribute( RouteResult::class, RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), []) ); @@ -124,7 +124,7 @@ class AuthenticationMiddlewareTest extends TestCase */ public function errorIsReturnedWhenVerificationFails() { - $request = ServerRequestFactory::fromGlobals()->withAttribute( + $request = (new ServerRequest())->withAttribute( RouteResult::class, RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), []) ); @@ -151,7 +151,7 @@ class AuthenticationMiddlewareTest extends TestCase public function updatedResponseIsReturnedWhenVerificationPasses() { $newResponse = new Response(); - $request = ServerRequestFactory::fromGlobals()->withAttribute( + $request = (new ServerRequest())->withAttribute( RouteResult::class, RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), []) ); diff --git a/module/Rest/test/Middleware/BodyParserMiddlewareTest.php b/module/Rest/test/Middleware/BodyParserMiddlewareTest.php index 3cf95130..8359a044 100644 --- a/module/Rest/test/Middleware/BodyParserMiddlewareTest.php +++ b/module/Rest/test/Middleware/BodyParserMiddlewareTest.php @@ -10,7 +10,7 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Rest\Middleware\BodyParserMiddleware; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use Zend\Diactoros\Stream; use function array_shift; @@ -29,7 +29,7 @@ class BodyParserMiddlewareTest extends TestCase */ public function requestsFromOtherMethodsJustFallbackToNextMiddleware() { - $request = ServerRequestFactory::fromGlobals()->withMethod('GET'); + $request = (new ServerRequest())->withMethod('GET'); $delegate = $this->prophesize(RequestHandlerInterface::class); /** @var MethodProphecy $process */ $process = $delegate->handle($request)->willReturn(new Response()); @@ -47,9 +47,9 @@ class BodyParserMiddlewareTest extends TestCase $test = $this; $body = new Stream('php://temp', 'wr'); $body->write('{"foo": "bar", "bar": ["one", 5]}'); - $request = ServerRequestFactory::fromGlobals()->withMethod('PUT') - ->withBody($body) - ->withHeader('content-type', 'application/json'); + $request = (new ServerRequest())->withMethod('PUT') + ->withBody($body) + ->withHeader('content-type', 'application/json'); $delegate = $this->prophesize(RequestHandlerInterface::class); /** @var MethodProphecy $process */ $process = $delegate->handle(Argument::type(ServerRequestInterface::class))->will( @@ -79,8 +79,8 @@ class BodyParserMiddlewareTest extends TestCase $test = $this; $body = new Stream('php://temp', 'wr'); $body->write('foo=bar&bar[]=one&bar[]=5'); - $request = ServerRequestFactory::fromGlobals()->withMethod('PUT') - ->withBody($body); + $request = (new ServerRequest())->withMethod('PUT') + ->withBody($body); $delegate = $this->prophesize(RequestHandlerInterface::class); /** @var MethodProphecy $process */ $process = $delegate->handle(Argument::type(ServerRequestInterface::class))->will( diff --git a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php index bde89c6b..a96581b8 100644 --- a/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php +++ b/module/Rest/test/Middleware/CrossDomainMiddlewareTest.php @@ -9,7 +9,7 @@ use Prophecy\Prophecy\ObjectProphecy; use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class CrossDomainMiddlewareTest extends TestCase { @@ -32,7 +32,7 @@ class CrossDomainMiddlewareTest extends TestCase $originalResponse = new Response(); $this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce(); - $response = $this->middleware->process(ServerRequestFactory::fromGlobals(), $this->delegate->reveal()); + $response = $this->middleware->process(new ServerRequest(), $this->delegate->reveal()); $this->assertSame($originalResponse, $response); $headers = $response->getHeaders(); @@ -49,7 +49,7 @@ class CrossDomainMiddlewareTest extends TestCase $this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce(); $response = $this->middleware->process( - ServerRequestFactory::fromGlobals()->withHeader('Origin', 'local'), + (new ServerRequest())->withHeader('Origin', 'local'), $this->delegate->reveal() ); $this->assertNotSame($originalResponse, $response); @@ -65,7 +65,7 @@ class CrossDomainMiddlewareTest extends TestCase public function optionsRequestIncludesMoreHeaders() { $originalResponse = new Response(); - $request = ServerRequestFactory::fromGlobals()->withMethod('OPTIONS')->withHeader('Origin', 'local'); + $request = (new ServerRequest())->withMethod('OPTIONS')->withHeader('Origin', 'local'); $this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce(); $response = $this->middleware->process($request, $this->delegate->reveal()); diff --git a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php index 7917962a..115602d7 100644 --- a/module/Rest/test/Middleware/PathVersionMiddlewareTest.php +++ b/module/Rest/test/Middleware/PathVersionMiddlewareTest.php @@ -10,7 +10,7 @@ use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware; use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; use Zend\Diactoros\Uri; use function array_shift; @@ -29,7 +29,7 @@ class PathVersionMiddlewareTest extends TestCase */ public function whenVersionIsProvidedRequestRemainsUnchanged() { - $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/v2/foo')); + $request = (new ServerRequest())->withUri(new Uri('/v2/foo')); $delegate = $this->prophesize(RequestHandlerInterface::class); $process = $delegate->handle($request)->willReturn(new Response()); @@ -44,7 +44,7 @@ class PathVersionMiddlewareTest extends TestCase */ public function versionOneIsPrependedWhenNoVersionIsDefined() { - $request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/bar/baz')); + $request = (new ServerRequest())->withUri(new Uri('/bar/baz')); $delegate = $this->prophesize(RequestHandlerInterface::class); $delegate->handle(Argument::type(Request::class))->will(function (array $args) use ($request) { diff --git a/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php b/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php index 86c71e86..b3f8cf3b 100644 --- a/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php +++ b/module/Rest/test/Middleware/ShortUrl/CreateShortUrlContentNegotiationMiddlewareTest.php @@ -10,7 +10,7 @@ use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Rest\Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware; use Zend\Diactoros\Response; use Zend\Diactoros\Response\JsonResponse; -use Zend\Diactoros\ServerRequestFactory; +use Zend\Diactoros\ServerRequest; class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase { @@ -33,7 +33,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase $expectedResp = new Response(); $this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn($expectedResp); - $resp = $this->middleware->process(ServerRequestFactory::fromGlobals(), $this->requestHandler->reveal()); + $resp = $this->middleware->process(new ServerRequest(), $this->requestHandler->reveal()); $this->assertSame($expectedResp, $resp); } @@ -45,7 +45,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase */ public function properResponseIsReturned(?string $accept, array $query, string $expectedContentType) { - $request = ServerRequestFactory::fromGlobals()->withQueryParams($query); + $request = (new ServerRequest())->withQueryParams($query); if ($accept !== null) { $request = $request->withHeader('Accept', $accept); } @@ -81,7 +81,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase */ public function properBodyIsReturnedInPlainTextResponses(array $json, string $expectedBody) { - $request = ServerRequestFactory::fromGlobals()->withQueryParams(['format' => 'txt']); + $request = (new ServerRequest())->withQueryParams(['format' => 'txt']); $handle = $this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn( new JsonResponse($json)