1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-19 03:11:19 +02:00

Also add setBasePath to NormalizerFormatter/JsonFormatter

This commit is contained in:
Jordi Boggiano
2024-06-28 10:39:13 +02:00
parent a4471eb05b
commit 47e301d3e2
3 changed files with 54 additions and 2 deletions

View File

@@ -118,6 +118,18 @@ class JsonFormatterTest extends TestCase
$this->assertContextContainsFormattedException($formattedException, $message);
}
public function testBasePathWithException(): void
{
$formatter = new JsonFormatter();
$formatter->setBasePath(dirname(dirname(dirname(__DIR__))));
$exception = new \RuntimeException('Foo');
$message = $this->formatRecordWithExceptionInContext($formatter, $exception);
$parsed = json_decode($message, true);
self::assertSame('tests/Monolog/Formatter/JsonFormatterTest.php:' . (__LINE__ - 5), $parsed['context']['exception']['file']);
}
public function testDefFormatWithPreviousException()
{
$formatter = new JsonFormatter();

View File

@@ -81,6 +81,20 @@ class NormalizerFormatterTest extends TestCase
], $formatted);
}
public function testFormatExceptionWithBasePath(): void
{
$formatter = new NormalizerFormatter('Y-m-d');
$formatter->setBasePath(dirname(dirname(dirname(__DIR__))));
$e = new \LogicException('bar');
$formatted = $formatter->normalizeValue([
'exception' => $e,
]);
self::assertSame('tests/Monolog/Formatter/NormalizerFormatterTest.php:' . (__LINE__ - 5), $formatted['exception']['file']);
self::assertStringStartsWith('vendor/phpunit/phpunit/src/Framework/TestCase.php:', $formatted['exception']['trace'][0]);
self::assertStringStartsWith('vendor/phpunit/phpunit/src/Framework/TestCase.php:', $formatted['exception']['trace'][1]);
}
public function testFormatSoapFaultException()
{
if (!class_exists('SoapFault')) {