Skip to content

Commit

Permalink
improving more tests (#1127)
Browse files Browse the repository at this point in the history
  • Loading branch information
weslenteche authored Oct 15, 2023
1 parent ea86fe1 commit f22ffa0
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 1 deletion.
46 changes: 46 additions & 0 deletions tests/Unit/SDK/FactoryRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace OpenTelemetry\Tests\Unit\SDK;

use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface;
use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface;
use OpenTelemetry\SDK\Logs\LogRecordExporterFactoryInterface;
use OpenTelemetry\SDK\Metrics\MetricExporterFactoryInterface;
use OpenTelemetry\SDK\Registry;
use OpenTelemetry\SDK\Trace\SpanExporter\SpanExporterFactoryInterface;
Expand Down Expand Up @@ -74,6 +76,41 @@ public static function metricExporterProvider(): array
];
}

/**
* @dataProvider logRecordExporterProvider
*/
public function test_default_log_record_exporter_factories(string $name): void
{
$factory = Registry::logRecordExporterFactory($name);
$this->assertInstanceOf(LogRecordExporterFactoryInterface::class, $factory);
}

public static function logRecordExporterProvider(): array
{
return [
['console'],
['memory'],
];
}

/**
* @dataProvider textMapPropagator
*/
public function test_default_text_map_propagator(string $name): void
{
$propagator = Registry::textMapPropagator($name);
$this->assertInstanceOf(TextMapPropagatorInterface::class, $propagator);
}

public static function textMapPropagator(): array
{
return [
['tracecontext'],
['b3multi'],
['b3'],
];
}

/**
* @dataProvider invalidFactoryProvider
*/
Expand Down Expand Up @@ -101,6 +138,15 @@ public function test_register_invalid_metric_exporter_factory($factory): void
Registry::registerMetricExporterFactory('foo', $factory, true);
}

/**
* @dataProvider invalidFactoryProvider
*/
public function test_register_invalid_log_record_exporter_factory($factory): void
{
$this->expectException(PHPUnitFrameworkException::class);
Registry::registerLogRecordExporterFactory('foo', $factory, true);
}

public static function invalidFactoryProvider(): array
{
return [
Expand Down
21 changes: 21 additions & 0 deletions tests/Unit/SDK/Logs/Exporter/InMemoryExporterFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Tests\Unit\SDK\Logs\Exporter;

use OpenTelemetry\SDK\Logs\Exporter\InMemoryExporterFactory;
use OpenTelemetry\SDK\Logs\LogRecordExporterInterface;
use PHPUnit\Framework\TestCase;

/**
* @covers \OpenTelemetry\SDK\Logs\Exporter\InMemoryExporterFactory
*/
class InMemoryExporterFactoryTest extends TestCase
{
public function test_create(): void
{
$factory = new InMemoryExporterFactory();
$this->assertInstanceOf(LogRecordExporterInterface::class, $factory->create());
}
}
51 changes: 51 additions & 0 deletions tests/Unit/SDK/Logs/Exporter/InMemoryExporterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Tests\Unit\SDK\Logs\Exporter;

use OpenTelemetry\API\Logs\LogRecord;
use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeInterface;
use OpenTelemetry\SDK\Logs\Exporter\InMemoryExporter;
use OpenTelemetry\SDK\Logs\LoggerSharedState;
use OpenTelemetry\SDK\Logs\ReadableLogRecord;
use PHPUnit\Framework\TestCase;

/**
* @covers \OpenTelemetry\SDK\Logs\Exporter\InMemoryExporter
* @psalm-suppress UndefinedInterfaceMethod
*/
class InMemoryExporterTest extends TestCase
{
public function test_export(): void
{
$exporter = new InMemoryExporter();
$batch = [
(new ReadableLogRecord(
$this->createMock(InstrumentationScopeInterface::class),
$this->createMock(LoggerSharedState::class),
(new LogRecord('foo')),
)),
];

$this->assertTrue($exporter->export($batch)->await());
}

public function test_force_flush(): void
{
$exporter = new InMemoryExporter();
$this->assertTrue($exporter->forceFlush());
}

public function test_shutdown(): void
{
$exporter = new InMemoryExporter();
$this->assertTrue($exporter->shutdown());
}

public function test_storage(): void
{
$exporter = new InMemoryExporter();
$this->assertCount(0, $exporter->getStorage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Tests\Unit\SDK\Metrics\MetricExporter;

use OpenTelemetry\SDK\Metrics\MetricExporter\InMemoryExporterFactory;
use OpenTelemetry\SDK\Metrics\MetricExporterInterface;
use PHPUnit\Framework\TestCase;

/**
* @covers \OpenTelemetry\SDK\Metrics\MetricExporter\InMemoryExporterFactory
*/
class InMemoryExporterFactoryTest extends TestCase
{
public function test_create(): void
{
$exporter = (new InMemoryExporterFactory())->create();
$this->assertInstanceOf(MetricExporterInterface::class, $exporter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Tests\Unit\SDK\Metrics\MetricExporter;

use OpenTelemetry\SDK\Metrics\MetricExporter\NoopMetricExporterFactory;
use OpenTelemetry\SDK\Metrics\MetricExporterInterface;
use PHPUnit\Framework\TestCase;

/**
* @covers \OpenTelemetry\SDK\Metrics\MetricExporter\NoopMetricExporterFactory
*/
class NoopMetricExporterFactoryTest extends TestCase
{
public function test_create(): void
{
$exporter = (new NoopMetricExporterFactory())->create();
$this->assertInstanceOf(MetricExporterInterface::class, $exporter);
}
}
3 changes: 2 additions & 1 deletion tests/Unit/SDK/SdkBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function setUp(): void
->setMeterProvider($this->meterProvider)
->setLoggerProvider($this->loggerProvider)
->setPropagator($this->propagator)
->setTracerProvider($this->tracerProvider);
->setTracerProvider($this->tracerProvider)
->setAutoShutdown(true);
}

public function test_build(): void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Tests\Unit\SDK\Trace\SpanExporter;

use OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporterFactory;
use OpenTelemetry\SDK\Trace\SpanExporterInterface;
use PHPUnit\Framework\TestCase;

/**
* @covers \OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporterFactory
*/
class ConsoleSpanExporterFactoryTest extends TestCase
{
public function test_create(): void
{
$exporter = (new ConsoleSpanExporterFactory())->create();
$this->assertInstanceOf(SpanExporterInterface::class, $exporter);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace OpenTelemetry\Tests\Unit\SDK\Trace\SpanExporter;

use OpenTelemetry\SDK\Trace\SpanExporter\InMemorySpanExporterFactory;
use OpenTelemetry\SDK\Trace\SpanExporterInterface;
use PHPUnit\Framework\TestCase;

/**
* @covers \OpenTelemetry\SDK\Trace\SpanExporter\InMemorySpanExporterFactory
*/
class InMemorySpanExporterFactoryTest extends TestCase
{
public function test_create(): void
{
$exporter = (new InMemorySpanExporterFactory())->create();
$this->assertInstanceOf(SpanExporterInterface::class, $exporter);
}
}

0 comments on commit f22ffa0

Please sign in to comment.