-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathErrorLogWriterTest.php
More file actions
54 lines (43 loc) · 1.63 KB
/
ErrorLogWriterTest.php
File metadata and controls
54 lines (43 loc) · 1.63 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
51
52
53
54
<?php
declare(strict_types=1);
namespace OpenTelemetry\Tests\Unit\API\Behavior\Internal\LogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\ErrorLogWriter;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(ErrorLogWriter::class)]
final class ErrorLogWriterTest extends TestCase
{
public function test_write_calls_error_log(): void
{
$writer = new ErrorLogWriter();
// Capture error_log output by redirecting to a temp file
$file = tempnam(sys_get_temp_dir(), 'otel_errorlog_');
$this->assertNotFalse($file);
try {
ini_set('error_log', $file);
$writer->write('warning', 'test error log message', []);
$contents = file_get_contents($file);
$this->assertStringContainsString('test error log message', $contents);
} finally {
ini_restore('error_log');
unlink($file);
}
}
public function test_write_with_exception_context(): void
{
$writer = new ErrorLogWriter();
$file = tempnam(sys_get_temp_dir(), 'otel_errorlog_');
$this->assertNotFalse($file);
try {
ini_set('error_log', $file);
$exception = new \RuntimeException('boom');
$writer->write('error', 'failure occurred', ['exception' => $exception]);
$contents = file_get_contents($file);
$this->assertStringContainsString('failure occurred', $contents);
$this->assertStringContainsString('boom', $contents);
} finally {
ini_restore('error_log');
unlink($file);
}
}
}