-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathPsr3LogWriterTest.php
More file actions
50 lines (40 loc) · 1.58 KB
/
Psr3LogWriterTest.php
File metadata and controls
50 lines (40 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
declare(strict_types=1);
namespace OpenTelemetry\Tests\Unit\API\Behavior\Internal\LogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\Psr3LogWriter;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
#[CoversClass(Psr3LogWriter::class)]
final class Psr3LogWriterTest extends TestCase
{
public function test_write_delegates_to_psr3_logger(): void
{
$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->once())
->method('log')
->with('warning', 'test message', ['key' => 'value']);
$writer = new Psr3LogWriter($logger);
$writer->write('warning', 'test message', ['key' => 'value']);
}
public function test_write_passes_level_through(): void
{
$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->once())
->method('log')
->with('error', 'error message', []);
$writer = new Psr3LogWriter($logger);
$writer->write('error', 'error message', []);
}
public function test_write_passes_context_with_exception(): void
{
$exception = new \RuntimeException('test exception');
$context = ['exception' => $exception, 'extra' => 'data'];
$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->once())
->method('log')
->with('critical', 'something broke', $context);
$writer = new Psr3LogWriter($logger);
$writer->write('critical', 'something broke', $context);
}
}