mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 15:23:12 +08:00
Simplified code to render not-foubnd templates by infering the template to be used inside NotFoundHandler
This commit is contained in:
@@ -110,4 +110,33 @@ class NotFoundHandlerTest extends TestCase
|
||||
'invalidShortUrl',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider provideTemplates
|
||||
*/
|
||||
public function properErrorTemplateIsRendered(ServerRequestInterface $request, string $expectedTemplate): void
|
||||
{
|
||||
$request = $request->withHeader('Accept', 'text/html');
|
||||
$render = $this->renderer->render($expectedTemplate)->willReturn('');
|
||||
|
||||
$resp = $this->delegate->handle($request);
|
||||
|
||||
$this->assertInstanceOf(Response\HtmlResponse::class, $resp);
|
||||
$render->shouldHaveBeenCalledOnce();
|
||||
}
|
||||
|
||||
public function provideTemplates(): iterable
|
||||
{
|
||||
$request = ServerRequestFactory::fromGlobals();
|
||||
|
||||
yield [$request, NotFoundHandler::NOT_FOUND_ERROR_TEMPLATE];
|
||||
yield [
|
||||
$request->withAttribute(
|
||||
RouteResult::class,
|
||||
RouteResult::fromRoute(new Route('', $this->prophesize(MiddlewareInterface::class)->reveal()))
|
||||
),
|
||||
NotFoundHandler::INVALID_SHORT_CODE_ERROR_TEMPLATE,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user