Do not use ServerRequestFactory::fromGlobals in tests

This commit is contained in:
Alejandro Celaya 2018-12-25 23:01:30 +01:00
parent 8b3324e143
commit 32070b1fa7
30 changed files with 126 additions and 140 deletions

View file

@ -10,7 +10,7 @@ use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Common\Middleware\CloseDbConnectionMiddleware; use Shlinkio\Shlink\Common\Middleware\CloseDbConnectionMiddleware;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class CloseDbConnectionMiddlewareTest extends TestCase class CloseDbConnectionMiddlewareTest extends TestCase
{ {
@ -34,7 +34,7 @@ class CloseDbConnectionMiddlewareTest extends TestCase
*/ */
public function connectionIsClosedWhenMiddlewareIsProcessed() public function connectionIsClosedWhenMiddlewareIsProcessed()
{ {
$req = ServerRequestFactory::fromGlobals(); $req = new ServerRequest();
$resp = new Response(); $resp = new Response();
$conn = $this->prophesize(Connection::class); $conn = $this->prophesize(Connection::class);

View file

@ -6,7 +6,7 @@ namespace ShlinkioTest\Shlink\Common\Middleware;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Common\Middleware\LocaleMiddleware; use Shlinkio\Shlink\Common\Middleware\LocaleMiddleware;
use ShlinkioTest\Shlink\Common\Util\TestUtils; use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use Zend\I18n\Translator\Translator; use Zend\I18n\Translator\Translator;
class LocaleMiddlewareTest extends TestCase class LocaleMiddlewareTest extends TestCase
@ -28,7 +28,7 @@ class LocaleMiddlewareTest extends TestCase
public function whenNoHeaderIsPresentLocaleIsNotChanged() public function whenNoHeaderIsPresentLocaleIsNotChanged()
{ {
$this->assertEquals('ru', $this->translator->getLocale()); $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()); $this->assertEquals('ru', $this->translator->getLocale());
} }
@ -38,7 +38,7 @@ class LocaleMiddlewareTest extends TestCase
public function whenTheHeaderIsPresentLocaleIsChanged() public function whenTheHeaderIsPresentLocaleIsChanged()
{ {
$this->assertEquals('ru', $this->translator->getLocale()); $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->middleware->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertEquals('es', $this->translator->getLocale()); $this->assertEquals('es', $this->translator->getLocale());
} }
@ -53,7 +53,7 @@ class LocaleMiddlewareTest extends TestCase
$this->assertEquals('ru', $this->translator->getLocale()); $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->middleware->process($request, $handler->reveal());
$this->assertEquals($expected, $this->translator->getLocale()); $this->assertEquals($expected, $this->translator->getLocale());
} }

View file

@ -14,7 +14,7 @@ use Shlinkio\Shlink\Core\Options\AppOptions;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Core\Service\VisitsTracker; use Shlinkio\Shlink\Core\Service\VisitsTracker;
use ShlinkioTest\Shlink\Common\Util\TestUtils; use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class PixelActionTest extends TestCase class PixelActionTest extends TestCase
{ {
@ -48,7 +48,7 @@ class PixelActionTest extends TestCase
)->shouldBeCalledOnce(); )->shouldBeCalledOnce();
$this->visitTracker->track(Argument::cetera())->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()); $response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertInstanceOf(PixelResponse::class, $response); $this->assertInstanceOf(PixelResponse::class, $response);

View file

@ -17,7 +17,7 @@ use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
use ShlinkioTest\Shlink\Common\Util\TestUtils; use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use const FILEINFO_MIME; use const FILEINFO_MIME;
use function filesize; use function filesize;
@ -49,10 +49,7 @@ class PreviewActionTest extends TestCase
$delegate->handle(Argument::cetera())->shouldBeCalledOnce() $delegate->handle(Argument::cetera())->shouldBeCalledOnce()
->willReturn(new Response()); ->willReturn(new Response());
$this->action->process( $this->action->process((new ServerRequest())->withAttribute('shortCode', $shortCode), $delegate->reveal());
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
$delegate->reveal()
);
} }
/** /**
@ -68,7 +65,7 @@ class PreviewActionTest extends TestCase
$this->previewGenerator->generatePreview($url)->willReturn($path)->shouldBeCalledOnce(); $this->previewGenerator->generatePreview($url)->willReturn($path)->shouldBeCalledOnce();
$resp = $this->action->process( $resp = $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), (new ServerRequest())->withAttribute('shortCode', $shortCode),
TestUtils::createReqHandlerMock()->reveal() TestUtils::createReqHandlerMock()->reveal()
); );
@ -89,7 +86,7 @@ class PreviewActionTest extends TestCase
$process = $delegate->handle(Argument::any())->willReturn(new Response()); $process = $delegate->handle(Argument::any())->willReturn(new Response());
$this->action->process( $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), (new ServerRequest())->withAttribute('shortCode', $shortCode),
$delegate->reveal() $delegate->reveal()
); );

View file

@ -15,7 +15,7 @@ use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use Zend\Expressive\Router\RouterInterface; use Zend\Expressive\Router\RouterInterface;
class QrCodeActionTest extends TestCase class QrCodeActionTest extends TestCase
@ -46,10 +46,7 @@ class QrCodeActionTest extends TestCase
$delegate = $this->prophesize(RequestHandlerInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$process = $delegate->handle(Argument::any())->willReturn(new Response()); $process = $delegate->handle(Argument::any())->willReturn(new Response());
$this->action->process( $this->action->process((new ServerRequest())->withAttribute('shortCode', $shortCode), $delegate->reveal());
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
$delegate->reveal()
);
$process->shouldHaveBeenCalledOnce(); $process->shouldHaveBeenCalledOnce();
} }
@ -66,10 +63,7 @@ class QrCodeActionTest extends TestCase
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->handle(Argument::any())->willReturn(new Response()); $process = $delegate->handle(Argument::any())->willReturn(new Response());
$this->action->process( $this->action->process((new ServerRequest())->withAttribute('shortCode', $shortCode), $delegate->reveal());
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode),
$delegate->reveal()
);
$process->shouldHaveBeenCalledOnce(); $process->shouldHaveBeenCalledOnce();
} }
@ -85,7 +79,7 @@ class QrCodeActionTest extends TestCase
$delegate = $this->prophesize(RequestHandlerInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$resp = $this->action->process( $resp = $this->action->process(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode), (new ServerRequest())->withAttribute('shortCode', $shortCode),
$delegate->reveal() $delegate->reveal()
); );

View file

@ -15,7 +15,7 @@ use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Core\Service\VisitsTracker; use Shlinkio\Shlink\Core\Service\VisitsTracker;
use ShlinkioTest\Shlink\Common\Util\TestUtils; use ShlinkioTest\Shlink\Common\Util\TestUtils;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class RedirectActionTest extends TestCase class RedirectActionTest extends TestCase
{ {
@ -54,7 +54,7 @@ class RedirectActionTest extends TestCase
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$this->visitTracker->track(Argument::cetera())->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()); $response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal());
$this->assertInstanceOf(Response\RedirectResponse::class, $response); $this->assertInstanceOf(Response\RedirectResponse::class, $response);
@ -76,7 +76,7 @@ class RedirectActionTest extends TestCase
$handler = $this->prophesize(RequestHandlerInterface::class); $handler = $this->prophesize(RequestHandlerInterface::class);
$handle = $handler->handle(Argument::any())->willReturn(new Response()); $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()); $this->action->process($request, $handler->reveal());
$handle->shouldHaveBeenCalledOnce(); $handle->shouldHaveBeenCalledOnce();
@ -98,7 +98,7 @@ class RedirectActionTest extends TestCase
$this->notFoundOptions->enableRedirection = true; $this->notFoundOptions->enableRedirection = true;
$this->notFoundOptions->redirectTo = 'https://shlink.io'; $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()); $resp = $this->action->process($request, $handler->reveal());
$this->assertEquals(302, $resp->getStatusCode()); $this->assertEquals(302, $resp->getStatusCode());
@ -119,7 +119,7 @@ class RedirectActionTest extends TestCase
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$this->visitTracker->track(Argument::cetera())->shouldNotBeCalled(); $this->visitTracker->track(Argument::cetera())->shouldNotBeCalled();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode) $request = (new ServerRequest())->withAttribute('shortCode', $shortCode)
->withQueryParams(['foobar' => true]); ->withQueryParams(['foobar' => true]);
$response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal()); $response = $this->action->process($request, TestUtils::createReqHandlerMock()->reveal());

View file

@ -10,7 +10,7 @@ use Prophecy\Argument;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Core\Middleware\QrCodeCacheMiddleware; use Shlinkio\Shlink\Core\Middleware\QrCodeCacheMiddleware;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Uri; use Zend\Diactoros\Uri;
class QrCodeCacheMiddlewareTest extends TestCase class QrCodeCacheMiddlewareTest extends TestCase
@ -34,9 +34,7 @@ class QrCodeCacheMiddlewareTest extends TestCase
$delegate = $this->prophesize(RequestHandlerInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$delegate->handle(Argument::any())->willReturn(new Response())->shouldBeCalledOnce(); $delegate->handle(Argument::any())->willReturn(new Response())->shouldBeCalledOnce();
$this->middleware->process(ServerRequestFactory::fromGlobals()->withUri( $this->middleware->process((new ServerRequest())->withUri(new Uri('/foo/bar')), $delegate->reveal());
new Uri('/foo/bar')
), $delegate->reveal());
$this->assertTrue($this->cache->contains('/foo/bar')); $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']); $this->cache->save('/foo', ['body' => 'the body', 'content-type' => 'image/png']);
$delegate = $this->prophesize(RequestHandlerInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$resp = $this->middleware->process( $resp = $this->middleware->process((new ServerRequest())->withUri($uri), $delegate->reveal());
ServerRequestFactory::fromGlobals()->withUri($uri),
$delegate->reveal()
);
$this->assertFalse($isCalled); $this->assertFalse($isCalled);
$resp->getBody()->rewind(); $resp->getBody()->rewind();

View file

@ -9,7 +9,7 @@ use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Response\NotFoundHandler; use Shlinkio\Shlink\Core\Response\NotFoundHandler;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use Zend\Expressive\Template\TemplateRendererInterface; use Zend\Expressive\Template\TemplateRendererInterface;
class NotFoundHandlerTest extends TestCase class NotFoundHandlerTest extends TestCase
@ -35,7 +35,7 @@ class NotFoundHandlerTest extends TestCase
*/ */
public function properResponseTypeIsReturned(string $expectedResponse, string $accept, int $renderCalls) public function properResponseTypeIsReturned(string $expectedResponse, string $accept, int $renderCalls)
{ {
$request = ServerRequestFactory::fromGlobals()->withHeader('Accept', $accept); $request = (new ServerRequest())->withHeader('Accept', $accept);
/** @var MethodProphecy $render */ /** @var MethodProphecy $render */
$render = $this->renderer->render(Argument::cetera())->willReturn(''); $render = $this->renderer->render(Argument::cetera())->willReturn('');

View file

@ -10,7 +10,7 @@ use Shlinkio\Shlink\Rest\Action\AuthenticateAction;
use Shlinkio\Shlink\Rest\Authentication\JWTService; use Shlinkio\Shlink\Rest\Authentication\JWTService;
use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Entity\ApiKey;
use Shlinkio\Shlink\Rest\Service\ApiKeyService; use Shlinkio\Shlink\Rest\Service\ApiKeyService;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use function strpos; use function strpos;
class AuthenticateActionTest extends TestCase class AuthenticateActionTest extends TestCase
@ -36,7 +36,7 @@ class AuthenticateActionTest extends TestCase
*/ */
public function notProvidingAuthDataReturnsError() public function notProvidingAuthDataReturnsError()
{ {
$resp = $this->action->handle(ServerRequestFactory::fromGlobals()); $resp = $this->action->handle(new ServerRequest());
$this->assertEquals(400, $resp->getStatusCode()); $this->assertEquals(400, $resp->getStatusCode());
} }
@ -48,7 +48,7 @@ class AuthenticateActionTest extends TestCase
$this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->setId('5')) $this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->setId('5'))
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = (new ServerRequest())->withParsedBody([
'apiKey' => 'foo', 'apiKey' => 'foo',
]); ]);
$response = $this->action->handle($request); $response = $this->action->handle($request);
@ -66,7 +66,7 @@ class AuthenticateActionTest extends TestCase
$this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->disable()) $this->apiKeyService->getByKey('foo')->willReturn((new ApiKey())->disable())
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = (new ServerRequest())->withParsedBody([
'apiKey' => 'foo', 'apiKey' => 'foo',
]); ]);
$response = $this->action->handle($request); $response = $this->action->handle($request);

