mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-24 13:49:03 +03:00
Migrated NotFoundTypeResolverMiddlewareTest to use PHPUnit mocks
This commit is contained in:
parent
ff543b151c
commit
bf0b58b344
1 changed files with 10 additions and 14 deletions
|
@ -7,10 +7,8 @@ namespace ShlinkioTest\Shlink\Core\ErrorHandler;
|
|||
use Laminas\Diactoros\Response;
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use PHPUnit\Framework\Assert;
|
||||
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,30 +16,28 @@ use Shlinkio\Shlink\Core\ErrorHandler\NotFoundTypeResolverMiddleware;
|
|||
|
||||
class NotFoundTypeResolverMiddlewareTest extends TestCase
|
||||
{
|
||||
use ProphecyTrait;
|
||||
|
||||
private NotFoundTypeResolverMiddleware $middleware;
|
||||
private ObjectProphecy $handler;
|
||||
private MockObject $handler;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->middleware = new NotFoundTypeResolverMiddleware('');
|
||||
$this->handler = $this->prophesize(RequestHandlerInterface::class);
|
||||
$this->handler = $this->createMock(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());
|
||||
$this->handler->expects($this->once())->method('handle')->with(
|
||||
$this->callback(function (ServerRequestInterface $req): bool {
|
||||
Assert::assertArrayHasKey(NotFoundType::class, $req->getAttributes());
|
||||
return true;
|
||||
}),
|
||||
)->willReturn(new Response());
|
||||
|
||||
return true;
|
||||
}))->willReturn(new Response());
|
||||
|
||||
$this->middleware->process($request, $this->handler->reveal());
|
||||
$this->middleware->process($request, $this->handler);
|
||||
|
||||
self::assertArrayNotHasKey(NotFoundType::class, $request->getAttributes());
|
||||
$handle->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue