From f7e63710e492660d599571ec95e391fc57013237 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Wed, 21 Mar 2018 02:05:55 +0200 Subject: [PATCH] updated tests to fix deprecations also fixed cs errors in middleware-pipeline --- .../autoload/middleware-pipeline.global.php | 4 ++-- ...sponseImplicitOptionsMiddlewareFactory.php | 2 +- ...seImplicitOptionsMiddlewareFactoryTest.php | 2 +- .../CheckAuthenticationMiddlewareTest.php | 24 +++++++++++++------ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/config/autoload/middleware-pipeline.global.php b/config/autoload/middleware-pipeline.global.php index da661abe..3157f6ee 100644 --- a/config/autoload/middleware-pipeline.global.php +++ b/config/autoload/middleware-pipeline.global.php @@ -29,7 +29,7 @@ return [ 'routing' => [ 'middleware' => [ - Expressive\Router\Middleware\RouteMiddleware::class + Expressive\Router\Middleware\RouteMiddleware::class, ], 'priority' => 10, ], @@ -47,7 +47,7 @@ return [ 'post-routing' => [ 'middleware' => [ - Expressive\Router\Middleware\DispatchMiddleware::class + Expressive\Router\Middleware\DispatchMiddleware::class, ], 'priority' => 1, ], diff --git a/module/Common/src/Factory/EmptyResponseImplicitOptionsMiddlewareFactory.php b/module/Common/src/Factory/EmptyResponseImplicitOptionsMiddlewareFactory.php index 2ddf4080..89858e8c 100644 --- a/module/Common/src/Factory/EmptyResponseImplicitOptionsMiddlewareFactory.php +++ b/module/Common/src/Factory/EmptyResponseImplicitOptionsMiddlewareFactory.php @@ -6,7 +6,7 @@ namespace Shlinkio\Shlink\Common\Factory; use Interop\Container\ContainerInterface; use Interop\Container\Exception\ContainerException; use Zend\Diactoros\Response\EmptyResponse; -use Zend\Expressive\Middleware\ImplicitOptionsMiddleware; +use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware; use Zend\ServiceManager\Exception\ServiceNotCreatedException; use Zend\ServiceManager\Exception\ServiceNotFoundException; use Zend\ServiceManager\Factory\FactoryInterface; diff --git a/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php b/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php index dd4b6301..11b76440 100644 --- a/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php +++ b/module/Common/test/Factory/EmptyResponseImplicitOptionsMiddlewareFactoryTest.php @@ -6,7 +6,7 @@ namespace ShlinkioTest\Shlink\Common\Factory; use PHPUnit\Framework\TestCase; use Shlinkio\Shlink\Common\Factory\EmptyResponseImplicitOptionsMiddlewareFactory; use Zend\Diactoros\Response\EmptyResponse; -use Zend\Expressive\Middleware\ImplicitOptionsMiddleware; +use Zend\Expressive\Router\Middleware\ImplicitOptionsMiddleware; use Zend\ServiceManager\ServiceManager; class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase diff --git a/module/Rest/test/Middleware/CheckAuthenticationMiddlewareTest.php b/module/Rest/test/Middleware/CheckAuthenticationMiddlewareTest.php index 1600f877..5fd78a7b 100644 --- a/module/Rest/test/Middleware/CheckAuthenticationMiddlewareTest.php +++ b/module/Rest/test/Middleware/CheckAuthenticationMiddlewareTest.php @@ -17,6 +17,8 @@ use Zend\Expressive\Router\Route; use Zend\Expressive\Router\RouteResult; use Zend\I18n\Translator\Translator; +use function Zend\Stratigility\middleware; + class CheckAuthenticationMiddlewareTest extends TestCase { /** @@ -32,6 +34,9 @@ class CheckAuthenticationMiddlewareTest extends TestCase { $this->jwtService = $this->prophesize(JWTService::class); $this->middleware = new CheckAuthenticationMiddleware($this->jwtService->reveal(), Translator::factory([])); + $this->dummyMiddleware = middleware(function ($request, $handler) { + return new Response\EmptyResponse; + }); } /** @@ -59,7 +64,12 @@ class CheckAuthenticationMiddlewareTest extends TestCase $request = ServerRequestFactory::fromGlobals()->withAttribute( RouteResult::class, - RouteResult::fromRoute(new Route('foo', '', Route::HTTP_METHOD_ANY, AuthenticateAction::class)) + RouteResult::fromRoute(new Route( + 'foo', + $this->dummyMiddleware, + Route::HTTP_METHOD_ANY, + AuthenticateAction::class + )) ); $delegate = $this->prophesize(DelegateInterface::class); /** @var MethodProphecy $process */ @@ -69,7 +79,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase $request = ServerRequestFactory::fromGlobals()->withAttribute( RouteResult::class, - RouteResult::fromRoute(new Route('bar', 'foo'), []) + RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), []) )->withMethod('OPTIONS'); $delegate = $this->prophesize(DelegateInterface::class); /** @var MethodProphecy $process */ @@ -85,7 +95,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase { $request = ServerRequestFactory::fromGlobals()->withAttribute( RouteResult::class, - RouteResult::fromRoute(new Route('bar', 'foo'), []) + RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), []) ); $response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal()); $this->assertEquals(401, $response->getStatusCode()); @@ -99,7 +109,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase $authToken = 'ABC-abc'; $request = ServerRequestFactory::fromGlobals()->withAttribute( RouteResult::class, - RouteResult::fromRoute(new Route('bar', 'foo'), []) + RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), []) )->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, $authToken); $response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal()); @@ -116,7 +126,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase $authToken = 'ABC-abc'; $request = ServerRequestFactory::fromGlobals()->withAttribute( RouteResult::class, - RouteResult::fromRoute(new Route('bar', 'foo'), []) + RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), []) )->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Basic ' . $authToken); $response = $this->middleware->process($request, TestUtils::createDelegateMock()->reveal()); @@ -135,7 +145,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase $authToken = 'ABC-abc'; $request = ServerRequestFactory::fromGlobals()->withAttribute( RouteResult::class, - RouteResult::fromRoute(new Route('bar', 'foo'), []) + RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), []) )->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'Bearer ' . $authToken); $this->jwtService->verify($authToken)->willReturn(false)->shouldBeCalledTimes(1); @@ -151,7 +161,7 @@ class CheckAuthenticationMiddlewareTest extends TestCase $authToken = 'ABC-abc'; $request = ServerRequestFactory::fromGlobals()->withAttribute( RouteResult::class, - RouteResult::fromRoute(new Route('bar', 'foo'), []) + RouteResult::fromRoute(new Route('bar', $this->dummyMiddleware), []) )->withHeader(CheckAuthenticationMiddleware::AUTHORIZATION_HEADER, 'bearer ' . $authToken); $this->jwtService->verify($authToken)->willReturn(true)->shouldBeCalledTimes(1); $this->jwtService->refresh($authToken)->willReturn($authToken)->shouldBeCalledTimes(1);