2021-02-08 15:16:15 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace ShlinkioTest\Shlink\Core\ErrorHandler;
|
|
|
|
|
|
|
|
use Laminas\Diactoros\ServerRequestFactory;
|
2022-10-21 12:29:02 -05:00
|
|
|
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;
|
2021-07-15 10:23:09 -05:00
|
|
|
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
|
|
|
|
{
|
2022-10-21 12:29:02 -05:00
|
|
|
$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,
|
2022-10-21 12:29:02 -05:00
|
|
|
$this->createMock(NotFoundType::class),
|
2021-02-08 15:16:15 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
2021-07-15 10:23:09 -05:00
|
|
|
public function delegatesIntoRequestTracker(): void
|
2021-02-08 15:16:15 -06:00
|
|
|
{
|
2022-10-23 11:15:57 -05: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
|
|
|
|
2022-10-21 12:29:02 -05:00
|
|
|
$this->middleware->process($this->request, $this->handler);
|
2021-02-08 15:16:15 -06:00
|
|
|
}
|
|
|
|
}
|