-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathLogWriterFactoryTest.php
More file actions
58 lines (50 loc) · 1.85 KB
/
LogWriterFactoryTest.php
File metadata and controls
58 lines (50 loc) · 1.85 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
55
56
57
58
<?php
declare(strict_types=1);
namespace OpenTelemetry\Tests\Unit\API\Behavior\Internal;
use OpenTelemetry\API\Behavior\Internal\LogWriter\ErrorLogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\NoopLogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\Psr3LogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\StreamLogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriter\TriggerErrorLogWriter;
use OpenTelemetry\API\Behavior\Internal\LogWriterFactory;
use OpenTelemetry\API\LoggerHolder;
use OpenTelemetry\Tests\TestState;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
#[CoversClass(LogWriterFactory::class)]
class LogWriterFactoryTest extends TestCase
{
use TestState;
#[\Override]
public function setUp(): void
{
LoggerHolder::unset();
}
/**
* @psalm-suppress ArgumentTypeCoercion
*/
#[DataProvider('logDestinationProvider')]
public function test_log_destination_from_env(string $value, string $expected): void
{
$this->setEnvironmentVariable('OTEL_PHP_LOG_DESTINATION', $value);
$this->assertInstanceOf($expected, (new LogWriterFactory())->create());
}
public static function logDestinationProvider(): array
{
return [
['error_log', ErrorLogWriter::class],
['trigger_error', TriggerErrorLogWriter::class],
['stdout', StreamLogWriter::class],
['stderr', StreamLogWriter::class],
['none', NoopLogWriter::class],
['', ErrorLogWriter::class],
];
}
public function test_psr3_log_destination(): void
{
LoggerHolder::set($this->createMock(LoggerInterface::class));
$this->assertInstanceOf(Psr3LogWriter::class, (new LogWriterFactory())->create());
}
}