From 9b20ddb9bab792a6fa15f1f38d7c2d527a4a9a08 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Mon, 29 Apr 2024 13:00:54 +1000 Subject: [PATCH] test coverage --- .../Unit/API/Instrumentation/InstrumentationTest.php | 12 ++++++++++++ tests/Unit/SDK/SdkBuilderTest.php | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/tests/Unit/API/Instrumentation/InstrumentationTest.php b/tests/Unit/API/Instrumentation/InstrumentationTest.php index ce96727b5..90e61f310 100644 --- a/tests/Unit/API/Instrumentation/InstrumentationTest.php +++ b/tests/Unit/API/Instrumentation/InstrumentationTest.php @@ -7,8 +7,11 @@ use OpenTelemetry\API\Globals; use OpenTelemetry\API\Instrumentation\CachedInstrumentation; use OpenTelemetry\API\Instrumentation\Configurator; +use OpenTelemetry\API\Logs\EventLoggerInterface; +use OpenTelemetry\API\Logs\EventLoggerProviderInterface; use OpenTelemetry\API\Logs\LoggerInterface; use OpenTelemetry\API\Logs\LoggerProviderInterface; +use OpenTelemetry\API\Logs\NoopEventLoggerProvider; use OpenTelemetry\API\Logs\NoopLoggerProvider; use OpenTelemetry\API\Metrics\MeterInterface; use OpenTelemetry\API\Metrics\MeterProviderInterface; @@ -41,6 +44,7 @@ public function test_globals_not_configured_returns_noop_instances(): void $this->assertInstanceOf(NoopMeterProvider::class, Globals::meterProvider()); $this->assertInstanceOf(NoopTextMapPropagator::class, Globals::propagator()); $this->assertInstanceOf(NoopLoggerProvider::class, Globals::loggerProvider()); + $this->assertInstanceOf(NoopEventLoggerProvider::class, Globals::eventLoggerProvider()); } public function test_globals_returns_configured_instances(): void @@ -49,12 +53,14 @@ public function test_globals_returns_configured_instances(): void $meterProvider = $this->createMock(MeterProviderInterface::class); $propagator = $this->createMock(TextMapPropagatorInterface::class); $loggerProvider = $this->createMock(LoggerProviderInterface::class); + $eventLoggerProvider = $this->createMock(EventLoggerProviderInterface::class); $scope = Configurator::create() ->withTracerProvider($tracerProvider) ->withMeterProvider($meterProvider) ->withPropagator($propagator) ->withLoggerProvider($loggerProvider) + ->withEventLoggerProvider($eventLoggerProvider) ->activate(); try { @@ -62,6 +68,7 @@ public function test_globals_returns_configured_instances(): void $this->assertSame($meterProvider, Globals::meterProvider()); $this->assertSame($propagator, Globals::propagator()); $this->assertSame($loggerProvider, Globals::loggerProvider()); + $this->assertSame($eventLoggerProvider, Globals::eventLoggerProvider()); } finally { $scope->detach(); } @@ -88,12 +95,16 @@ public function test_instrumentation_returns_configured_instances(): void $logger = $this->createMock(LoggerInterface::class); $loggerProvider = $this->createMock(LoggerProviderInterface::class); $loggerProvider->method('getLogger')->willReturn($logger); + $eventLogger = $this->createMock(EventLoggerInterface::class); + $eventLoggerProvider = $this->createMock(EventLoggerProviderInterface::class); + $eventLoggerProvider->method('getEventLogger')->willReturn($eventLogger); $propagator = $this->createMock(TextMapPropagatorInterface::class); $scope = Configurator::create() ->withTracerProvider($tracerProvider) ->withMeterProvider($meterProvider) ->withLoggerProvider($loggerProvider) + ->withEventLoggerProvider($eventLoggerProvider) ->withPropagator($propagator) ->activate(); @@ -101,6 +112,7 @@ public function test_instrumentation_returns_configured_instances(): void $this->assertSame($tracer, $instrumentation->tracer()); $this->assertSame($meter, $instrumentation->meter()); $this->assertSame($logger, $instrumentation->logger()); + $this->assertSame($eventLogger, $instrumentation->eventLogger()); } finally { $scope->detach(); } diff --git a/tests/Unit/SDK/SdkBuilderTest.php b/tests/Unit/SDK/SdkBuilderTest.php index 0d05cd123..48baabaae 100644 --- a/tests/Unit/SDK/SdkBuilderTest.php +++ b/tests/Unit/SDK/SdkBuilderTest.php @@ -5,6 +5,7 @@ namespace OpenTelemetry\Tests\Unit\SDK; use OpenTelemetry\API\Globals; +use OpenTelemetry\API\Logs\EventLoggerProviderInterface; use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; use OpenTelemetry\SDK\Logs\LoggerProviderInterface; use OpenTelemetry\SDK\Metrics\MeterProviderInterface; @@ -21,6 +22,7 @@ class SdkBuilderTest extends TestCase private TracerProviderInterface $tracerProvider; private MeterProviderInterface $meterProvider; private LoggerProviderInterface $loggerProvider; + private EventLoggerProviderInterface $eventLoggerProvider; private SdkBuilder $builder; public function setUp(): void @@ -29,9 +31,11 @@ public function setUp(): void $this->tracerProvider = $this->createMock(TracerProviderInterface::class); $this->meterProvider = $this->createMock(MeterProviderInterface::class); $this->loggerProvider = $this->createMock(LoggerProviderInterface::class); + $this->eventLoggerProvider = $this->createMock(EventLoggerProviderInterface::class); $this->builder = (new SdkBuilder()) ->setMeterProvider($this->meterProvider) ->setLoggerProvider($this->loggerProvider) + ->setEventLoggerProvider($this->eventLoggerProvider) ->setPropagator($this->propagator) ->setTracerProvider($this->tracerProvider) ->setAutoShutdown(true); @@ -44,6 +48,7 @@ public function test_build(): void $this->assertSame($this->propagator, $sdk->getPropagator()); $this->assertSame($this->tracerProvider, $sdk->getTracerProvider()); $this->assertSame($this->loggerProvider, $sdk->getLoggerProvider()); + $this->assertSame($this->eventLoggerProvider, $sdk->getEventLoggerProvider()); } public function test_build_and_register_global(): void @@ -53,6 +58,7 @@ public function test_build_and_register_global(): void $this->assertSame($this->propagator, Globals::propagator()); $this->assertSame($this->tracerProvider, Globals::tracerProvider()); $this->assertSame($this->loggerProvider, Globals::loggerProvider()); + $this->assertSame($this->eventLoggerProvider, Globals::eventLoggerProvider()); $scope->detach(); } }