|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Test: TracyToPsrLoggerAdapter. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +use Tester\Assert; |
| 10 | +use Tracy\Bridges\Psr\TracyToPsrLoggerAdapter; |
| 11 | +use Tracy\ILogger; |
| 12 | + |
| 13 | + |
| 14 | +require __DIR__ . '/../bootstrap.php'; |
| 15 | + |
| 16 | +class DummyTracyLogger implements ILogger |
| 17 | +{ |
| 18 | + /** @var array */ |
| 19 | + public $entries = []; |
| 20 | + |
| 21 | + |
| 22 | + public function log($value, string $priority = self::INFO) |
| 23 | + { |
| 24 | + $this->entries[] = [$priority, $value]; |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | + |
| 29 | +$tracyLogger = new DummyTracyLogger; |
| 30 | +$psrLogger = new TracyToPsrLoggerAdapter($tracyLogger); |
| 31 | +$exception = new \Exception('Something went wrong'); |
| 32 | + |
| 33 | +$psrLogger->info('info'); |
| 34 | +$psrLogger->warning('warning'); |
| 35 | +$psrLogger->error('order failed with exception', ['exception' => $exception]); |
| 36 | +$psrLogger->error('order failed with context', ['orderId' => 123]); |
| 37 | +$psrLogger->error('order failed with context and exception', ['orderId' => 123, 'exception' => $exception]); |
| 38 | + |
| 39 | +Assert::same([ |
| 40 | + [ILogger::INFO, 'info'], |
| 41 | + [ILogger::WARNING, 'warning'], |
| 42 | + [ILogger::ERROR, $exception], |
| 43 | + [ILogger::ERROR, 'order failed with exception'], |
| 44 | + [ILogger::ERROR, ['message' => 'order failed with context', 'context' => ['orderId' => 123]]], |
| 45 | + [ILogger::ERROR, $exception], |
| 46 | + [ILogger::ERROR, ['message' => 'order failed with context and exception', 'context' => ['orderId' => 123]]], |
| 47 | +], $tracyLogger->entries); |
0 commit comments