Skip to content

Commit

Permalink
Merge branch '4.x' into add-psalm
Browse files Browse the repository at this point in the history
  • Loading branch information
akrabat committed Jun 13, 2024
2 parents 3ab597e + 8388b33 commit c7910ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Slim/Handlers/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ protected function writeToErrorLog(): void
{
$renderer = $this->callableResolver->resolve($this->logErrorRenderer);
$error = $renderer($this->exception, $this->logErrorDetails);
if (!$this->displayErrorDetails) {
if ($this->logErrorRenderer === PlainTextErrorRenderer::class && !$this->displayErrorDetails) {
$error .= "\nTips: To display error details in HTTP response ";
$error .= 'set "displayErrorDetails" to true in the ErrorHandler constructor.';
}
Expand Down
29 changes: 29 additions & 0 deletions tests/Handlers/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,35 @@ public function testWriteToErrorLogShowTip()
$handler->__invoke($request, $exception, false, true, true);
}

public function testWriteToErrorLogDoesNotShowTipIfErrorLogRendererIsNotPlainText()
{
$request = $this
->createServerRequest('/', 'GET')
->withHeader('Accept', 'application/json');

$logger = $this->getMockLogger();

$handler = new ErrorHandler(
$this->getCallableResolver(),
$this->getResponseFactory(),
$logger
);

$handler->setLogErrorRenderer(HtmlErrorRenderer::class);

$logger->expects(self::once())
->method('error')
->willReturnCallback(static function (string $error) {
self::assertStringNotContainsString(
'set "displayErrorDetails" to true in the ErrorHandler constructor',
$error
);
});

$exception = new HttpNotFoundException($request);
$handler->__invoke($request, $exception, false, true, true);
}

public function testDefaultErrorRenderer()
{
$request = $this
Expand Down

0 comments on commit c7910ea

Please sign in to comment.