Created NotFoundTypeResolverMiddlewareTest

This commit is contained in:
Alejandro Celaya 2021-02-08 22:06:03 +01:00
parent 55e7f7ccb0
commit 0e165bc7e0

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ErrorHandler;
use Laminas\Diactoros\Response;
use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType;
use Shlinkio\Shlink\Core\ErrorHandler\NotFoundTypeResolverMiddleware;
class NotFoundTypeResolverMiddlewareTest extends TestCase
{
use ProphecyTrait;
private NotFoundTypeResolverMiddleware $middleware;
private ObjectProphecy $handler;
protected function setUp(): void
{
$this->middleware = new NotFoundTypeResolverMiddleware('');
$this->handler = $this->prophesize(RequestHandlerInterface::class);
}
/** @test */
public function notFoundTypeIsAddedToRequest(): void
{
$request = ServerRequestFactory::fromGlobals();
$handle = $this->handler->handle(Argument::that(function (ServerRequestInterface $req) {
Assert::assertArrayHasKey(NotFoundType::class, $req->getAttributes());
return true;
}))->willReturn(new Response());
$this->middleware->process($request, $this->handler->reveal());
self::assertArrayNotHasKey(NotFoundType::class, $request->getAttributes());
$handle->shouldHaveBeenCalledOnce();
}
}