. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fig\Http\Message\RequestMethodInterface; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\TestCase; use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Server\RequestHandlerInterface; use function app; use function response; /** * Test the CheckCsrf middleware. * * @covers \Fisharebest\Webtrees\Http\Middleware\CheckCsrf */ class CheckCsrfTest extends TestCase { /** * @return void */ public function testMiddleware(): void { $handler = self::createMock(RequestHandlerInterface::class); $handler->method('handle')->willReturn(response()); $request = self::createRequest(RequestMethodInterface::METHOD_POST) ->withUri(app(UriFactoryInterface::class)->createUri('http://example.com')); $middleware = new CheckCsrf(); $response = $middleware->process($request, $handler); self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode()); self::assertSame('http://example.com', $response->getHeaderLine('Location')); } }