mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-28 09:03:07 +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\Response;
|
||||||
use Laminas\Diactoros\ServerRequestFactory;
|
use Laminas\Diactoros\ServerRequestFactory;
|
||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\Argument;
|
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Psr\Http\Server\RequestHandlerInterface;
|
use Psr\Http\Server\RequestHandlerInterface;
|
||||||
use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType;
|
use Shlinkio\Shlink\Core\ErrorHandler\Model\NotFoundType;
|
||||||
|
@ -18,30 +16,28 @@ use Shlinkio\Shlink\Core\ErrorHandler\NotFoundTypeResolverMiddleware;
|
||||||
|
|
||||||
class NotFoundTypeResolverMiddlewareTest extends TestCase
|
class NotFoundTypeResolverMiddlewareTest extends TestCase
|
||||||
{
|
{
|
||||||
use ProphecyTrait;
|
|
||||||
|
|
||||||
private NotFoundTypeResolverMiddleware $middleware;
|
private NotFoundTypeResolverMiddleware $middleware;
|
||||||
private ObjectProphecy $handler;
|
private MockObject $handler;
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
$this->middleware = new NotFoundTypeResolverMiddleware('');
|
$this->middleware = new NotFoundTypeResolverMiddleware('');
|
||||||
$this->handler = $this->prophesize(RequestHandlerInterface::class);
|
$this->handler = $this->createMock(RequestHandlerInterface::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function notFoundTypeIsAddedToRequest(): void
|
public function notFoundTypeIsAddedToRequest(): void
|
||||||
{
|
{
|
||||||
$request = ServerRequestFactory::fromGlobals();
|
$request = ServerRequestFactory::fromGlobals();
|
||||||
$handle = $this->handler->handle(Argument::that(function (ServerRequestInterface $req) {
|
$this->handler->expects($this->once())->method('handle')->with(
|
||||||
Assert::assertArrayHasKey(NotFoundType::class, $req->getAttributes());
|
$this->callback(function (ServerRequestInterface $req): bool {
|
||||||
|
Assert::assertArrayHasKey(NotFoundType::class, $req->getAttributes());
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
)->willReturn(new Response());
|
||||||
|
|
||||||
return true;
|
$this->middleware->process($request, $this->handler);
|
||||||
}))->willReturn(new Response());
|
|
||||||
|
|
||||||
$this->middleware->process($request, $this->handler->reveal());
|
|
||||||
|
|
||||||
self::assertArrayNotHasKey(NotFoundType::class, $request->getAttributes());
|
self::assertArrayNotHasKey(NotFoundType::class, $request->getAttributes());
|
||||||
$handle->shouldHaveBeenCalledOnce();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue