mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-23 01:16:23 -06:00
updated tests to fix deprecations
also fixed cs errors in middleware-pipeline
This commit is contained in:
parent
d3b5cd5c57
commit
f7e63710e4
@ -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,
|
||||
],
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user