mirror of
https://github.com/shlinkio/shlink.git
synced 2024-12-31 19:26:58 -06:00
Migrated NotFoundTrackerMiddlewareTest to use PHPUnit mocks
This commit is contained in:
parent
d842025835
commit
ff543b151c
@ -4,12 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace ShlinkioTest\Shlink\Core\ErrorHandler;
|
||||
|
||||
use Laminas\Diactoros\Response;
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
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;
|
||||
@ -18,35 +15,31 @@ use Shlinkio\Shlink\Core\Visit\RequestTrackerInterface;
|
||||
|
||||
class NotFoundTrackerMiddlewareTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
private NotFoundTrackerMiddleware $middleware;
|
||||
private ServerRequestInterface $request;
|
||||
private ObjectProphecy $requestTracker;
|
||||
private ObjectProphecy $notFoundType;
|
||||
private ObjectProphecy $handler;
|
||||
private MockObject $handler;
|
||||
private MockObject $requestTracker;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->notFoundType = $this->prophesize(NotFoundType::class);
|
||||
$this->handler = $this->prophesize(RequestHandlerInterface::class);
|
||||
$this->handler->handle(Argument::cetera())->willReturn(new Response());
|
||||
|
||||
$this->requestTracker = $this->prophesize(RequestTrackerInterface::class);
|
||||
$this->middleware = new NotFoundTrackerMiddleware($this->requestTracker->reveal());
|
||||
$this->handler = $this->createMock(RequestHandlerInterface::class);
|
||||
$this->requestTracker = $this->createMock(RequestTrackerInterface::class);
|
||||
$this->middleware = new NotFoundTrackerMiddleware($this->requestTracker);
|
||||
|
||||
$this->request = ServerRequestFactory::fromGlobals()->withAttribute(
|
||||
NotFoundType::class,
|
||||
$this->notFoundType->reveal(),
|
||||
$this->createMock(NotFoundType::class),
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function delegatesIntoRequestTracker(): void
|
||||
{
|
||||
$this->middleware->process($this->request, $this->handler->reveal());
|
||||
$this->handler->expects($this->once())->method('handle')->with($this->equalTo($this->request));
|
||||
$this->requestTracker->expects($this->once())->method('trackNotFoundIfApplicable')->with(
|
||||
$this->equalTo($this->request),
|
||||
);
|
||||
|
||||
$this->requestTracker->trackNotFoundIfApplicable($this->request)->shouldHaveBeenCalledOnce();
|
||||
$this->handler->handle($this->request)->shouldHaveBeenCalledOnce();
|
||||
$this->middleware->process($this->request, $this->handler);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user