View file

@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Rest\Action\ShortUrl\CreateShortUrlAction; use Shlinkio\Shlink\Rest\Action\ShortUrl\CreateShortUrlAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Uri; use Zend\Diactoros\Uri;
use function strpos; use function strpos;
@ -38,7 +38,7 @@ class CreateShortUrlActionTest extends TestCase
*/ */
public function missingLongUrlParamReturnsError() public function missingLongUrlParamReturnsError()
{ {
$response = $this->action->handle(ServerRequestFactory::fromGlobals()); $response = $this->action->handle(new ServerRequest());
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
} }
@ -53,7 +53,7 @@ class CreateShortUrlActionTest extends TestCase
) )
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = (new ServerRequest())->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar', 'longUrl' => 'http://www.domain.com/foo/bar',
]); ]);
$response = $this->action->handle($request); $response = $this->action->handle($request);
@ -70,7 +70,7 @@ class CreateShortUrlActionTest extends TestCase
->willThrow(InvalidUrlException::class) ->willThrow(InvalidUrlException::class)
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = (new ServerRequest())->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar', 'longUrl' => 'http://www.domain.com/foo/bar',
]); ]);
$response = $this->action->handle($request); $response = $this->action->handle($request);
@ -92,7 +92,7 @@ class CreateShortUrlActionTest extends TestCase
Argument::cetera() Argument::cetera()
)->willThrow(NonUniqueSlugException::class)->shouldBeCalledOnce(); )->willThrow(NonUniqueSlugException::class)->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = (new ServerRequest())->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar', 'longUrl' => 'http://www.domain.com/foo/bar',
'customSlug' => 'foo', 'customSlug' => 'foo',
]); ]);
@ -110,7 +110,7 @@ class CreateShortUrlActionTest extends TestCase
->willThrow(Exception::class) ->willThrow(Exception::class)
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = (new ServerRequest())->withParsedBody([
'longUrl' => 'http://www.domain.com/foo/bar', 'longUrl' => 'http://www.domain.com/foo/bar',
]); ]);
$response = $this->action->handle($request); $response = $this->action->handle($request);

View file

