shlink/module/Core/test/ErrorHandler/NotFoundTrackerMiddlewareTest.php

44 lines
1.5 KiB
PHP
Raw Normal View History

2021-02-08 15:16:15 -06:00
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\ErrorHandler;
use Laminas\Diactoros\ServerRequestFactory;
use PHPUnit\Framework\MockObject\MockObject;
2021-02-08 15:16:15 -06:00
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType;
use Shlinkio\Shlink\Core\ErrorHandler\NotFoundTrackerMiddleware;
use Shlinkio\Shlink\Core\Visit\RequestTrackerInterface;
2021-02-08 15:16:15 -06:00
class NotFoundTrackerMiddlewareTest extends TestCase
{
private NotFoundTrackerMiddleware $middleware;
private ServerRequestInterface $request;
2022-10-24 12:53:13 -05:00
private MockObject & RequestHandlerInterface $handler;
private MockObject & RequestTrackerInterface $requestTracker;
2021-02-08 15:16:15 -06:00
protected function setUp(): void
{
$this->handler = $this->createMock(RequestHandlerInterface::class);
$this->requestTracker = $this->createMock(RequestTrackerInterface::class);
$this->middleware = new NotFoundTrackerMiddleware($this->requestTracker);
2021-02-08 15:16:15 -06:00
$this->request = ServerRequestFactory::fromGlobals()->withAttribute(
NotFoundType::class,
$this->createMock(NotFoundType::class),
2021-02-08 15:16:15 -06:00
);
}
/** @test */
public function delegatesIntoRequestTracker(): void
2021-02-08 15:16:15 -06:00
{
$this->handler->expects($this->once())->method('handle')->with($this->request);
$this->requestTracker->expects($this->once())->method('trackNotFoundIfApplicable')->with($this->request);
2021-02-08 15:16:15 -06:00
$this->middleware->process($this->request, $this->handler);
2021-02-08 15:16:15 -06:00
}
}