Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
brettmc committed Apr 29, 2024
1 parent 829afad commit 9b20ddb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/Unit/API/Instrumentation/InstrumentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -49,19 +53,22 @@ 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 {
$this->assertSame($tracerProvider, Globals::tracerProvider());
$this->assertSame($meterProvider, Globals::meterProvider());
$this->assertSame($propagator, Globals::propagator());
$this->assertSame($loggerProvider, Globals::loggerProvider());
$this->assertSame($eventLoggerProvider, Globals::eventLoggerProvider());
} finally {
$scope->detach();
}
Expand All @@ -88,19 +95,24 @@ 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();

try {
$this->assertSame($tracer, $instrumentation->tracer());
$this->assertSame($meter, $instrumentation->meter());
$this->assertSame($logger, $instrumentation->logger());
$this->assertSame($eventLogger, $instrumentation->eventLogger());
} finally {
$scope->detach();
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/SDK/SdkBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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();
}
}

0 comments on commit 9b20ddb

Please sign in to comment.