@ -12,7 +12,7 @@ use Shlinkio\Shlink\Rest\Action\ShortUrl\DeleteShortUrlAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Throwable; use Throwable;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class DeleteShortUrlActionTest extends TestCase class DeleteShortUrlActionTest extends TestCase
{ {
@ -35,7 +35,7 @@ class DeleteShortUrlActionTest extends TestCase
$deleteByShortCode = $this->service->deleteByShortCode(Argument::any())->will(function () { $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()); $this->assertEquals(204, $resp->getStatusCode());
$deleteByShortCode->shouldHaveBeenCalledOnce(); $deleteByShortCode->shouldHaveBeenCalledOnce();
@ -50,7 +50,7 @@ class DeleteShortUrlActionTest extends TestCase
$deleteByShortCode = $this->service->deleteByShortCode(Argument::any())->willThrow($e); $deleteByShortCode = $this->service->deleteByShortCode(Argument::any())->willThrow($e);
/** @var JsonResponse $resp */ /** @var JsonResponse $resp */
$resp = $this->action->handle(ServerRequestFactory::fromGlobals()); $resp = $this->action->handle(new ServerRequest());
$payload = $resp->getPayload(); $payload = $resp->getPayload();
$this->assertEquals($statusCode, $resp->getStatusCode()); $this->assertEquals($statusCode, $resp->getStatusCode());

View file

@ -12,7 +12,7 @@ use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface;
use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlAction; use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class EditShortUrlActionTest extends TestCase class EditShortUrlActionTest extends TestCase
{ {
@ -32,7 +32,7 @@ class EditShortUrlActionTest extends TestCase
*/ */
public function invalidDataReturnsError() public function invalidDataReturnsError()
{ {
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = (new ServerRequest())->withParsedBody([
'maxVisits' => 'invalid', 'maxVisits' => 'invalid',
]); ]);
@ -50,7 +50,7 @@ class EditShortUrlActionTest extends TestCase
*/ */
public function incorrectShortCodeReturnsError() public function incorrectShortCodeReturnsError()
{ {
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') $request = (new ServerRequest())->withAttribute('shortCode', 'abc123')
->withParsedBody([ ->withParsedBody([
'maxVisits' => 5, 'maxVisits' => 5,
]); ]);
@ -73,7 +73,7 @@ class EditShortUrlActionTest extends TestCase
*/ */
public function correctShortCodeReturnsSuccess() public function correctShortCodeReturnsSuccess()
{ {
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') $request = (new ServerRequest())->withAttribute('shortCode', 'abc123')
->withParsedBody([ ->withParsedBody([
'maxVisits' => 5, 'maxVisits' => 5,
]); ]);

View file

@ -9,7 +9,7 @@ use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException; use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\ShortUrlService; use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlTagsAction; use Shlinkio\Shlink\Rest\Action\ShortUrl\EditShortUrlTagsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class EditShortUrlTagsActionTest extends TestCase class EditShortUrlTagsActionTest extends TestCase
{ {
@ -29,7 +29,7 @@ class EditShortUrlTagsActionTest extends TestCase
*/ */
public function notProvidingTagsReturnsError() 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()); $this->assertEquals(400, $response->getStatusCode());
} }
@ -43,7 +43,7 @@ class EditShortUrlTagsActionTest extends TestCase
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$response = $this->action->handle( $response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') (new ServerRequest())->withAttribute('shortCode', 'abc123')
->withParsedBody(['tags' => []]) ->withParsedBody(['tags' => []])
); );
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
@ -59,7 +59,7 @@ class EditShortUrlTagsActionTest extends TestCase
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$response = $this->action->handle( $response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123') (new ServerRequest())->withAttribute('shortCode', 'abc123')
->withParsedBody(['tags' => []]) ->withParsedBody(['tags' => []])
); );
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());

View file

@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Service\ShortUrlService; use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\ShortUrl\ListShortUrlsAction; use Shlinkio\Shlink\Rest\Action\ShortUrl\ListShortUrlsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use Zend\Paginator\Adapter\ArrayAdapter; use Zend\Paginator\Adapter\ArrayAdapter;
use Zend\Paginator\Paginator; use Zend\Paginator\Paginator;
@ -37,7 +37,7 @@ class ListShortUrlsActionTest extends TestCase
$this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter())) $this->service->listShortUrls($page, null, [], null)->willReturn(new Paginator(new ArrayAdapter()))
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([ $response = $this->action->handle((new ServerRequest())->withQueryParams([
'page' => $page, 'page' => $page,
])); ]));
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
@ -52,7 +52,7 @@ class ListShortUrlsActionTest extends TestCase
$this->service->listShortUrls($page, null, [], null)->willThrow(Exception::class) $this->service->listShortUrls($page, null, [], null)->willThrow(Exception::class)
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withQueryParams([ $response = $this->action->handle((new ServerRequest())->withQueryParams([
'page' => $page, 'page' => $page,
])); ]));
$this->assertEquals(500, $response->getStatusCode()); $this->assertEquals(500, $response->getStatusCode());

View file

@ -12,7 +12,7 @@ use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Rest\Action\ShortUrl\ResolveShortUrlAction; use Shlinkio\Shlink\Rest\Action\ShortUrl\ResolveShortUrlAction;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use function strpos; use function strpos;
class ResolveShortUrlActionTest extends TestCase class ResolveShortUrlActionTest extends TestCase
@ -37,7 +37,7 @@ class ResolveShortUrlActionTest extends TestCase
$this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class) $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(EntityDoesNotExistException::class)
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); $request = (new ServerRequest())->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request); $response = $this->action->handle($request);
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_ARGUMENT_ERROR) > 0); $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') new ShortUrl('http://domain.com/foo/bar')
)->shouldBeCalledOnce(); )->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); $request = (new ServerRequest())->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request); $response = $this->action->handle($request);
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), 'http://domain.com/foo/bar') > 0); $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) $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(InvalidShortCodeException::class)
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); $request = (new ServerRequest())->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request); $response = $this->action->handle($request);
$this->assertEquals(400, $response->getStatusCode()); $this->assertEquals(400, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::INVALID_SHORTCODE_ERROR) > 0); $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) $this->urlShortener->shortCodeToUrl($shortCode)->willThrow(Exception::class)
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$request = ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode); $request = (new ServerRequest())->withAttribute('shortCode', $shortCode);
$response = $this->action->handle($request); $response = $this->action->handle($request);
$this->assertEquals(500, $response->getStatusCode()); $this->assertEquals(500, $response->getStatusCode());
$this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0); $this->assertTrue(strpos($response->getBody()->getContents(), RestUtils::UNKNOWN_ERROR) > 0);

View file

