Fixed use of ImplicitOptionsMiddleware with its new signature

This commit is contained in:
Alejandro Celaya 2021-07-30 18:05:03 +02:00
parent ea735fc0a0
commit 7b9ebbbb5f
2 changed files with 14 additions and 2 deletions

View File

@ -6,11 +6,18 @@ namespace Shlinkio\Shlink\Rest\Middleware;
use Laminas\Diactoros\Response\EmptyResponse;
use Mezzio\Router\Middleware\ImplicitOptionsMiddleware;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
class EmptyResponseImplicitOptionsMiddlewareFactory
{
public function __invoke(): ImplicitOptionsMiddleware
{
return new ImplicitOptionsMiddleware(fn () => new EmptyResponse());
return new ImplicitOptionsMiddleware(new class implements ResponseFactoryInterface {
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
{
return new EmptyResponse();
}
});
}
}

View File

@ -7,6 +7,7 @@ namespace ShlinkioTest\Shlink\Rest\Middleware;
use Laminas\Diactoros\Response\EmptyResponse;
use Mezzio\Router\Middleware\ImplicitOptionsMiddleware;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseFactoryInterface;
use ReflectionObject;
use Shlinkio\Shlink\Rest\Middleware\EmptyResponseImplicitOptionsMiddlewareFactory;
@ -34,6 +35,10 @@ class EmptyResponseImplicitOptionsMiddlewareFactoryTest extends TestCase
$ref = new ReflectionObject($instance);
$prop = $ref->getProperty('responseFactory');
$prop->setAccessible(true);
self::assertInstanceOf(EmptyResponse::class, $prop->getValue($instance)());
/** @var ResponseFactoryInterface $value */
$value = $prop->getValue($instance);
self::assertInstanceOf(EmptyResponse::class, $value->createResponse());
}
}