Simplified code to render not-foubnd templates by infering the template to be used inside NotFoundHandler

This commit is contained in:
Alejandro Celaya
2019-11-02 18:49:24 +01:00
parent 01f60614ef
commit 906dfe60f8
6 changed files with 44 additions and 44 deletions

View File

@@ -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,
];
}
}