@ -13,7 +13,7 @@ use Shlinkio\Shlink\Core\Service\UrlShortenerInterface;
use Shlinkio\Shlink\Rest\Action\ShortUrl\SingleStepCreateShortUrlAction; use Shlinkio\Shlink\Rest\Action\ShortUrl\SingleStepCreateShortUrlAction;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class SingleStepCreateShortUrlActionTest extends TestCase class SingleStepCreateShortUrlActionTest extends TestCase
{ {
@ -44,7 +44,7 @@ class SingleStepCreateShortUrlActionTest extends TestCase
*/ */
public function errorResponseIsReturnedIfInvalidApiKeyIsProvided() public function errorResponseIsReturnedIfInvalidApiKeyIsProvided()
{ {
$request = ServerRequestFactory::fromGlobals()->withQueryParams(['apiKey' => 'abc123']); $request = (new ServerRequest())->withQueryParams(['apiKey' => 'abc123']);
$findApiKey = $this->apiKeyService->check('abc123')->willReturn(false); $findApiKey = $this->apiKeyService->check('abc123')->willReturn(false);
/** @var JsonResponse $resp */ /** @var JsonResponse $resp */
@ -62,7 +62,7 @@ class SingleStepCreateShortUrlActionTest extends TestCase
*/ */
public function errorResponseIsReturnedIfNoUrlIsProvided() public function errorResponseIsReturnedIfNoUrlIsProvided()
{ {
$request = ServerRequestFactory::fromGlobals()->withQueryParams(['apiKey' => 'abc123']); $request = (new ServerRequest())->withQueryParams(['apiKey' => 'abc123']);
$findApiKey = $this->apiKeyService->check('abc123')->willReturn(true); $findApiKey = $this->apiKeyService->check('abc123')->willReturn(true);
/** @var JsonResponse $resp */ /** @var JsonResponse $resp */
@ -80,7 +80,7 @@ class SingleStepCreateShortUrlActionTest extends TestCase
*/ */
public function properDataIsPassedWhenGeneratingShortCode() public function properDataIsPassedWhenGeneratingShortCode()
{ {
$request = ServerRequestFactory::fromGlobals()->withQueryParams([ $request = (new ServerRequest())->withQueryParams([
'apiKey' => 'abc123', 'apiKey' => 'abc123',
'longUrl' => 'http://foobar.com', 'longUrl' => 'http://foobar.com',
]); ]);

View file

@ -9,7 +9,7 @@ use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\CreateTagsAction; use Shlinkio\Shlink\Rest\Action\Tag\CreateTagsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class CreateTagsActionTest extends TestCase class CreateTagsActionTest extends TestCase
{ {
@ -31,7 +31,7 @@ class CreateTagsActionTest extends TestCase
*/ */
public function processDelegatesIntoService($tags) public function processDelegatesIntoService($tags)
{ {
$request = ServerRequestFactory::fromGlobals()->withParsedBody(['tags' => $tags]); $request = (new ServerRequest())->withParsedBody(['tags' => $tags]);
/** @var MethodProphecy $deleteTags */ /** @var MethodProphecy $deleteTags */
$deleteTags = $this->tagService->createTags($tags ?: [])->willReturn(new ArrayCollection()); $deleteTags = $this->tagService->createTags($tags ?: [])->willReturn(new ArrayCollection());

View file

@ -8,7 +8,7 @@ use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\DeleteTagsAction; use Shlinkio\Shlink\Rest\Action\Tag\DeleteTagsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class DeleteTagsActionTest extends TestCase class DeleteTagsActionTest extends TestCase
{ {
@ -30,7 +30,7 @@ class DeleteTagsActionTest extends TestCase
*/ */
public function processDelegatesIntoService($tags) public function processDelegatesIntoService($tags)
{ {
$request = ServerRequestFactory::fromGlobals()->withQueryParams(['tags' => $tags]); $request = (new ServerRequest())->withQueryParams(['tags' => $tags]);
/** @var MethodProphecy $deleteTags */ /** @var MethodProphecy $deleteTags */
$deleteTags = $this->tagService->deleteTags($tags ?: []); $deleteTags = $this->tagService->deleteTags($tags ?: []);

View file

@ -9,7 +9,7 @@ use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\ListTagsAction; use Shlinkio\Shlink\Rest\Action\Tag\ListTagsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use function Shlinkio\Shlink\Common\json_decode; use function Shlinkio\Shlink\Common\json_decode;
class ListTagsActionTest extends TestCase class ListTagsActionTest extends TestCase
@ -33,7 +33,7 @@ class ListTagsActionTest extends TestCase
/** @var MethodProphecy $listTags */ /** @var MethodProphecy $listTags */
$listTags = $this->tagService->listTags()->willReturn([new Tag('foo'), new Tag('bar')]); $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([ $this->assertEquals([
'tags' => [ 'tags' => [

View file

@ -10,7 +10,7 @@ use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException; use Shlinkio\Shlink\Core\Exception\EntityDoesNotExistException;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\Tag\UpdateTagAction; use Shlinkio\Shlink\Rest\Action\Tag\UpdateTagAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class UpdateTagActionTest extends TestCase class UpdateTagActionTest extends TestCase
{ {
@ -32,7 +32,7 @@ class UpdateTagActionTest extends TestCase
*/ */
public function whenInvalidParamsAreProvidedAnErrorIsReturned(array $bodyParams) public function whenInvalidParamsAreProvidedAnErrorIsReturned(array $bodyParams)
{ {
$request = ServerRequestFactory::fromGlobals()->withParsedBody($bodyParams); $request = (new ServerRequest())->withParsedBody($bodyParams);
$resp = $this->action->handle($request); $resp = $this->action->handle($request);
$this->assertEquals(400, $resp->getStatusCode()); $this->assertEquals(400, $resp->getStatusCode());
@ -52,7 +52,7 @@ class UpdateTagActionTest extends TestCase
*/ */
public function requestingInvalidTagReturnsError() public function requestingInvalidTagReturnsError()
{ {
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = (new ServerRequest())->withParsedBody([
'oldName' => 'foo', 'oldName' => 'foo',
'newName' => 'bar', 'newName' => 'bar',
]); ]);
@ -70,7 +70,7 @@ class UpdateTagActionTest extends TestCase
*/ */
public function correctInvocationRenamesTag() public function correctInvocationRenamesTag()
{ {
$request = ServerRequestFactory::fromGlobals()->withParsedBody([ $request = (new ServerRequest())->withParsedBody([
'oldName' => 'foo', 'oldName' => 'foo',
'newName' => 'bar', 'newName' => 'bar',
]); ]);

View file

@ -12,7 +12,7 @@ use Shlinkio\Shlink\Common\Util\DateRange;
use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Model\VisitsParams;
use Shlinkio\Shlink\Core\Service\VisitsTracker; use Shlinkio\Shlink\Core\Service\VisitsTracker;
use Shlinkio\Shlink\Rest\Action\Visit\GetVisitsAction; use Shlinkio\Shlink\Rest\Action\Visit\GetVisitsAction;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use Zend\Paginator\Adapter\ArrayAdapter; use Zend\Paginator\Adapter\ArrayAdapter;
use Zend\Paginator\Paginator; use Zend\Paginator\Paginator;
@ -39,7 +39,7 @@ class GetVisitsActionTest extends TestCase
new Paginator(new ArrayAdapter([])) new Paginator(new ArrayAdapter([]))
)->shouldBeCalledOnce(); )->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)); $response = $this->action->handle((new ServerRequest())->withAttribute('shortCode', $shortCode));
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
} }
@ -53,7 +53,7 @@ class GetVisitsActionTest extends TestCase
InvalidArgumentException::class InvalidArgumentException::class
)->shouldBeCalledOnce(); )->shouldBeCalledOnce();
$response = $this->action->handle(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)); $response = $this->action->handle((new ServerRequest())->withAttribute('shortCode', $shortCode));
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
} }
@ -72,7 +72,7 @@ class GetVisitsActionTest extends TestCase
->shouldBeCalledOnce(); ->shouldBeCalledOnce();
$response = $this->action->handle( $response = $this->action->handle(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode) (new ServerRequest())->withAttribute('shortCode', $shortCode)
->withQueryParams([ ->withQueryParams([
'endDate' => '2016-01-01 00:00:00', 'endDate' => '2016-01-01 00:00:00',
'page' => '3', 'page' => '3',

View file

@ -10,7 +10,7 @@ use Shlinkio\Shlink\Rest\Authentication\Plugin\ApiKeyHeaderPlugin;
use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException; use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class ApiKeyHeaderPluginTest extends TestCase class ApiKeyHeaderPluginTest extends TestCase
{ {
@ -68,6 +68,6 @@ class ApiKeyHeaderPluginTest extends TestCase
private function createRequest(string $apiKey): ServerRequestInterface private function createRequest(string $apiKey): ServerRequestInterface
{ {
return ServerRequestFactory::fromGlobals()->withHeader(ApiKeyHeaderPlugin::HEADER_NAME, $apiKey); return (new ServerRequest())->withHeader(ApiKeyHeaderPlugin::HEADER_NAME, $apiKey);
} }
} }

View file

@ -9,7 +9,7 @@ use Shlinkio\Shlink\Rest\Authentication\JWTServiceInterface;
use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthorizationHeaderPlugin; use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthorizationHeaderPlugin;
use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException; use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use function sprintf; use function sprintf;
class AuthorizationHeaderPluginTest extends TestCase class AuthorizationHeaderPluginTest extends TestCase
@ -31,7 +31,7 @@ class AuthorizationHeaderPluginTest extends TestCase
public function verifyAnAuthorizationWithoutBearerTypeThrowsException() public function verifyAnAuthorizationWithoutBearerTypeThrowsException()
{ {
$authToken = 'ABC-abc'; $authToken = 'ABC-abc';
$request = ServerRequestFactory::fromGlobals()->withHeader( $request = (new ServerRequest())->withHeader(
AuthorizationHeaderPlugin::HEADER_NAME, AuthorizationHeaderPlugin::HEADER_NAME,
$authToken $authToken
); );
@ -51,7 +51,7 @@ class AuthorizationHeaderPluginTest extends TestCase
public function verifyAnAuthorizationWithWrongTypeThrowsException() public function verifyAnAuthorizationWithWrongTypeThrowsException()
{ {
$authToken = 'Basic ABC-abc'; $authToken = 'Basic ABC-abc';
$request = ServerRequestFactory::fromGlobals()->withHeader( $request = (new ServerRequest())->withHeader(
AuthorizationHeaderPlugin::HEADER_NAME, AuthorizationHeaderPlugin::HEADER_NAME,
$authToken $authToken
); );
@ -70,7 +70,7 @@ class AuthorizationHeaderPluginTest extends TestCase
public function verifyAnExpiredTokenThrowsException() public function verifyAnExpiredTokenThrowsException()
{ {
$authToken = 'Bearer ABC-abc'; $authToken = 'Bearer ABC-abc';
$request = ServerRequestFactory::fromGlobals()->withHeader( $request = (new ServerRequest())->withHeader(
AuthorizationHeaderPlugin::HEADER_NAME, AuthorizationHeaderPlugin::HEADER_NAME,
$authToken $authToken
); );
@ -94,7 +94,7 @@ class AuthorizationHeaderPluginTest extends TestCase
public function verifyValidTokenDoesNotThrowException() public function verifyValidTokenDoesNotThrowException()
{ {
$authToken = 'Bearer ABC-abc'; $authToken = 'Bearer ABC-abc';
$request = ServerRequestFactory::fromGlobals()->withHeader( $request = (new ServerRequest())->withHeader(
AuthorizationHeaderPlugin::HEADER_NAME, AuthorizationHeaderPlugin::HEADER_NAME,
$authToken $authToken
); );
@ -111,7 +111,7 @@ class AuthorizationHeaderPluginTest extends TestCase
public function updateReturnsAnUpdatedResponseWithNewJwt() public function updateReturnsAnUpdatedResponseWithNewJwt()
{ {
$authToken = 'Bearer ABC-abc'; $authToken = 'Bearer ABC-abc';
$request = ServerRequestFactory::fromGlobals()->withHeader( $request = (new ServerRequest())->withHeader(
AuthorizationHeaderPlugin::HEADER_NAME, AuthorizationHeaderPlugin::HEADER_NAME,
$authToken $authToken
); );

View file

@ -11,7 +11,7 @@ use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthenticationPluginInterface;
use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthorizationHeaderPlugin; use Shlinkio\Shlink\Rest\Authentication\Plugin\AuthorizationHeaderPlugin;
use Shlinkio\Shlink\Rest\Authentication\RequestToHttpAuthPlugin; use Shlinkio\Shlink\Rest\Authentication\RequestToHttpAuthPlugin;
use Shlinkio\Shlink\Rest\Exception\NoAuthenticationException; use Shlinkio\Shlink\Rest\Exception\NoAuthenticationException;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use function implode; use function implode;
use function sprintf; use function sprintf;
@ -33,7 +33,7 @@ class RequestToAuthPluginTest extends TestCase
*/ */
public function exceptionIsFoundWhenNoneOfTheSupportedMethodsIsFound() public function exceptionIsFoundWhenNoneOfTheSupportedMethodsIsFound()
{ {
$request = ServerRequestFactory::fromGlobals(); $request = new ServerRequest();
$this->expectException(NoAuthenticationException::class); $this->expectException(NoAuthenticationException::class);
$this->expectExceptionMessage(sprintf( $this->expectExceptionMessage(sprintf(
@ -50,7 +50,7 @@ class RequestToAuthPluginTest extends TestCase
*/ */
public function properPluginIsFetchedWhenAnyAuthTypeIsFound(array $headers, string $expectedHeader) public function properPluginIsFetchedWhenAnyAuthTypeIsFound(array $headers, string $expectedHeader)
{ {
$request = ServerRequestFactory::fromGlobals(); $request = new ServerRequest();
foreach ($headers as $header => $value) { foreach ($headers as $header => $value) {
$request = $request->withHeader($header, $value); $request = $request->withHeader($header, $value);
} }

View file

@ -6,7 +6,7 @@ namespace ShlinkioTest\Shlink\Rest\ErrorHandler;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Shlinkio\Shlink\Rest\ErrorHandler\JsonErrorResponseGenerator; use Shlinkio\Shlink\Rest\ErrorHandler\JsonErrorResponseGenerator;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class JsonErrorResponseGeneratorTest extends TestCase class JsonErrorResponseGeneratorTest extends TestCase
{ {
@ -23,7 +23,7 @@ class JsonErrorResponseGeneratorTest extends TestCase
*/ */
public function noErrorStatusReturnsInternalServerError() 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->assertInstanceOf(Response\JsonResponse::class, $response);
$this->assertEquals(500, $response->getStatusCode()); $this->assertEquals(500, $response->getStatusCode());
} }
@ -35,7 +35,7 @@ class JsonErrorResponseGeneratorTest extends TestCase
{ {
$response = $this->errorHandler->__invoke( $response = $this->errorHandler->__invoke(
null, null,
ServerRequestFactory::fromGlobals(), new ServerRequest(),
(new Response())->withStatus(405) (new Response())->withStatus(405)
); );
$this->assertInstanceOf(Response\JsonResponse::class, $response); $this->assertInstanceOf(Response\JsonResponse::class, $response);

View file

@ -22,7 +22,7 @@ use Shlinkio\Shlink\Rest\Exception\VerifyAuthenticationException;
use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware; use Shlinkio\Shlink\Rest\Middleware\AuthenticationMiddleware;
use Shlinkio\Shlink\Rest\Util\RestUtils; use Shlinkio\Shlink\Rest\Util\RestUtils;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use Zend\Expressive\Router\Route; use Zend\Expressive\Router\Route;
use Zend\Expressive\Router\RouteResult; use Zend\Expressive\Router\RouteResult;
use function implode; use function implode;
@ -68,18 +68,18 @@ class AuthenticationMiddlewareTest extends TestCase
$dummyMiddleware = $this->getDummyMiddleware(); $dummyMiddleware = $this->getDummyMiddleware();
return [ return [
'with no route result' => [ServerRequestFactory::fromGlobals()], 'with no route result' => [new ServerRequest()],
'with failure route result' => [ServerRequestFactory::fromGlobals()->withAttribute( 'with failure route result' => [(new ServerRequest())->withAttribute(
RouteResult::class, RouteResult::class,
RouteResult::fromRouteFailure([RequestMethodInterface::METHOD_GET]) RouteResult::fromRouteFailure([RequestMethodInterface::METHOD_GET])
)], )],
'with whitelisted route' => [ServerRequestFactory::fromGlobals()->withAttribute( 'with whitelisted route' => [(new ServerRequest())->withAttribute(
RouteResult::class, RouteResult::class,
RouteResult::fromRoute( RouteResult::fromRoute(
new Route('foo', $dummyMiddleware, Route::HTTP_METHOD_ANY, AuthenticateAction::class) 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::class,
RouteResult::fromRoute(new Route('bar', $dummyMiddleware), []) RouteResult::fromRoute(new Route('bar', $dummyMiddleware), [])
)->withMethod(RequestMethodInterface::METHOD_OPTIONS)], )->withMethod(RequestMethodInterface::METHOD_OPTIONS)],
@ -92,7 +92,7 @@ class AuthenticationMiddlewareTest extends TestCase
*/ */
public function errorIsReturnedWhenNoValidAuthIsProvided($e) public function errorIsReturnedWhenNoValidAuthIsProvided($e)
{ {
$request = ServerRequestFactory::fromGlobals()->withAttribute( $request = (new ServerRequest())->withAttribute(
RouteResult::class, RouteResult::class,
RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), []) RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), [])
); );
@ -124,7 +124,7 @@ class AuthenticationMiddlewareTest extends TestCase
*/ */
public function errorIsReturnedWhenVerificationFails() public function errorIsReturnedWhenVerificationFails()
{ {
$request = ServerRequestFactory::fromGlobals()->withAttribute( $request = (new ServerRequest())->withAttribute(
RouteResult::class, RouteResult::class,
RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), []) RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), [])
); );
@ -151,7 +151,7 @@ class AuthenticationMiddlewareTest extends TestCase
public function updatedResponseIsReturnedWhenVerificationPasses() public function updatedResponseIsReturnedWhenVerificationPasses()
{ {
$newResponse = new Response(); $newResponse = new Response();
$request = ServerRequestFactory::fromGlobals()->withAttribute( $request = (new ServerRequest())->withAttribute(
RouteResult::class, RouteResult::class,
RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), []) RouteResult::fromRoute(new Route('bar', $this->getDummyMiddleware()), [])
); );

View file

@ -10,7 +10,7 @@ use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Rest\Middleware\BodyParserMiddleware; use Shlinkio\Shlink\Rest\Middleware\BodyParserMiddleware;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Stream; use Zend\Diactoros\Stream;
use function array_shift; use function array_shift;
@ -29,7 +29,7 @@ class BodyParserMiddlewareTest extends TestCase
*/ */
public function requestsFromOtherMethodsJustFallbackToNextMiddleware() public function requestsFromOtherMethodsJustFallbackToNextMiddleware()
{ {
$request = ServerRequestFactory::fromGlobals()->withMethod('GET'); $request = (new ServerRequest())->withMethod('GET');
$delegate = $this->prophesize(RequestHandlerInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */
$process = $delegate->handle($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
@ -47,7 +47,7 @@ class BodyParserMiddlewareTest extends TestCase
$test = $this; $test = $this;
$body = new Stream('php://temp', 'wr'); $body = new Stream('php://temp', 'wr');
$body->write('{"foo": "bar", "bar": ["one", 5]}'); $body->write('{"foo": "bar", "bar": ["one", 5]}');
$request = ServerRequestFactory::fromGlobals()->withMethod('PUT') $request = (new ServerRequest())->withMethod('PUT')
->withBody($body) ->withBody($body)
->withHeader('content-type', 'application/json'); ->withHeader('content-type', 'application/json');
$delegate = $this->prophesize(RequestHandlerInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
@ -79,7 +79,7 @@ class BodyParserMiddlewareTest extends TestCase
$test = $this; $test = $this;
$body = new Stream('php://temp', 'wr'); $body = new Stream('php://temp', 'wr');
$body->write('foo=bar&bar[]=one&bar[]=5'); $body->write('foo=bar&bar[]=one&bar[]=5');
$request = ServerRequestFactory::fromGlobals()->withMethod('PUT') $request = (new ServerRequest())->withMethod('PUT')
->withBody($body); ->withBody($body);
$delegate = $this->prophesize(RequestHandlerInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
/** @var MethodProphecy $process */ /** @var MethodProphecy $process */

View file

@ -9,7 +9,7 @@ use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware; use Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class CrossDomainMiddlewareTest extends TestCase class CrossDomainMiddlewareTest extends TestCase
{ {
@ -32,7 +32,7 @@ class CrossDomainMiddlewareTest extends TestCase
$originalResponse = new Response(); $originalResponse = new Response();
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce(); $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); $this->assertSame($originalResponse, $response);
$headers = $response->getHeaders(); $headers = $response->getHeaders();
@ -49,7 +49,7 @@ class CrossDomainMiddlewareTest extends TestCase
$this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce(); $this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce();
$response = $this->middleware->process( $response = $this->middleware->process(
ServerRequestFactory::fromGlobals()->withHeader('Origin', 'local'), (new ServerRequest())->withHeader('Origin', 'local'),
$this->delegate->reveal() $this->delegate->reveal()
); );
$this->assertNotSame($originalResponse, $response); $this->assertNotSame($originalResponse, $response);
@ -65,7 +65,7 @@ class CrossDomainMiddlewareTest extends TestCase
public function optionsRequestIncludesMoreHeaders() public function optionsRequestIncludesMoreHeaders()
{ {
$originalResponse = new Response(); $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(); $this->delegate->handle(Argument::any())->willReturn($originalResponse)->shouldBeCalledOnce();
$response = $this->middleware->process($request, $this->delegate->reveal()); $response = $this->middleware->process($request, $this->delegate->reveal());

View file

@ -10,7 +10,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface; use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware; use Shlinkio\Shlink\Rest\Middleware\PathVersionMiddleware;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Uri; use Zend\Diactoros\Uri;
use function array_shift; use function array_shift;
@ -29,7 +29,7 @@ class PathVersionMiddlewareTest extends TestCase
*/ */
public function whenVersionIsProvidedRequestRemainsUnchanged() public function whenVersionIsProvidedRequestRemainsUnchanged()
{ {
$request = ServerRequestFactory::fromGlobals()->withUri(new Uri('/v2/foo')); $request = (new ServerRequest())->withUri(new Uri('/v2/foo'));
$delegate = $this->prophesize(RequestHandlerInterface::class); $delegate = $this->prophesize(RequestHandlerInterface::class);
$process = $delegate->handle($request)->willReturn(new Response()); $process = $delegate->handle($request)->willReturn(new Response());
@ -44,7 +44,7 @@ class PathVersionMiddlewareTest extends TestCase
*/ */
public function versionOneIsPrependedWhenNoVersionIsDefined() 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 = $this->prophesize(RequestHandlerInterface::class);
$delegate->handle(Argument::type(Request::class))->will(function (array $args) use ($request) { $delegate->handle(Argument::type(Request::class))->will(function (array $args) use ($request) {

View file

@ -10,7 +10,7 @@ use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Rest\Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware; use Shlinkio\Shlink\Rest\Middleware\ShortUrl\CreateShortUrlContentNegotiationMiddleware;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\ServerRequestFactory; use Zend\Diactoros\ServerRequest;
class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase
{ {
@ -33,7 +33,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase
$expectedResp = new Response(); $expectedResp = new Response();
$this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn($expectedResp); $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); $this->assertSame($expectedResp, $resp);
} }
@ -45,7 +45,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase
*/ */
public function properResponseIsReturned(?string $accept, array $query, string $expectedContentType) public function properResponseIsReturned(?string $accept, array $query, string $expectedContentType)
{ {
$request = ServerRequestFactory::fromGlobals()->withQueryParams($query); $request = (new ServerRequest())->withQueryParams($query);
if ($accept !== null) { if ($accept !== null) {
$request = $request->withHeader('Accept', $accept); $request = $request->withHeader('Accept', $accept);
} }
@ -81,7 +81,7 @@ class CreateShortUrlContentNegotiationMiddlewareTest extends TestCase
*/ */
public function properBodyIsReturnedInPlainTextResponses(array $json, string $expectedBody) 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( $handle = $this->requestHandler->handle(Argument::type(ServerRequestInterface::class))->willReturn(
new JsonResponse($json) new JsonResponse($json)