From fbdb103590eb9cbe9051184c5fb6dd6f344afe21 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 16 May 2024 09:21:28 +1000 Subject: [PATCH] upgrade to phpunit 11 (#1308) * run unit tests in random order running in random order highlights some interference between tests (mostly logging being enabled), and is a requirement for mutation testing (ie, all tests must pass when executed in a random order). * adding infection mutation testing this adds the ability to run infection. It generates a lot of output, which is an exercise for another PR... * replace assertwell/phpunit-global-state the package was not compatible with phpunit 11. create out own test Trait, which handles env vars, as well as general cleanup of the usual suspects of state that our tests mess up * remove redundant tearDown functions there's an after annotation on the trait to handle this * use rector to upgrade tests for phpunit 11 * fixing CoversFunction for namespaced functions * use FQNs in test attributes --- Makefile | 4 +- composer.json | 3 +- rector.php | 1 + tests/Benchmark/OtlpBench.php | 6 +- .../Integration/Config/ConfigurationTest.php | 10 +- .../Integration/SDK/AlwaysOffSamplerTest.php | 5 +- tests/Integration/SDK/AlwaysOnSamplerTest.php | 5 +- .../SDK/Context/SpanContextTest.php | 19 +- tests/Integration/SDK/MeterProviderTest.php | 14 +- tests/Integration/SDK/MeterTest.php | 26 +-- tests/Integration/SDK/ParentBasedTest.php | 5 +- .../SDK/Resource/ResourceInfoFactoryTest.php | 14 +- .../SDK/Resource/ResourceInfoTest.php | 22 +-- tests/Integration/SDK/SpanBuilderTest.php | 44 ++--- .../Integration/SDK/SpanLimitsBuilderTest.php | 55 ++---- tests/Integration/SDK/SpanProcessorTest.php | 5 +- .../SDK/TraceIdRatioBasedSamplerTest.php | 5 +- tests/Integration/SDK/TracerTest.php | 19 +- tests/TestState.php | 44 +++++ tests/Unit/API/Baggage/BaggageTest.php | 5 +- .../Propagation/BaggagePropagatorTest.php | 8 +- .../API/Baggage/Propagation/ParserTest.php | 14 +- .../API/Behavior/Internal/FormatterTest.php | 5 +- .../Internal/LogWriterFactoryTest.php | 18 +- .../API/Behavior/LogsMessagesTraitTest.php | 33 ++-- tests/Unit/API/Common/Time/ClockTest.php | 10 +- .../Unit/API/Common/Time/SystemClockTest.php | 5 +- .../ConfigurationResolverTest.php | 31 +--- .../Instrumentation/InstrumentationTest.php | 17 +- .../InstrumentationTraitTest.php | 5 +- tests/Unit/API/LoggerHolderTest.php | 10 +- tests/Unit/API/Logs/LogRecordTest.php | 10 +- tests/Unit/API/Logs/Map/Psr3Test.php | 10 +- .../Unit/API/Logs/NoopLoggerProviderTest.php | 5 +- tests/Unit/API/Logs/NoopLoggerTest.php | 5 +- tests/Unit/API/Logs/SeverityTest.php | 10 +- tests/Unit/API/Trace/NonRecordingSpanTest.php | 5 +- tests/Unit/API/Trace/NoopSpanBuilderTest.php | 5 +- .../TraceContextPropagatorTest.php | 5 +- .../Propagation/TraceContextValidatorTest.php | 5 +- tests/Unit/API/Trace/SpanContextTest.php | 5 +- .../API/Trace/SpanContextValidatorTest.php | 5 +- tests/Unit/API/Trace/TraceStateTest.php | 3 +- tests/Unit/API/Trace/TraceTest.php | 13 +- .../ConfigurationFactoryTest.php | 7 +- tests/Unit/Context/ContextKeyTest.php | 5 +- tests/Unit/Context/ContextKeysTest.php | 5 +- tests/Unit/Context/ContextStorageTest.php | 11 +- tests/Unit/Context/ContextTest.php | 5 +- tests/Unit/Context/DebugScopeTest.php | 20 +- .../ArrayAccessGetterSetterTest.php | 5 +- .../MultiTextMapPropagatorTest.php | 5 +- .../Propagation/NoopTextMapPropagatorTest.php | 5 +- tests/Unit/Context/ScopeTest.php | 6 +- .../Contrib/Grpc/GrpcTransportFactoryTest.php | 5 +- tests/Unit/Contrib/Grpc/GrpcTransportTest.php | 5 +- .../Contrib/Otlp/AttributesConverterTest.php | 14 +- .../Contrib/Otlp/HttpEndpointResolverTest.php | 26 +-- tests/Unit/Contrib/Otlp/LogsConverterTest.php | 9 +- .../Contrib/Otlp/LogsExporterFactoryTest.php | 19 +- tests/Unit/Contrib/Otlp/LogsExporterTest.php | 5 +- .../Unit/Contrib/Otlp/MetricConverterTest.php | 5 +- .../Otlp/MetricExporterFactoryTest.php | 22 +-- .../Unit/Contrib/Otlp/MetricExporterTest.php | 5 +- .../Otlp/OtlpHttpTransportFactoryTest.php | 5 +- tests/Unit/Contrib/Otlp/OtlpUtilTest.php | 23 +-- .../Contrib/Otlp/ProtobufSerializerTest.php | 5 +- tests/Unit/Contrib/Otlp/SpanConverterTest.php | 18 +- .../Contrib/Otlp/SpanExporterFactoryTest.php | 17 +- tests/Unit/Contrib/Otlp/SpanExporterTest.php | 5 +- .../Contrib/Zipkin/ZipkinExporterTest.php | 5 +- .../Zipkin/ZipkinSpanConverterTest.php | 18 +- .../B3/B3DebugFlagContextKeyTest.php | 5 +- .../Propagator/B3/B3MultiPropagatorTest.php | 26 +-- .../Propagator/B3/B3PropagatorTest.php | 22 +-- .../Propagator/B3/B3SinglePropagatorTest.php | 14 +- .../CloudTrace/CloudTraceFormatterTest.php | 14 +- .../CloudTracePropagatorOneWayTest.php | 5 +- .../CloudTrace/CloudTracePropagatorTest.php | 5 +- .../Propagator/CloudTrace/UtilsTest.php | 26 +-- .../Jaeger/JaegerBaggagePropagatorTest.php | 5 +- .../Jaeger/JaegerDebugFlagContextKeyTest.php | 5 +- .../Jaeger/JaegerPropagatorTest.php | 5 +- .../HttpDiscovery/DependencyResolverTest.php | 10 +- .../HttpPlugClientResolverTest.php | 5 +- .../MessageFactoryResolverTest.php | 10 +- .../HttpDiscovery/PsrClientResolverTest.php | 5 +- .../Attribute/AttributeValidatorTest.php | 18 +- .../SDK/Common/Attribute/AttributesTest.php | 11 +- .../Attribute/FilteredAttributesTest.php | 8 +- .../Configuration/ConfigurationTest.php | 73 ++------ .../Parser/BooleanParserTest.php | 22 +-- .../Configuration/Parser/ListParserTest.php | 13 +- .../Configuration/Parser/MapParserTest.php | 19 +- .../Configuration/Parser/RatioParserTest.php | 18 +- .../Resolver/CompositeResolverTest.php | 8 +- .../Resolver/EnvironmentResolverTest.php | 19 +- .../Resolver/PhpIniResolverTest.php | 8 +- .../SDK/Common/Dev/Compatibility/UtilTest.php | 22 +-- .../Common/Export/Http/PsrTransportTest.php | 8 +- .../SDK/Common/Export/Http/PsrUtilsTest.php | 10 +- .../Stream/StreamTransportFactoryTest.php | 5 +- tests/Unit/SDK/Common/Future/FutureTest.php | 17 +- .../Http/Psr/Client/Discovery/BuzzTest.php | 5 +- .../Psr/Client/Discovery/CurlClientTest.php | 5 +- .../Http/Psr/Client/Discovery/GuzzleTest.php | 5 +- .../Http/Psr/Client/Discovery/SymfonyTest.php | 5 +- .../Common/Http/Psr/Client/DiscoveryTest.php | 11 +- .../Http/Psr/Message/MessageFactoryTest.php | 5 +- .../InstrumentationScopeTest.php | 8 +- .../Common/Util/ClassConstantAccessorTest.php | 5 +- .../SDK/Common/Util/ShutdownHandlerTest.php | 7 +- tests/Unit/SDK/Common/Util/WeakenTest.php | 14 +- tests/Unit/SDK/FactoryRegistryTest.php | 42 ++--- .../Logs/EventLoggerProviderFactoryTest.php | 17 +- .../Unit/SDK/Logs/EventLoggerProviderTest.php | 5 +- tests/Unit/SDK/Logs/EventLoggerTest.php | 11 +- .../Exporter/ConsoleExporterFactoryTest.php | 5 +- .../SDK/Logs/Exporter/ConsoleExporterTest.php | 3 +- .../Exporter/InMemoryExporterFactoryTest.php | 5 +- .../Logs/Exporter/InMemoryExporterTest.php | 3 +- .../SDK/Logs/Exporter/NoopExporterTest.php | 5 +- tests/Unit/SDK/Logs/ExporterFactoryTest.php | 17 +- .../SDK/Logs/LogRecordLimitsBuilderTest.php | 8 +- .../Logs/LogRecordProcessorFactoryTest.php | 17 +- .../SDK/Logs/LoggerProviderBuilderTest.php | 6 +- .../SDK/Logs/LoggerProviderFactoryTest.php | 5 +- tests/Unit/SDK/Logs/LoggerProviderTest.php | 3 +- tests/Unit/SDK/Logs/LoggerSharedStateTest.php | 3 +- tests/Unit/SDK/Logs/LoggerTest.php | 3 +- .../Unit/SDK/Logs/NoopLoggerProviderTest.php | 5 +- .../Processor/BatchLogRecordProcessorTest.php | 18 +- .../Processor/MultiLogRecordProcessorTest.php | 10 +- .../Processor/NoopLogRecordProcessorTest.php | 5 +- .../SimpleLogRecordProcessorTest.php | 3 +- tests/Unit/SDK/Logs/ReadableLogRecordTest.php | 10 +- .../Unit/SDK/Logs/SimplePsrFileLoggerTest.php | 10 +- ...ExplicitBucketHistogramAggregationTest.php | 7 +- .../Aggregation/LastValueAggregationTest.php | 7 +- .../Aggregation/SumAggregationTest.php | 7 +- .../FilteredAttributeProcessorTest.php | 9 +- .../IdentityAttributeProcessorTest.php | 9 +- .../Metrics/Exemplar/BucketStorageTest.php | 5 +- .../Exemplar/FilteredReservoirTest.php | 20 +- .../Exemplar/FixedSizeReservoirTest.php | 5 +- .../Exemplar/HistogramBucketReservoirTest.php | 5 +- .../Metrics/Exemplar/NoopReservoirTest.php | 5 +- tests/Unit/SDK/Metrics/InstrumentTest.php | 33 +--- .../SDK/Metrics/MeterProviderFactoryTest.php | 17 +- tests/Unit/SDK/Metrics/MeterProviderTest.php | 5 +- tests/Unit/SDK/Metrics/MeterTest.php | 6 +- .../ConsoleMetricExporterFactoryTest.php | 5 +- .../InMemoryExporterFactoryTest.php | 5 +- .../MetricExporter/InMemoryExporterTest.php | 5 +- .../NoopMetricExporterFactoryTest.php | 5 +- .../MetricFactory/StreamFactoryTest.php | 11 +- .../MetricReader/ExportingReaderTest.php | 5 +- .../MetricRegistry/MetricRegistryTest.php | 11 +- .../DelayedStalenessHandlerTest.php | 8 +- .../ImmediateStalenessHandlerTest.php | 8 +- .../NoopStalenessHandlerTest.php | 8 +- .../SDK/Metrics/Stream/DeltaStorageTest.php | 16 +- .../SDK/Metrics/Stream/MetricStreamTest.php | 172 +++++++++--------- .../Metrics/View/CriteriaViewRegistryTest.php | 5 +- .../Metrics/View/SelectionCriteriaTest.php | 29 +-- .../SDK/Metrics/View/ViewTemplateTest.php | 5 +- .../SDK/Propagation/PropagatorFactoryTest.php | 21 +-- .../SDK/Resource/Detectors/ComposerTest.php | 13 +- .../SDK/Resource/Detectors/CompositeTest.php | 13 +- .../SDK/Resource/Detectors/ConstantTest.php | 15 +- .../Resource/Detectors/EnvironmentTest.php | 25 +-- .../Unit/SDK/Resource/Detectors/HostTest.php | 16 +- .../Detectors/OperatingSystemTest.php | 11 +- .../Resource/Detectors/ProcessRuntimeTest.php | 11 +- .../SDK/Resource/Detectors/ProcessTest.php | 11 +- .../Resource/Detectors/SdkProvidedTest.php | 9 +- tests/Unit/SDK/Resource/Detectors/SdkTest.php | 11 +- .../SDK/Resource/ResourceInfoFactoryTest.php | 41 ++--- tests/Unit/SDK/Resource/ResourceInfoTest.php | 30 +-- tests/Unit/SDK/SdkAutoloaderTest.php | 19 +- tests/Unit/SDK/SdkBuilderTest.php | 5 +- tests/Unit/SDK/SdkTest.php | 23 +-- .../Behavior/UsesSpanConverterTraitTest.php | 11 +- tests/Unit/SDK/Trace/EventTest.php | 5 +- tests/Unit/SDK/Trace/ExporterFactoryTest.php | 30 ++- tests/Unit/SDK/Trace/ImmutableSpanTest.php | 5 +- tests/Unit/SDK/Trace/LinkTest.php | 5 +- tests/Unit/SDK/Trace/NonRecordingSpanTest.php | 10 +- .../Unit/SDK/Trace/RandomIdGeneratorTest.php | 18 +- .../Trace/Sampler/AlwaysOffSamplerTest.php | 11 +- .../SDK/Trace/Sampler/AlwaysOnSamplerTest.php | 11 +- .../SDK/Trace/Sampler/ParentBasedTest.php | 21 +-- .../Sampler/TraceIdRatioBasedSamplerTest.php | 18 +- tests/Unit/SDK/Trace/SamplerFactoryTest.php | 25 +-- tests/Unit/SDK/Trace/SamplingResultTest.php | 10 +- tests/Unit/SDK/Trace/SpanBuilderTest.php | 5 +- .../SpanExporter/AbstractExporterTestCase.php | 5 +- .../ConsoleSpanExporterFactoryTest.php | 5 +- .../SpanExporter/ConsoleSpanExporterTest.php | 3 +- .../FriendlySpanConverterTest.php | 5 +- .../SpanExporter/InMemoryExporterTest.php | 10 +- .../InMemorySpanExporterFactoryTest.php | 5 +- .../SpanExporter/LoggerDecoratorTest.php | 5 +- .../Trace/SpanExporter/LoggerExporterTest.php | 5 +- .../SpanExporter/NullSpanConverterTest.php | 5 +- .../Unit/SDK/Trace/SpanLimitsBuilderTest.php | 22 +-- .../BatchSpanProcessorBuilderTest.php | 6 +- .../SpanProcessor/BatchSpanProcessorTest.php | 21 +-- .../SpanProcessor/MultiSpanProcessorTest.php | 13 +- .../SpanProcessor/NoopSpanProcessorTest.php | 14 +- .../SpanProcessor/SimpleSpanProcessorTest.php | 10 +- .../SDK/Trace/SpanProcessorFactoryTest.php | 17 +- tests/Unit/SDK/Trace/SpanTest.php | 92 +++------- tests/Unit/SDK/Trace/StatusDataTest.php | 13 +- .../SDK/Trace/TracerProviderFactoryTest.php | 15 +- tests/Unit/SDK/Trace/TracerProviderTest.php | 38 +--- .../Unit/SDK/Trace/TracerSharedStateTest.php | 7 +- tests/Unit/SDK/Trace/TracerTest.php | 11 +- tests/Unit/SDK/Util/SpanData.php | 3 +- 219 files changed, 1043 insertions(+), 1752 deletions(-) create mode 100644 tests/TestState.php diff --git a/Makefile b/Makefile index df42c09a9..8538ca84d 100644 --- a/Makefile +++ b/Makefile @@ -95,9 +95,9 @@ bash: ## bash shell into container style: ## Run style check/fix $(DC_RUN_PHP) env XDEBUG_MODE=off env PHP_CS_FIXER_IGNORE_ENV=1 vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --using-cache=no -vvv rector-write: ## Run rector - $(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/rector/vendor/bin/rector process src + $(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/rector/vendor/bin/rector process rector: ## Run rector (dry-run) - $(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/rector/vendor/bin/rector process src --dry-run + $(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/rector/vendor/bin/rector process --dry-run deptrac: ## Run deptrac $(DC_RUN_PHP) env XDEBUG_MODE=off vendor-bin/deptrac/vendor/bin/deptrac --formatter=table --report-uncovered --no-cache w3c-test-service: diff --git a/composer.json b/composer.json index 6f53c3354..3c3d450bd 100644 --- a/composer.json +++ b/composer.json @@ -83,7 +83,6 @@ "require-dev": { "ext-grpc": "*", "grpc/grpc": "^1.30", - "assertwell/phpunit-global-state": "^0.2.2", "bamarni/composer-bin-plugin": "^1.8", "dg/bypass-finals": "^1.4", "guzzlehttp/guzzle": "^7.4", @@ -100,7 +99,7 @@ "phpstan/phpstan": "^1.10.13", "phpstan/phpstan-mockery": "^1.1", "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^10", + "phpunit/phpunit": "^10 || ^11", "symfony/http-client": "^5.2", "symfony/var-exporter": "^5.4 || ^6.4 || ^7.0", "symfony/yaml": "^5.4 || ^6.4 || ^7.0" diff --git a/rector.php b/rector.php index bb15476cb..6526f4542 100644 --- a/rector.php +++ b/rector.php @@ -38,6 +38,7 @@ ], ReadOnlyPropertyRector::class => [ __DIR__ . '/src/SDK/Metrics/Stream/SynchronousMetricStream.php', + __DIR__ . '/tests/Unit/Extension/Propagator', ], DisallowedEmptyRuleFixerRector::class, ExplicitBoolCompareRector::class, diff --git a/tests/Benchmark/OtlpBench.php b/tests/Benchmark/OtlpBench.php index 1f4c31809..59ecfa498 100644 --- a/tests/Benchmark/OtlpBench.php +++ b/tests/Benchmark/OtlpBench.php @@ -26,8 +26,8 @@ class OtlpBench { private TracerInterface $tracer; - private SamplerInterface $sampler; - private ResourceInfo $resource; + private readonly SamplerInterface $sampler; + private readonly ResourceInfo $resource; private const PROTOBUF = 'application/x-protobuf'; private const JSON = 'application/json'; @@ -57,7 +57,7 @@ public function setUpNoExporter(): void private function createTransport(string $contentType): TransportInterface { return new class($contentType) implements TransportInterface { - private string $contentType; + private readonly string $contentType; public function __construct(string $contentType) { diff --git a/tests/Integration/Config/ConfigurationTest.php b/tests/Integration/Config/ConfigurationTest.php index c5391ed24..ae204f50b 100644 --- a/tests/Integration/Config/ConfigurationTest.php +++ b/tests/Integration/Config/ConfigurationTest.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace Config; +namespace OpenTelemetry\Tests\Integration\Config; use OpenTelemetry\Config\SDK\Configuration; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; +#[CoversNothing] final class ConfigurationTest extends TestCase { - /** - * @dataProvider openTelemetryConfigurationDataProvider - * @coversNothing - */ + #[DataProvider('openTelemetryConfigurationDataProvider')] public function test_open_telemetry_configuration(string $file): void { $this->expectNotToPerformAssertions(); diff --git a/tests/Integration/SDK/AlwaysOffSamplerTest.php b/tests/Integration/SDK/AlwaysOffSamplerTest.php index 42bc2316c..765a12650 100644 --- a/tests/Integration/SDK/AlwaysOffSamplerTest.php +++ b/tests/Integration/SDK/AlwaysOffSamplerTest.php @@ -12,11 +12,10 @@ use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Trace\Sampler\AlwaysOffSampler; use OpenTelemetry\SDK\Trace\SamplingResult; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] class AlwaysOffSamplerTest extends TestCase { public function test_always_off_sampler(): void diff --git a/tests/Integration/SDK/AlwaysOnSamplerTest.php b/tests/Integration/SDK/AlwaysOnSamplerTest.php index 3fea3741f..ea19c3ba7 100644 --- a/tests/Integration/SDK/AlwaysOnSamplerTest.php +++ b/tests/Integration/SDK/AlwaysOnSamplerTest.php @@ -12,11 +12,10 @@ use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Trace\Sampler\AlwaysOnSampler; use OpenTelemetry\SDK\Trace\SamplingResult; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] class AlwaysOnSamplerTest extends TestCase { public function test_always_on_sampler_decision(): void diff --git a/tests/Integration/SDK/Context/SpanContextTest.php b/tests/Integration/SDK/Context/SpanContextTest.php index 85493d47a..b7820eb00 100644 --- a/tests/Integration/SDK/Context/SpanContextTest.php +++ b/tests/Integration/SDK/Context/SpanContextTest.php @@ -9,16 +9,15 @@ use OpenTelemetry\API\Trace\SpanContextValidator; use OpenTelemetry\API\Trace\TraceState; use OpenTelemetry\SDK\Trace\RandomIdGenerator; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] class SpanContextTest extends TestCase { - /** - * @dataProvider invalidSpanData - */ + #[DataProvider('invalidSpanData')] public function test_invalid_span(string $traceId, string $spanId): void { $spanContext = SpanContext::create($traceId, $spanId); @@ -40,18 +39,14 @@ public static function invalidSpanData(): array ]; } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_valid_span(): void { $spanContext = SpanContext::create('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbb', API\TraceFlags::SAMPLED); $this->assertTrue($spanContext->isValid()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_context_is_remote_from_restore(): void { $spanContext = SpanContext::createFromRemoteParent('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbb', API\TraceFlags::SAMPLED); diff --git a/tests/Integration/SDK/MeterProviderTest.php b/tests/Integration/SDK/MeterProviderTest.php index 9e573da43..578cf5d7d 100644 --- a/tests/Integration/SDK/MeterProviderTest.php +++ b/tests/Integration/SDK/MeterProviderTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Integration\SDK; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Common\Time\ClockInterface; use OpenTelemetry\API\Common\Time\TestClock; use OpenTelemetry\API\Metrics as API; @@ -28,19 +27,14 @@ use OpenTelemetry\SDK\Metrics\StalenessHandler\ImmediateStalenessHandlerFactory; use OpenTelemetry\SDK\Metrics\View\CriteriaViewRegistry; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] final class MeterProviderTest extends TestCase { - use EnvironmentVariables; - - public function tearDown(): void - { - self::restoreEnvironmentVariables(); - } + use TestState; public function test_weak_asynchronous_observer_is_released_when_instance_out_of_scope(): void { diff --git a/tests/Integration/SDK/MeterTest.php b/tests/Integration/SDK/MeterTest.php index 6c57d6f72..36fd6f1b2 100644 --- a/tests/Integration/SDK/MeterTest.php +++ b/tests/Integration/SDK/MeterTest.php @@ -9,17 +9,18 @@ use OpenTelemetry\API\Metrics\Noop\NoopObservableCounter; use OpenTelemetry\API\Metrics\ObserverInterface; use OpenTelemetry\SDK\Metrics\Data\Sum; +use OpenTelemetry\SDK\Metrics\Meter; use OpenTelemetry\SDK\Metrics\MeterProviderBuilder; use OpenTelemetry\SDK\Metrics\MetricExporter\InMemoryExporter; use OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; use Psr\Log\LogLevel; +#[CoversClass(Meter::class)] final class MeterTest extends TestCase { - /** - * @covers \OpenTelemetry\SDK\Metrics\Meter::batchObserve - */ public function test_batch_observe_observes_all_provided_instruments(): void { $exporter = new InMemoryExporter(); @@ -49,9 +50,6 @@ static function (ObserverInterface $a, ObserverInterface $b): void { } } - /** - * @covers \OpenTelemetry\SDK\Metrics\Meter::batchObserve - */ public function test_batch_observe_calls_callback_only_once(): void { $reader = new ExportingReader(new InMemoryExporter()); @@ -78,9 +76,6 @@ static function () use (&$c): void { } } - /** - * @covers \OpenTelemetry\SDK\Metrics\Meter::batchObserve - */ public function test_batch_observe_detach_detaches_callback(): void { $exporter = new InMemoryExporter(); @@ -111,9 +106,6 @@ static function (ObserverInterface $a, ObserverInterface $b): void { } } - /** - * @covers \OpenTelemetry\SDK\Metrics\Meter::batchObserve - */ public function test_batch_observe_weakens_callback(): void { $exporter = new InMemoryExporter(); @@ -153,9 +145,6 @@ public function __invoke(ObserverInterface $a, ObserverInterface $b): void } } - /** - * @covers \OpenTelemetry\SDK\Metrics\Meter::batchObserve - */ public function test_batch_observe_invalid_instrument(): void { $logWriter = $this->createMock(LogWriterInterface::class); @@ -192,9 +181,6 @@ static function (ObserverInterface $a, ObserverInterface $b): void { } } - /** - * @covers \OpenTelemetry\SDK\Metrics\Meter::batchObserve - */ public function test_batch_observe_invalid_instrument_different_meter(): void { $logWriter = $this->createMock(LogWriterInterface::class); @@ -231,9 +217,7 @@ static function (ObserverInterface $a, ObserverInterface $b): void { } } - /** - * @coversNothing - */ + #[CoversNothing] public function test_batch_observe_detach_with_repeated_instrument_does_not_trigger_undefined_offset_warning(): void { $this->expectNotToPerformAssertions(); diff --git a/tests/Integration/SDK/ParentBasedTest.php b/tests/Integration/SDK/ParentBasedTest.php index 1ea40138d..8ac25eec2 100644 --- a/tests/Integration/SDK/ParentBasedTest.php +++ b/tests/Integration/SDK/ParentBasedTest.php @@ -10,11 +10,10 @@ use OpenTelemetry\SDK\Trace\Sampler\ParentBased; use OpenTelemetry\SDK\Trace\SamplerInterface; use OpenTelemetry\SDK\Trace\SamplingResult; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] class ParentBasedTest extends TestCase { public function test_parent_based_root_span(): void diff --git a/tests/Integration/SDK/Resource/ResourceInfoFactoryTest.php b/tests/Integration/SDK/Resource/ResourceInfoFactoryTest.php index 180bdaae5..6c5fdede8 100644 --- a/tests/Integration/SDK/Resource/ResourceInfoFactoryTest.php +++ b/tests/Integration/SDK/Resource/ResourceInfoFactoryTest.php @@ -4,23 +4,17 @@ namespace OpenTelemetry\Tests\Integration\SDK\Resource; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use Composer\InstalledVersions; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; use OpenTelemetry\SemConv\ResourceAttributes; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] class ResourceInfoFactoryTest extends TestCase { - use EnvironmentVariables; - - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } + use TestState; public function test_all_default_resources(): void { diff --git a/tests/Integration/SDK/Resource/ResourceInfoTest.php b/tests/Integration/SDK/Resource/ResourceInfoTest.php index 62da45b38..6a179c4f8 100644 --- a/tests/Integration/SDK/Resource/ResourceInfoTest.php +++ b/tests/Integration/SDK/Resource/ResourceInfoTest.php @@ -4,28 +4,22 @@ namespace OpenTelemetry\Tests\Integration\SDK\Resource; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Resource\Detectors; use OpenTelemetry\SDK\Resource\ResourceInfo; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] class ResourceInfoTest extends TestCase { - use EnvironmentVariables; + use TestState; - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - - /** - * @dataProvider environmentResourceProvider - * @group compliance - */ + #[DataProvider('environmentResourceProvider')] + #[Group('compliance')] public function test_resource_from_environment(string $envAttributes, array $userAttributes, array $expected): void { $this->setEnvironmentVariable('OTEL_RESOURCE_ATTRIBUTES', $envAttributes); diff --git a/tests/Integration/SDK/SpanBuilderTest.php b/tests/Integration/SDK/SpanBuilderTest.php index c8eaa0369..702c21423 100644 --- a/tests/Integration/SDK/SpanBuilderTest.php +++ b/tests/Integration/SDK/SpanBuilderTest.php @@ -22,12 +22,12 @@ use OpenTelemetry\SDK\Trace\SpanLimitsBuilder; use OpenTelemetry\SDK\Trace\SpanProcessorInterface; use OpenTelemetry\SDK\Trace\TracerProvider; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\Group; use function range; use function str_repeat; -/** - * @coversNothing - */ +#[CoversNothing] class SpanBuilderTest extends MockeryTestCase { private const SPAN_NAME = 'span_name'; @@ -52,9 +52,7 @@ protected function setUp(): void ); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_add_link(): void { /** @var Span $span */ @@ -68,9 +66,7 @@ public function test_add_link(): void $this->assertCount(2, $span->toSpanData()->getLinks()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_add_link_after_span_creation(): void { /** @var Span $span */ @@ -183,9 +179,7 @@ public function test_add_link_truncate_link_attribute_value(): void ); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_add_link_no_effect_after_start_span(): void { $spanBuilder = $this->tracer->spanBuilder(self::SPAN_NAME); @@ -209,9 +203,7 @@ public function test_add_link_no_effect_after_start_span(): void $this->assertCount(1, $span->toSpanData()->getLinks()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_set_attribute(): void { /** @var Span $span */ @@ -235,9 +227,7 @@ public function test_set_attribute(): void $this->assertNull($attributes->get('nil')); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_set_attribute_no_effect_after_end(): void { /** @var Span $span */ @@ -261,9 +251,6 @@ public function test_set_attribute_no_effect_after_end(): void $this->assertFalse($attributes->has('doo')); } - /** - * @group trace-compliance - */ // public function test_set_attribute_empty_string_value_is_set(): void // { // /** @var Span $span */ @@ -273,18 +260,13 @@ public function test_set_attribute_no_effect_after_end(): void // ->setAttribute('nil', null) // ->setAttribute('empty-string', '') // ->startSpan(); - // $attributes = $span->toSpanData()->getAttributes(); // $this->assertSame(1, $attributes->count()); // $this->assertSame('', $attributes->get('empty-string')); // $this->assertNull($attributes->get('nil')); - // $span->end(); // } - - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_set_attribute_only_null_string_value_should_not_be_set(): void { /** @var Span $span */ @@ -299,9 +281,7 @@ public function test_set_attribute_only_null_string_value_should_not_be_set(): v $this->assertNull($attributes->get('nil')); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_set_attribute_no_effect_after_start_span(): void { $spanBuilder = $this->tracer->spanBuilder(self::SPAN_NAME); @@ -395,9 +375,7 @@ public function test_set_attributes(): void $this->assertSame(1, $attributes->get('id')); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_set_attributes_merges_attributes_correctly(): void { $attributes = ['id' => 2, 'foo' => 'bar', 'key' => 'val']; diff --git a/tests/Integration/SDK/SpanLimitsBuilderTest.php b/tests/Integration/SDK/SpanLimitsBuilderTest.php index 418349eee..eb0e82855 100644 --- a/tests/Integration/SDK/SpanLimitsBuilderTest.php +++ b/tests/Integration/SDK/SpanLimitsBuilderTest.php @@ -4,26 +4,19 @@ namespace OpenTelemetry\Tests\Integration\SDK; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Trace\SpanLimitsBuilder; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] class SpanLimitsBuilderTest extends TestCase { - use EnvironmentVariables; + use TestState; - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_length_limits_builder_uses_environment_variable(): void { $this->setEnvironmentVariable('OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT', 9); @@ -33,9 +26,7 @@ public function test_span_length_limits_builder_uses_environment_variable(): voi $this->assertEquals(Attributes::factory(128, 9), $spanLimits->getAttributesFactory()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_length_limits_builder_uses_configured_value(): void { $this->setEnvironmentVariable('OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT', 9); @@ -46,9 +37,7 @@ public function test_span_length_limits_builder_uses_configured_value(): void $this->assertEquals(Attributes::factory(128, 201), $spanLimits->getAttributesFactory()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_event_limits_builder_uses_environment_variable(): void { $this->setEnvironmentVariable('OTEL_SPAN_EVENT_COUNT_LIMIT', 200); @@ -57,9 +46,7 @@ public function test_span_event_limits_builder_uses_environment_variable(): void $this->assertEquals(200, $spanLimits->getEventCountLimit()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_event_limits_builder_uses_configured_value(): void { $this->setEnvironmentVariable('OTEL_SPAN_EVENT_COUNT_LIMIT', 200); @@ -69,9 +56,7 @@ public function test_span_event_limits_builder_uses_configured_value(): void $this->assertEquals(185, $spanLimits->getEventCountLimit()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_limits_link_builder_uses_environment_variable(): void { $this->setEnvironmentVariable('OTEL_SPAN_LINK_COUNT_LIMIT', 1101); @@ -80,9 +65,7 @@ public function test_span_limits_link_builder_uses_environment_variable(): void $this->assertEquals(1101, $spanLimits->getLinkCountLimit()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_limits_link_builder_uses_configured_value(): void { $this->setEnvironmentVariable('OTEL_SPAN_LINK_COUNT_LIMIT', 1102); @@ -92,9 +75,7 @@ public function test_span_limits_link_builder_uses_configured_value(): void $this->assertEquals(193, $spanLimits->getLinkCountLimit()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_attribute_per_event_count_limits_builder_uses_environment_variable(): void { $this->setEnvironmentVariable('OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT', 400); @@ -103,9 +84,7 @@ public function test_span_attribute_per_event_count_limits_builder_uses_environm $this->assertEquals(Attributes::factory(400), $spanLimits->getEventAttributesFactory()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_event_attribute_per_event_count_limits_builder_uses_configured_value(): void { $this->setEnvironmentVariable('OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT', 400); @@ -115,9 +94,7 @@ public function test_span_event_attribute_per_event_count_limits_builder_uses_co $this->assertEquals(Attributes::factory(155), $spanLimits->getEventAttributesFactory()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_attribute_per_link_count_limits_builder_uses_environment_variable(): void { $this->setEnvironmentVariable('OTEL_LINK_ATTRIBUTE_COUNT_LIMIT', 500); @@ -126,9 +103,7 @@ public function test_span_attribute_per_link_count_limits_builder_uses_environme $this->assertEquals(Attributes::factory(500), $spanLimits->getLinkAttributesFactory()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_link_attribute_per_event_count_limits_builder_uses_configured_value(): void { $this->setEnvironmentVariable('OTEL_LINK_ATTRIBUTE_COUNT_LIMIT', 500); diff --git a/tests/Integration/SDK/SpanProcessorTest.php b/tests/Integration/SDK/SpanProcessorTest.php index ae272f618..0d4112081 100644 --- a/tests/Integration/SDK/SpanProcessorTest.php +++ b/tests/Integration/SDK/SpanProcessorTest.php @@ -8,11 +8,10 @@ use OpenTelemetry\Context\Context; use OpenTelemetry\SDK\Trace\SpanProcessorInterface; use OpenTelemetry\SDK\Trace\TracerProvider; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] class SpanProcessorTest extends TestCase { public function test_parent_context_should_be_passed_to_span_processor(): void diff --git a/tests/Integration/SDK/TraceIdRatioBasedSamplerTest.php b/tests/Integration/SDK/TraceIdRatioBasedSamplerTest.php index 3487fa39d..0f1bc58e4 100644 --- a/tests/Integration/SDK/TraceIdRatioBasedSamplerTest.php +++ b/tests/Integration/SDK/TraceIdRatioBasedSamplerTest.php @@ -12,11 +12,10 @@ use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Trace\Sampler\TraceIdRatioBasedSampler; use OpenTelemetry\SDK\Trace\SamplingResult; +use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] class TraceIdRatioBasedSamplerTest extends TestCase { public function test_never_trace_id_ratio_based_sampler_decision(): void diff --git a/tests/Integration/SDK/TracerTest.php b/tests/Integration/SDK/TracerTest.php index e0596e13c..44f2b8fa6 100644 --- a/tests/Integration/SDK/TracerTest.php +++ b/tests/Integration/SDK/TracerTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Integration\SDK; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Trace as API; use OpenTelemetry\API\Trace\NonRecordingSpan; use OpenTelemetry\API\Trace\SpanContext; @@ -24,19 +23,15 @@ use OpenTelemetry\SDK\Trace\TracerProvider; use OpenTelemetry\SDK\Trace\TracerProviderFactory; use OpenTelemetry\SemConv\TraceAttributes; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversNothing; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @coversNothing - */ +#[CoversNothing] class TracerTest extends TestCase { - use EnvironmentVariables; - - public function tearDown(): void - { - self::restoreEnvironmentVariables(); - } + use TestState; public function test_noop_span_should_be_started_when_sampling_result_is_drop(): void { @@ -84,9 +79,7 @@ public function test_sampler_may_override_parents_trace_state(): void $this->assertEquals($newTraceState, $span->getContext()->getTraceState()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_should_receive_instrumentation_scope(): void { $tracerProvider = new TracerProvider(); diff --git a/tests/TestState.php b/tests/TestState.php new file mode 100644 index 000000000..75a2f75a9 --- /dev/null +++ b/tests/TestState.php @@ -0,0 +1,44 @@ +environmentVariables as $variable => $value) { + putenv(false === $value ? $variable : "{$variable}={$value}"); + } + } + + protected function setEnvironmentVariable(string $variable, mixed $value): void + { + if (! isset($this->environmentVariables[$variable])) { + $this->environmentVariables[$variable] = getenv($variable); + } + + putenv(null === $value ? $variable : "{$variable}={$value}"); + } +} diff --git a/tests/Unit/API/Baggage/BaggageTest.php b/tests/Unit/API/Baggage/BaggageTest.php index a22fa0f71..c4de0254d 100644 --- a/tests/Unit/API/Baggage/BaggageTest.php +++ b/tests/Unit/API/Baggage/BaggageTest.php @@ -8,11 +8,10 @@ use OpenTelemetry\API\Baggage\Entry; use OpenTelemetry\API\Baggage\Metadata; use OpenTelemetry\Context\Context; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Baggage\Baggage - */ +#[CoversClass(Baggage::class)] class BaggageTest extends TestCase { // region contextInteraction diff --git a/tests/Unit/API/Baggage/Propagation/BaggagePropagatorTest.php b/tests/Unit/API/Baggage/Propagation/BaggagePropagatorTest.php index 33f4c7458..5db59dffb 100644 --- a/tests/Unit/API/Baggage/Propagation/BaggagePropagatorTest.php +++ b/tests/Unit/API/Baggage/Propagation/BaggagePropagatorTest.php @@ -8,11 +8,11 @@ use OpenTelemetry\API\Baggage\Metadata; use OpenTelemetry\API\Baggage\Propagation\BaggagePropagator; use OpenTelemetry\Context\Context; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Baggage\Propagation\BaggagePropagator - */ +#[CoversClass(BaggagePropagator::class)] class BaggagePropagatorTest extends TestCase { public function test_fields(): void @@ -84,7 +84,7 @@ public function test_extract_missing_header(): void ); } - /** @dataProvider headerProvider */ + #[DataProvider('headerProvider')] public function test_extract(string $header, Baggage $expectedBaggage): void { $propagator = BaggagePropagator::getInstance(); diff --git a/tests/Unit/API/Baggage/Propagation/ParserTest.php b/tests/Unit/API/Baggage/Propagation/ParserTest.php index 956aa173a..ef8b0e346 100644 --- a/tests/Unit/API/Baggage/Propagation/ParserTest.php +++ b/tests/Unit/API/Baggage/Propagation/ParserTest.php @@ -7,12 +7,12 @@ use OpenTelemetry\API\Baggage\BaggageBuilder; use OpenTelemetry\API\Baggage\BaggageBuilderInterface; use OpenTelemetry\API\Baggage\Propagation\Parser; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Baggage\Propagation\Parser - */ +#[CoversClass(Parser::class)] class ParserTest extends TestCase { /** @var BaggageBuilderInterface&MockObject */ @@ -30,9 +30,7 @@ public function test_parse_into_splits_by_comma(): void $parser->parseInto($this->builder); } - /** - * @dataProvider headerProvider - */ + #[DataProvider('headerProvider')] public function test_parse_into(string $header): void { $parser = new Parser($header); @@ -77,9 +75,7 @@ public function test_parse_into_with_properties(): void } } - /** - * @dataProvider invalidHeaderProvider - */ + #[DataProvider('invalidHeaderProvider')] public function test_parse_into_with_invalid_header(string $header): void { $parser = new Parser($header); diff --git a/tests/Unit/API/Behavior/Internal/FormatterTest.php b/tests/Unit/API/Behavior/Internal/FormatterTest.php index 18086631a..3cdcd381b 100644 --- a/tests/Unit/API/Behavior/Internal/FormatterTest.php +++ b/tests/Unit/API/Behavior/Internal/FormatterTest.php @@ -5,11 +5,10 @@ namespace OpenTelemetry\Tests\Unit\API\Behavior\Internal; use OpenTelemetry\API\Behavior\Internal\LogWriter\Formatter; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Behavior\Internal\LogWriter\Formatter - */ +#[CoversClass(Formatter::class)] class FormatterTest extends TestCase { public function test_no_exception_contains_code_location(): void diff --git a/tests/Unit/API/Behavior/Internal/LogWriterFactoryTest.php b/tests/Unit/API/Behavior/Internal/LogWriterFactoryTest.php index 16f6204df..1d781d390 100644 --- a/tests/Unit/API/Behavior/Internal/LogWriterFactoryTest.php +++ b/tests/Unit/API/Behavior/Internal/LogWriterFactoryTest.php @@ -4,38 +4,32 @@ namespace OpenTelemetry\Tests\Unit\API\Behavior\Internal; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; 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\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; -/** - * @covers \OpenTelemetry\API\Behavior\Internal\LogWriterFactory - */ +#[CoversClass(LogWriterFactory::class)] class LogWriterFactoryTest extends TestCase { - use EnvironmentVariables; + use TestState; public function setUp(): void { LoggerHolder::unset(); } - public function tearDown(): void - { - self::restoreEnvironmentVariables(); - LoggerHolder::unset(); - } - /** - * @dataProvider logDestinationProvider * @psalm-suppress ArgumentTypeCoercion */ + #[DataProvider('logDestinationProvider')] public function test_log_destination_from_env(string $value, string $expected): void { $this->setEnvironmentVariable('OTEL_PHP_LOG_DESTINATION', $value); diff --git a/tests/Unit/API/Behavior/LogsMessagesTraitTest.php b/tests/Unit/API/Behavior/LogsMessagesTraitTest.php index 08e93f59c..3a7479629 100644 --- a/tests/Unit/API/Behavior/LogsMessagesTraitTest.php +++ b/tests/Unit/API/Behavior/LogsMessagesTraitTest.php @@ -4,20 +4,21 @@ namespace OpenTelemetry\Tests\Unit\API\Behavior; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Behavior\Internal\Logging; use OpenTelemetry\API\Behavior\Internal\LogWriter\LogWriterInterface; use OpenTelemetry\API\Behavior\LogsMessagesTrait; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\TestDox; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Log\LogLevel; -/** - * @covers \OpenTelemetry\API\Behavior\LogsMessagesTrait - */ +#[CoversClass(LogsMessagesTrait::class)] class LogsMessagesTraitTest extends TestCase { - use EnvironmentVariables; + use TestState; protected MockObject $writer; @@ -28,15 +29,7 @@ public function setUp(): void Logging::setLogWriter($this->writer); } - public function tearDown(): void - { - Logging::reset(); - $this->restoreEnvironmentVariables(); - } - - /** - * @dataProvider logProvider - */ + #[DataProvider('logProvider')] public function test_log(string $method, string $expectedLevel): void { $instance = $this->createInstance(); @@ -58,10 +51,8 @@ public static function logProvider(): array ]; } - /** - * @testdox Proxies logging methods through to logger - * @dataProvider logLevelProvider - */ + #[DataProvider('logLevelProvider')] + #[TestDox('Proxies logging methods through to logger')] public function test_log_methods(string $method, string $expectedLogLevel): void { $instance = $this->createInstance(); @@ -83,14 +74,12 @@ public static function logLevelProvider(): array ]; } - /** - * @dataProvider otelLogLevelProvider - */ + #[DataProvider('otelLogLevelProvider')] public function test_logging_respects_configured_otel_log_level(string $otelLogLevel, string $method, bool $expected): void { $this->setEnvironmentVariable('OTEL_LOG_LEVEL', $otelLogLevel); $instance = $this->createInstance(); - if ($expected === true) { + if ($expected) { $this->writer->expects($this->once())->method('write'); } else { $this->writer->expects($this->never())->method('write'); diff --git a/tests/Unit/API/Common/Time/ClockTest.php b/tests/Unit/API/Common/Time/ClockTest.php index 1eb622119..51799799c 100644 --- a/tests/Unit/API/Common/Time/ClockTest.php +++ b/tests/Unit/API/Common/Time/ClockTest.php @@ -7,11 +7,10 @@ use OpenTelemetry\API\Common\Time\Clock; use OpenTelemetry\API\Common\Time\ClockInterface; use OpenTelemetry\API\Common\Time\SystemClock; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Common\Time\Clock - */ +#[CoversClass(Clock::class)] class ClockTest extends TestCase { public function setUp(): void @@ -19,11 +18,6 @@ public function setUp(): void Clock::reset(); } - public function tearDown(): void - { - Clock::reset(); - } - public function test_default_is_system_clock(): void { $this->assertInstanceOf(SystemClock::class, Clock::getDefault()); diff --git a/tests/Unit/API/Common/Time/SystemClockTest.php b/tests/Unit/API/Common/Time/SystemClockTest.php index 652a63203..a3b22b3e7 100644 --- a/tests/Unit/API/Common/Time/SystemClockTest.php +++ b/tests/Unit/API/Common/Time/SystemClockTest.php @@ -6,11 +6,10 @@ use DateTime; use OpenTelemetry\API\Common\Time\SystemClock; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Common\Time\SystemClock - */ +#[CoversClass(SystemClock::class)] class SystemClockTest extends TestCase { private const NANOS_PER_SECOND = 1_000_000_000; diff --git a/tests/Unit/API/Instrumentation/ConfigurationResolverTest.php b/tests/Unit/API/Instrumentation/ConfigurationResolverTest.php index 4b7a24c9c..81aafbf9b 100644 --- a/tests/Unit/API/Instrumentation/ConfigurationResolverTest.php +++ b/tests/Unit/API/Instrumentation/ConfigurationResolverTest.php @@ -4,16 +4,16 @@ namespace OpenTelemetry\Tests\Unit\API\Instrumentation; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Instrumentation\ConfigurationResolver; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Instrumentation\ConfigurationResolver - */ +#[CoversClass(ConfigurationResolver::class)] class ConfigurationResolverTest extends TestCase { - use EnvironmentVariables; + use TestState; private ConfigurationResolver $resolver; @@ -22,14 +22,7 @@ public function setUp(): void $this->resolver = new ConfigurationResolver(); } - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - - /** - * @dataProvider hasProvider - */ + #[DataProvider('hasProvider')] public function test_has(?string $value, bool $expected): void { $this->assertFalse($this->resolver->has('OTEL_FOO')); @@ -53,9 +46,7 @@ public function test_get_string(): void $this->assertSame('bar', $this->resolver->getString('OTEL_FOO')); } - /** - * @dataProvider booleanProvider - */ + #[DataProvider('booleanProvider')] public function test_get_boolean(?string $value, ?bool $expected): void { $this->assertFalse($this->resolver->has('OTEL_FOO')); @@ -74,9 +65,7 @@ public static function booleanProvider(): array ]; } - /** - * @dataProvider intProvider - */ + #[DataProvider('intProvider')] public function test_get_int(?string $value, ?int $expected): void { $this->assertFalse($this->resolver->has('OTEL_FOO')); @@ -96,9 +85,7 @@ public static function intProvider(): array ]; } - /** - * @dataProvider listProvider - */ + #[DataProvider('listProvider')] public function test_get_list(?string $value, array $expected): void { $this->assertFalse($this->resolver->has('OTEL_FOO')); diff --git a/tests/Unit/API/Instrumentation/InstrumentationTest.php b/tests/Unit/API/Instrumentation/InstrumentationTest.php index d0521d73e..f3f85ea1e 100644 --- a/tests/Unit/API/Instrumentation/InstrumentationTest.php +++ b/tests/Unit/API/Instrumentation/InstrumentationTest.php @@ -7,6 +7,7 @@ use OpenTelemetry\API\Globals; use OpenTelemetry\API\Instrumentation\CachedInstrumentation; use OpenTelemetry\API\Instrumentation\Configurator; +use OpenTelemetry\API\Instrumentation\ContextKeys; use OpenTelemetry\API\Logs\EventLoggerInterface; use OpenTelemetry\API\Logs\EventLoggerProviderInterface; use OpenTelemetry\API\Logs\LoggerInterface; @@ -23,14 +24,13 @@ use OpenTelemetry\API\Trace\TracerProviderInterface; use OpenTelemetry\Context\Propagation\NoopTextMapPropagator; use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Globals - * @covers \OpenTelemetry\API\Instrumentation\CachedInstrumentation - * @covers \OpenTelemetry\API\Instrumentation\Configurator - * @covers \OpenTelemetry\API\Instrumentation\ContextKeys - */ +#[CoversClass(Globals::class)] +#[CoversClass(CachedInstrumentation::class)] +#[CoversClass(Configurator::class)] +#[CoversClass(ContextKeys::class)] final class InstrumentationTest extends TestCase { public function setUp(): void @@ -38,11 +38,6 @@ public function setUp(): void Globals::reset(); } - public function tearDown(): void - { - Globals::reset(); - } - public function test_globals_not_configured_returns_noop_instances(): void { $this->assertInstanceOf(NoopTracerProvider::class, Globals::tracerProvider()); diff --git a/tests/Unit/API/Instrumentation/InstrumentationTraitTest.php b/tests/Unit/API/Instrumentation/InstrumentationTraitTest.php index 67a0e8330..11812e30a 100644 --- a/tests/Unit/API/Instrumentation/InstrumentationTraitTest.php +++ b/tests/Unit/API/Instrumentation/InstrumentationTraitTest.php @@ -14,14 +14,13 @@ use OpenTelemetry\API\Trace\TracerProviderInterface; use OpenTelemetry\Context\Propagation\NoopTextMapPropagator; use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use RuntimeException; -/** - * @covers \OpenTelemetry\API\Instrumentation\InstrumentationTrait - */ +#[CoversClass(InstrumentationTrait::class)] class InstrumentationTraitTest extends TestCase { public const INSTRUMENTATION_NAME = 'test-instrumentation'; diff --git a/tests/Unit/API/LoggerHolderTest.php b/tests/Unit/API/LoggerHolderTest.php index f5beb20e7..7b6387bf1 100644 --- a/tests/Unit/API/LoggerHolderTest.php +++ b/tests/Unit/API/LoggerHolderTest.php @@ -5,20 +5,14 @@ namespace OpenTelemetry\Tests\Unit\API; use OpenTelemetry\API\LoggerHolder; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -/** - * @covers \OpenTelemetry\API\LoggerHolder - */ +#[CoversClass(LoggerHolder::class)] class LoggerHolderTest extends TestCase { - public function tearDown(): void - { - LoggerHolder::unset(); - } - public function setUp(): void { LoggerHolder::unset(); diff --git a/tests/Unit/API/Logs/LogRecordTest.php b/tests/Unit/API/Logs/LogRecordTest.php index 525cbbda5..ae6faed6e 100644 --- a/tests/Unit/API/Logs/LogRecordTest.php +++ b/tests/Unit/API/Logs/LogRecordTest.php @@ -7,16 +7,14 @@ use OpenTelemetry\API\Logs\LogRecord; use OpenTelemetry\API\Logs\Severity; use OpenTelemetry\Context\Context; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Logs\LogRecord - */ +#[CoversClass(LogRecord::class)] class LogRecordTest extends TestCase { - /** - * @dataProvider settersProvider - */ + #[DataProvider('settersProvider')] public function test_setters(string $method, string $propertyName, mixed $value, mixed $expected = null): void { $record = new LogRecord(); diff --git a/tests/Unit/API/Logs/Map/Psr3Test.php b/tests/Unit/API/Logs/Map/Psr3Test.php index 38b1320a6..526834316 100644 --- a/tests/Unit/API/Logs/Map/Psr3Test.php +++ b/tests/Unit/API/Logs/Map/Psr3Test.php @@ -5,17 +5,15 @@ namespace OpenTelemetry\Tests\Unit\API\Logs\Map; use OpenTelemetry\API\Logs\Map\Psr3; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Log\LogLevel; -/** - * @covers \OpenTelemetry\API\Logs\Map\Psr3 - */ +#[CoversClass(Psr3::class)] class Psr3Test extends TestCase { - /** - * @dataProvider levelProvider - */ + #[DataProvider('levelProvider')] public function test_severity_number(string $level): void { $this->assertNotNull(Psr3::severityNumber($level)); diff --git a/tests/Unit/API/Logs/NoopLoggerProviderTest.php b/tests/Unit/API/Logs/NoopLoggerProviderTest.php index a63f523db..e2896067a 100644 --- a/tests/Unit/API/Logs/NoopLoggerProviderTest.php +++ b/tests/Unit/API/Logs/NoopLoggerProviderTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\API\Logs\NoopLogger; use OpenTelemetry\API\Logs\NoopLoggerProvider; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Logs\NoopLoggerProvider - */ +#[CoversClass(NoopLoggerProvider::class)] class NoopLoggerProviderTest extends TestCase { public function test_provides_logger(): void diff --git a/tests/Unit/API/Logs/NoopLoggerTest.php b/tests/Unit/API/Logs/NoopLoggerTest.php index 11def8606..ce0e35e6c 100644 --- a/tests/Unit/API/Logs/NoopLoggerTest.php +++ b/tests/Unit/API/Logs/NoopLoggerTest.php @@ -5,11 +5,10 @@ namespace OpenTelemetry\Example\Unit\API\Logs; use OpenTelemetry\API\Logs\NoopLogger; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Logs\NoopLogger - */ +#[CoversClass(NoopLogger::class)] class NoopLoggerTest extends TestCase { public function test_get_instance(): void diff --git a/tests/Unit/API/Logs/SeverityTest.php b/tests/Unit/API/Logs/SeverityTest.php index 9cd048d53..bb0dc898e 100644 --- a/tests/Unit/API/Logs/SeverityTest.php +++ b/tests/Unit/API/Logs/SeverityTest.php @@ -5,13 +5,13 @@ namespace OpenTelemetry\Tests\Unit\API\Logs; use OpenTelemetry\API\Logs\Severity; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Log\LogLevel; use ValueError; -/** - * @covers \OpenTelemetry\API\Logs\Severity - */ +#[CoversClass(Severity::class)] class SeverityTest extends TestCase { public function test_value_error(): void @@ -20,9 +20,7 @@ public function test_value_error(): void Severity::fromPsr3('unknown'); } - /** - * @dataProvider levelProvider - */ + #[DataProvider('levelProvider')] public function test_severity_number(string $level): void { $this->assertNotNull(Severity::fromPsr3($level)); diff --git a/tests/Unit/API/Trace/NonRecordingSpanTest.php b/tests/Unit/API/Trace/NonRecordingSpanTest.php index 7c1a7344e..705a778f0 100644 --- a/tests/Unit/API/Trace/NonRecordingSpanTest.php +++ b/tests/Unit/API/Trace/NonRecordingSpanTest.php @@ -8,11 +8,10 @@ use OpenTelemetry\API\Trace\NonRecordingSpan; use OpenTelemetry\API\Trace\SpanContextInterface; use OpenTelemetry\SDK\Common\Attribute\AttributesInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Trace\NonRecordingSpan - */ +#[CoversClass(NonRecordingSpan::class)] class NonRecordingSpanTest extends TestCase { private ?SpanContextInterface $context = null; diff --git a/tests/Unit/API/Trace/NoopSpanBuilderTest.php b/tests/Unit/API/Trace/NoopSpanBuilderTest.php index a7ae8a35c..8cfffe69d 100644 --- a/tests/Unit/API/Trace/NoopSpanBuilderTest.php +++ b/tests/Unit/API/Trace/NoopSpanBuilderTest.php @@ -12,11 +12,10 @@ use OpenTelemetry\Context\Context; use OpenTelemetry\Context\ContextKeys; use OpenTelemetry\Context\ContextStorageInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Trace\NoopSpanBuilder - */ +#[CoversClass(NoopSpanBuilder::class)] class NoopSpanBuilderTest extends TestCase { public function test_set_parent(): void diff --git a/tests/Unit/API/Trace/Propagation/TraceContextPropagatorTest.php b/tests/Unit/API/Trace/Propagation/TraceContextPropagatorTest.php index aa7ebf1ee..2d1863bea 100644 --- a/tests/Unit/API/Trace/Propagation/TraceContextPropagatorTest.php +++ b/tests/Unit/API/Trace/Propagation/TraceContextPropagatorTest.php @@ -15,11 +15,10 @@ use OpenTelemetry\Context\Context; use OpenTelemetry\Context\ContextInterface; use OpenTelemetry\SDK\Trace\Span; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Trace\Propagation\TraceContextPropagator - */ +#[CoversClass(TraceContextPropagator::class)] class TraceContextPropagatorTest extends TestCase { private const TRACE_ID_BASE16 = 'ff000000000000000000000000000041'; diff --git a/tests/Unit/API/Trace/Propagation/TraceContextValidatorTest.php b/tests/Unit/API/Trace/Propagation/TraceContextValidatorTest.php index 4ae3b8038..14e62714f 100644 --- a/tests/Unit/API/Trace/Propagation/TraceContextValidatorTest.php +++ b/tests/Unit/API/Trace/Propagation/TraceContextValidatorTest.php @@ -5,11 +5,10 @@ namespace OpenTelemetry\Tests\Unit\API\Trace\Propagation; use OpenTelemetry\API\Trace\Propagation\TraceContextValidator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Trace\Propagation\TraceContextValidator - */ +#[CoversClass(TraceContextValidator::class)] class TraceContextValidatorTest extends TestCase { private const INVALID_TRACE_FLAG = 'f'; diff --git a/tests/Unit/API/Trace/SpanContextTest.php b/tests/Unit/API/Trace/SpanContextTest.php index 8c9d69757..7786ef562 100644 --- a/tests/Unit/API/Trace/SpanContextTest.php +++ b/tests/Unit/API/Trace/SpanContextTest.php @@ -8,11 +8,10 @@ use OpenTelemetry\API\Trace\SpanContext; use OpenTelemetry\API\Trace\SpanContextValidator; use OpenTelemetry\API\Trace\TraceState; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Trace\SpanContext - */ +#[CoversClass(SpanContext::class)] class SpanContextTest extends TestCase { private const FIRST_TRACE_ID = '00000000000000000000000000000061'; diff --git a/tests/Unit/API/Trace/SpanContextValidatorTest.php b/tests/Unit/API/Trace/SpanContextValidatorTest.php index 928faa773..874e3978e 100644 --- a/tests/Unit/API/Trace/SpanContextValidatorTest.php +++ b/tests/Unit/API/Trace/SpanContextValidatorTest.php @@ -5,11 +5,10 @@ namespace OpenTelemetry\Tests\API\Unit\Trace; use OpenTelemetry\API\Trace\SpanContextValidator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Trace\SpanContextValidator - */ +#[CoversClass(SpanContextValidator::class)] class SpanContextValidatorTest extends TestCase { private const TRACE_ID = 'ff000000000000000000000000000041'; diff --git a/tests/Unit/API/Trace/TraceStateTest.php b/tests/Unit/API/Trace/TraceStateTest.php index 3d04febde..595d88b4d 100644 --- a/tests/Unit/API/Trace/TraceStateTest.php +++ b/tests/Unit/API/Trace/TraceStateTest.php @@ -8,15 +8,16 @@ use OpenTelemetry\API\Behavior\Internal\Logging; use OpenTelemetry\API\LoggerHolder; use OpenTelemetry\API\Trace\TraceState; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use function str_repeat; /** - * @covers \OpenTelemetry\API\Trace\TraceState * @psalm-suppress UndefinedInterfaceMethod */ +#[CoversClass(TraceState::class)] class TraceStateTest extends TestCase { private LoggerInterface $logger; diff --git a/tests/Unit/API/Trace/TraceTest.php b/tests/Unit/API/Trace/TraceTest.php index 76eb27eb6..5f394e47e 100644 --- a/tests/Unit/API/Trace/TraceTest.php +++ b/tests/Unit/API/Trace/TraceTest.php @@ -11,14 +11,13 @@ use OpenTelemetry\API\Trace\SpanInterface; use OpenTelemetry\API\Trace\StatusCode; use function OpenTelemetry\API\Trace\trace; +use PHPUnit\Framework\Attributes\CoversFunction; use PHPUnit\Framework\TestCase; use RuntimeException; use stdClass; use WeakReference; -/** - * @covers \OpenTelemetry\API\Trace\trace - */ +#[CoversFunction('\OpenTelemetry\API\Trace\trace')] final class TraceTest extends TestCase { public function test_runs_with_provided_span(): void @@ -64,7 +63,7 @@ public function test_rethrows_exception(): void { $this->expectException(RuntimeException::class); - trace(Span::getInvalid(), function (): void { + trace(Span::getInvalid(), function (): never { throw new RuntimeException(); }); } @@ -76,7 +75,7 @@ public function test_records_exception(): void $span->expects($this->once())->method('recordException'); try { - trace($span, function (): void { + trace($span, function (): never { throw new RuntimeException(); }); } catch (RuntimeException $e) { @@ -89,7 +88,7 @@ public function test_ends_span_on_exception(): void $span->expects($this->once())->method('end'); try { - trace($span, function (): void { + trace($span, function (): never { throw new RuntimeException(); }); } catch (RuntimeException $e) { @@ -98,7 +97,7 @@ public function test_ends_span_on_exception(): void public function test_exception_does_not_leak_closure_reference(): void { - $c = static function (): void { + $c = static function (): never { throw new RuntimeException(); }; $r = WeakReference::create($c); diff --git a/tests/Unit/Config/SDK/Configuration/ConfigurationFactoryTest.php b/tests/Unit/Config/SDK/Configuration/ConfigurationFactoryTest.php index 2cc3af786..af6ca88f0 100644 --- a/tests/Unit/Config/SDK/Configuration/ConfigurationFactoryTest.php +++ b/tests/Unit/Config/SDK/Configuration/ConfigurationFactoryTest.php @@ -16,18 +16,18 @@ use OpenTelemetry\Config\SDK\Configuration\Environment\ServerEnvSource; use OpenTelemetry\Config\SDK\Configuration\Internal; use PHPUnit\Framework\Attributes\BackupGlobals; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversNothing; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; use Symfony\Component\Yaml\Yaml; -/** - * @covers \OpenTelemetry\Config\SDK\Configuration\ConfigurationFactory - */ +#[CoversClass(ConfigurationFactory::class)] final class ConfigurationFactoryTest extends TestCase { + public $properties; /** * @psalm-suppress MissingTemplateParam */ @@ -176,7 +176,6 @@ private function getPropertiesFromPlugin(ComponentPlugin $plugin): array { assert($plugin instanceof Internal\ComponentPlugin); - /** @phpstan-ignore-next-line */ return (fn () => $this->properties)->bindTo($plugin, Internal\ComponentPlugin::class)(); } diff --git a/tests/Unit/Context/ContextKeyTest.php b/tests/Unit/Context/ContextKeyTest.php index 7b00b6b89..a4f42c98b 100644 --- a/tests/Unit/Context/ContextKeyTest.php +++ b/tests/Unit/Context/ContextKeyTest.php @@ -5,11 +5,10 @@ namespace OpenTelemetry\Tests\Unit\Context; use OpenTelemetry\Context\ContextKey; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Context\ContextKey - */ +#[CoversClass(ContextKey::class)] class ContextKeyTest extends TestCase { public function test_name(): void diff --git a/tests/Unit/Context/ContextKeysTest.php b/tests/Unit/Context/ContextKeysTest.php index ac0ce3967..70f0d3099 100644 --- a/tests/Unit/Context/ContextKeysTest.php +++ b/tests/Unit/Context/ContextKeysTest.php @@ -5,11 +5,10 @@ namespace OpenTelemetry\Tests\Unit\Context; use OpenTelemetry\Context\ContextKeys; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Context\ContextKeys - */ +#[CoversClass(ContextKeys::class)] final class ContextKeysTest extends TestCase { public function test_span_context_key(): void diff --git a/tests/Unit/Context/ContextStorageTest.php b/tests/Unit/Context/ContextStorageTest.php index 8d6843b9b..ec9a6bfe1 100644 --- a/tests/Unit/Context/ContextStorageTest.php +++ b/tests/Unit/Context/ContextStorageTest.php @@ -6,13 +6,14 @@ use OpenTelemetry\Context\Context; use OpenTelemetry\Context\ContextStorage; +use OpenTelemetry\Context\ContextStorageHead; +use OpenTelemetry\Context\ContextStorageNode; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Context\ContextStorage - * @covers \OpenTelemetry\Context\ContextStorageHead - * @covers \OpenTelemetry\Context\ContextStorageNode - */ +#[CoversClass(ContextStorage::class)] +#[CoversClass(ContextStorageHead::class)] +#[CoversClass(ContextStorageNode::class)] class ContextStorageTest extends TestCase { public function test_scope_returns_null_in_root(): void diff --git a/tests/Unit/Context/ContextTest.php b/tests/Unit/Context/ContextTest.php index b023300a4..21a7587d7 100644 --- a/tests/Unit/Context/ContextTest.php +++ b/tests/Unit/Context/ContextTest.php @@ -8,12 +8,11 @@ use OpenTelemetry\Context\ContextKeys; use OpenTelemetry\Context\DebugScope; use OpenTelemetry\Context\ImplicitContextKeyedInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use stdClass; -/** - * @covers \OpenTelemetry\Context\Context - */ +#[CoversClass(Context::class)] class ContextTest extends TestCase { public function test_activate(): void diff --git a/tests/Unit/Context/DebugScopeTest.php b/tests/Unit/Context/DebugScopeTest.php index 35d1a06f1..93dda01f2 100644 --- a/tests/Unit/Context/DebugScopeTest.php +++ b/tests/Unit/Context/DebugScopeTest.php @@ -9,11 +9,12 @@ use function ini_set; use OpenTelemetry\Context\Context; use OpenTelemetry\Context\DebugScope; +use PHPUnit\Framework\Attributes\BackupGlobals; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Context\DebugScope - */ +#[CoversClass(DebugScope::class)] +#[CoversClass(Context::class)] final class DebugScopeTest extends TestCase { public function setUp(): void @@ -28,10 +29,6 @@ public function tearDown(): void restore_error_handler(); } - /** - * @covers \OpenTelemetry\Context\Context::activate - * @covers \OpenTelemetry\Context\Context::debugScopesDisabled - */ public function test_debug_scope_enabled_by_default(): void { $scope = Context::getCurrent()->activate(); @@ -43,9 +40,6 @@ public function test_debug_scope_enabled_by_default(): void } } - /** - * @covers \OpenTelemetry\Context\Context::activate - */ public function test_disable_debug_scope_using_assertion_mode(): void { ini_set('zend.assertions', '0'); @@ -59,11 +53,7 @@ public function test_disable_debug_scope_using_assertion_mode(): void } } - /** - * @covers \OpenTelemetry\Context\Context::activate - * @covers \OpenTelemetry\Context\Context::debugScopesDisabled - * @backupGlobals - */ + #[BackupGlobals(true)] public function test_disable_debug_scope_using_otel_php_debug_scopes_disabled(): void { $_SERVER['OTEL_PHP_DEBUG_SCOPES_DISABLED'] = 'true'; diff --git a/tests/Unit/Context/Propagation/ArrayAccessGetterSetterTest.php b/tests/Unit/Context/Propagation/ArrayAccessGetterSetterTest.php index 19af53a85..9710e14aa 100644 --- a/tests/Unit/Context/Propagation/ArrayAccessGetterSetterTest.php +++ b/tests/Unit/Context/Propagation/ArrayAccessGetterSetterTest.php @@ -7,12 +7,11 @@ use ArrayObject; use InvalidArgumentException; use OpenTelemetry\Context\Propagation\ArrayAccessGetterSetter; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use stdClass; -/** - * @covers \OpenTelemetry\Context\Propagation\ArrayAccessGetterSetter - */ +#[CoversClass(ArrayAccessGetterSetter::class)] class ArrayAccessGetterSetterTest extends TestCase { public function test_get_from_map_array(): void diff --git a/tests/Unit/Context/Propagation/MultiTextMapPropagatorTest.php b/tests/Unit/Context/Propagation/MultiTextMapPropagatorTest.php index 8736a6976..0df7327f4 100644 --- a/tests/Unit/Context/Propagation/MultiTextMapPropagatorTest.php +++ b/tests/Unit/Context/Propagation/MultiTextMapPropagatorTest.php @@ -9,10 +9,9 @@ use OpenTelemetry\Context\Context; use OpenTelemetry\Context\Propagation\MultiTextMapPropagator; use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @covers \OpenTelemetry\Context\Propagation\MultiTextMapPropagator - */ +#[CoversClass(MultiTextMapPropagator::class)] class MultiTextMapPropagatorTest extends MockeryTestCase { /** @var Mockery\MockInterface&TextMapPropagatorInterface */ diff --git a/tests/Unit/Context/Propagation/NoopTextMapPropagatorTest.php b/tests/Unit/Context/Propagation/NoopTextMapPropagatorTest.php index 0cb924285..694b9c556 100644 --- a/tests/Unit/Context/Propagation/NoopTextMapPropagatorTest.php +++ b/tests/Unit/Context/Propagation/NoopTextMapPropagatorTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\Context\Context; use OpenTelemetry\Context\Propagation\NoopTextMapPropagator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Context\Propagation\NoopTextMapPropagator - */ +#[CoversClass(NoopTextMapPropagator::class)] class NoopTextMapPropagatorTest extends TestCase { public function test_fields(): void diff --git a/tests/Unit/Context/ScopeTest.php b/tests/Unit/Context/ScopeTest.php index 17a0d76c8..d9727ff54 100644 --- a/tests/Unit/Context/ScopeTest.php +++ b/tests/Unit/Context/ScopeTest.php @@ -7,12 +7,12 @@ use Fiber; use OpenTelemetry\Context\Context; use OpenTelemetry\Context\ContextStorage; +use OpenTelemetry\Context\ContextStorageNode; use OpenTelemetry\Context\ScopeInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Context\ContextStorageNode - */ +#[CoversClass(ContextStorageNode::class)] class ScopeTest extends TestCase { public function test_scope_close_restores_context(): void diff --git a/tests/Unit/Contrib/Grpc/GrpcTransportFactoryTest.php b/tests/Unit/Contrib/Grpc/GrpcTransportFactoryTest.php index 51139e2c7..50fa771b0 100644 --- a/tests/Unit/Contrib/Grpc/GrpcTransportFactoryTest.php +++ b/tests/Unit/Contrib/Grpc/GrpcTransportFactoryTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\Contrib\Grpc\GrpcTransportFactory; use OpenTelemetry\SDK\Common\Export\TransportInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Grpc\GrpcTransportFactory - */ +#[CoversClass(GrpcTransportFactory::class)] class GrpcTransportFactoryTest extends TestCase { public function test_grpc_transport_create(): void diff --git a/tests/Unit/Contrib/Grpc/GrpcTransportTest.php b/tests/Unit/Contrib/Grpc/GrpcTransportTest.php index 9accb2b57..2e3d4beb5 100644 --- a/tests/Unit/Contrib/Grpc/GrpcTransportTest.php +++ b/tests/Unit/Contrib/Grpc/GrpcTransportTest.php @@ -8,11 +8,10 @@ use InvalidArgumentException; use OpenTelemetry\Contrib\Grpc\GrpcTransport; use OpenTelemetry\Contrib\Grpc\GrpcTransportFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Grpc\GrpcTransport - */ +#[CoversClass(GrpcTransport::class)] final class GrpcTransportTest extends TestCase { private GrpcTransport $transport; diff --git a/tests/Unit/Contrib/Otlp/AttributesConverterTest.php b/tests/Unit/Contrib/Otlp/AttributesConverterTest.php index 8d2d6344b..08281ea27 100644 --- a/tests/Unit/Contrib/Otlp/AttributesConverterTest.php +++ b/tests/Unit/Contrib/Otlp/AttributesConverterTest.php @@ -5,16 +5,14 @@ namespace OpenTelemetry\Tests\Unit\Contrib\Otlp; use OpenTelemetry\Contrib\Otlp\AttributesConverter; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Otlp\AttributesConverter - */ +#[CoversClass(AttributesConverter::class)] class AttributesConverterTest extends TestCase { - /** - * @dataProvider basicTypesProvider - */ + #[DataProvider('basicTypesProvider')] public function test_convert_basic_types($value, string $expected): void { $json = AttributesConverter::convertAnyValue($value)->serializeToJsonString(); @@ -43,9 +41,7 @@ public function test_convert_bytes(): void $this->assertSame("\xe2", $anyValue->getBytesValue()); } - /** - * @dataProvider arrayProvider - */ + #[DataProvider('arrayProvider')] public function test_is_simple_array(array $value, bool $expected): void { $this->assertSame($expected, AttributesConverter::isSimpleArray($value)); diff --git a/tests/Unit/Contrib/Otlp/HttpEndpointResolverTest.php b/tests/Unit/Contrib/Otlp/HttpEndpointResolverTest.php index 108160b38..ae8a29d3f 100644 --- a/tests/Unit/Contrib/Otlp/HttpEndpointResolverTest.php +++ b/tests/Unit/Contrib/Otlp/HttpEndpointResolverTest.php @@ -9,11 +9,11 @@ use OpenTelemetry\API\Signals; use OpenTelemetry\Contrib\Otlp\HttpEndpointResolver; use OpenTelemetry\Contrib\Otlp\HttpEndpointResolverInterface; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Otlp\HttpEndpointResolver - */ +#[CoversClass(HttpEndpointResolver::class)] class HttpEndpointResolverTest extends TestCase { private const SIGNALS = [ @@ -31,9 +31,7 @@ class HttpEndpointResolverTest extends TestCase 'https', ]; - /** - * @dataProvider provideEndpoints - */ + #[DataProvider('provideEndpoints')] public function test_normalize(string $baseEndpoint, string $signal, string $expectedEndpoint): void { $this->assertSame( @@ -43,9 +41,7 @@ public function test_normalize(string $baseEndpoint, string $signal, string $exp ); } - /** - * @dataProvider provideSignals - */ + #[DataProvider('provideSignals')] public function test_normalize_throws_exception_on_invalid_scheme(string $signal): void { $this->expectException(InvalidArgumentException::class); @@ -54,9 +50,7 @@ public function test_normalize_throws_exception_on_invalid_scheme(string $signal ->resolve('foo://collector', $signal); } - /** - * @dataProvider provideSchemes - */ + #[DataProvider('provideSchemes')] public function test_normalize_throws_exception_on_invalid_signal(string $scheme): void { $this->expectException(InvalidArgumentException::class); @@ -65,9 +59,7 @@ public function test_normalize_throws_exception_on_invalid_signal(string $scheme ->resolve($scheme . '://collector', 'foo'); } - /** - * @dataProvider provideSignals - */ + #[DataProvider('provideSignals')] public function test_normalize_throws_exception_on_invalid_url(string $signal): void { $this->expectException(InvalidArgumentException::class); @@ -102,9 +94,7 @@ public static function provideEndpoints(): Generator } } - /** - * @dataProvider provideReferences - */ + #[DataProvider('provideReferences')] public function test_references_are_correct(array $values, array $reference): void { $this->assertSame( diff --git a/tests/Unit/Contrib/Otlp/LogsConverterTest.php b/tests/Unit/Contrib/Otlp/LogsConverterTest.php index dd8bc5c51..705746d75 100644 --- a/tests/Unit/Contrib/Otlp/LogsConverterTest.php +++ b/tests/Unit/Contrib/Otlp/LogsConverterTest.php @@ -10,12 +10,11 @@ use OpenTelemetry\Context\ContextKeys; use OpenTelemetry\Contrib\Otlp\LogsConverter; use OpenTelemetry\SDK\Logs\ReadableLogRecord; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Otlp\LogsConverter - */ +#[CoversClass(LogsConverter::class)] class LogsConverterTest extends TestCase { private const TRACE_ID_BASE16 = 'ff000000000000000000000000000041'; @@ -51,8 +50,8 @@ public function test_convert_with_context(): void $request = $this->converter->convert([$this->record]); /** @psalm-suppress InvalidArgument */ $row = $request->getResourceLogs()[0]->getScopeLogs()[0]->getLogRecords()[0]; - $this->assertSame(self::TRACE_ID_BASE16, bin2hex($row->getTraceId())); - $this->assertSame(self::SPAN_ID_BASE16, bin2hex($row->getSpanId())); + $this->assertSame(self::TRACE_ID_BASE16, bin2hex((string) $row->getTraceId())); + $this->assertSame(self::SPAN_ID_BASE16, bin2hex((string) $row->getSpanId())); $this->assertSame(self::FLAGS, $row->getFlags()); } } diff --git a/tests/Unit/Contrib/Otlp/LogsExporterFactoryTest.php b/tests/Unit/Contrib/Otlp/LogsExporterFactoryTest.php index eab64311a..9a2d22f57 100644 --- a/tests/Unit/Contrib/Otlp/LogsExporterFactoryTest.php +++ b/tests/Unit/Contrib/Otlp/LogsExporterFactoryTest.php @@ -4,22 +4,22 @@ namespace OpenTelemetry\Tests\Unit\Contrib\Otlp; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\Contrib\Otlp\LogsExporterFactory; use OpenTelemetry\SDK\Common\Configuration\KnownValues; use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface; use OpenTelemetry\SDK\Common\Export\TransportInterface; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; -/** - * @covers \OpenTelemetry\Contrib\Otlp\LogsExporterFactory - */ +#[CoversClass(LogsExporterFactory::class)] class LogsExporterFactoryTest extends TestCase { - use EnvironmentVariables; + use TestState; /** @var TransportFactoryInterface&MockObject $record */ private TransportFactoryInterface $transportFactory; @@ -32,11 +32,6 @@ public function setUp(): void $this->transport = $this->createMock(TransportInterface::class); } - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - public function test_unknown_protocol_exception(): void { $this->expectException(RuntimeException::class); @@ -45,9 +40,7 @@ public function test_unknown_protocol_exception(): void $factory->create(); } - /** - * @dataProvider configProvider - */ + #[DataProvider('configProvider')] public function test_create(array $env, string $endpoint, string $protocol, string $compression, array $headerKeys = [], array $expectedValues = []): void { foreach ($env as $k => $v) { diff --git a/tests/Unit/Contrib/Otlp/LogsExporterTest.php b/tests/Unit/Contrib/Otlp/LogsExporterTest.php index 9414633b2..a5e3857cb 100644 --- a/tests/Unit/Contrib/Otlp/LogsExporterTest.php +++ b/tests/Unit/Contrib/Otlp/LogsExporterTest.php @@ -9,12 +9,11 @@ use OpenTelemetry\SDK\Common\Export\TransportInterface; use OpenTelemetry\SDK\Common\Future\CompletedFuture; use OpenTelemetry\SDK\Common\Future\ErrorFuture; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Otlp\LogsExporter - */ +#[CoversClass(LogsExporter::class)] class LogsExporterTest extends TestCase { private MockObject $transport; diff --git a/tests/Unit/Contrib/Otlp/MetricConverterTest.php b/tests/Unit/Contrib/Otlp/MetricConverterTest.php index 143049179..1de1a02dd 100644 --- a/tests/Unit/Contrib/Otlp/MetricConverterTest.php +++ b/tests/Unit/Contrib/Otlp/MetricConverterTest.php @@ -20,11 +20,10 @@ use OpenTelemetry\SDK\Metrics\Data\Temporality; use OpenTelemetry\SDK\Resource\ResourceInfo; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Otlp\MetricConverter - */ +#[CoversClass(MetricConverter::class)] final class MetricConverterTest extends TestCase { public function test_empty_batch_returns_empty_request(): void diff --git a/tests/Unit/Contrib/Otlp/MetricExporterFactoryTest.php b/tests/Unit/Contrib/Otlp/MetricExporterFactoryTest.php index fc9f406ba..774800dd4 100644 --- a/tests/Unit/Contrib/Otlp/MetricExporterFactoryTest.php +++ b/tests/Unit/Contrib/Otlp/MetricExporterFactoryTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Unit\Contrib\Otlp; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\Contrib\Otlp\MetricExporterFactory; use OpenTelemetry\SDK\Common\Configuration\KnownValues; use OpenTelemetry\SDK\Common\Configuration\Variables; @@ -13,15 +12,19 @@ use OpenTelemetry\SDK\Metrics\AggregationTemporalitySelectorInterface; use OpenTelemetry\SDK\Metrics\Data\Temporality; use OpenTelemetry\SDK\Metrics\MetricMetadataInterface; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\Contrib\Otlp\MetricExporterFactory * @psalm-suppress UndefinedInterfaceMethod */ +#[CoversClass(MetricExporterFactory::class)] class MetricExporterFactoryTest extends TestCase { - use EnvironmentVariables; + use TestState; + private TransportFactoryInterface $transportFactory; private TransportInterface $transport; @@ -31,11 +34,6 @@ public function setUp(): void $this->transport = $this->createMock(TransportInterface::class); } - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - public function test_unknown_protocol_exception(): void { $this->expectException(\RuntimeException::class); @@ -44,9 +42,7 @@ public function test_unknown_protocol_exception(): void $factory->create(); } - /** - * @dataProvider temporalityProvider - */ + #[DataProvider('temporalityProvider')] public function test_create_with_temporality(array $env, ?string $expected): void { // @phpstan-ignore-next-line @@ -98,9 +94,7 @@ public static function temporalityProvider(): array ]; } - /** - * @dataProvider configProvider - */ + #[DataProvider('configProvider')] public function test_create(array $env, string $endpoint, string $protocol, string $compression, array $headerKeys = [], array $expectedValues = []): void { foreach ($env as $k => $v) { diff --git a/tests/Unit/Contrib/Otlp/MetricExporterTest.php b/tests/Unit/Contrib/Otlp/MetricExporterTest.php index 44880c7a4..8471596f7 100644 --- a/tests/Unit/Contrib/Otlp/MetricExporterTest.php +++ b/tests/Unit/Contrib/Otlp/MetricExporterTest.php @@ -15,12 +15,11 @@ use OpenTelemetry\SDK\Metrics\Data\Sum; use OpenTelemetry\SDK\Metrics\Data\Temporality; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use function stream_get_contents; -/** - * @covers \OpenTelemetry\Contrib\Otlp\MetricExporter - */ +#[CoversClass(MetricExporter::class)] final class MetricExporterTest extends TestCase { private $stream; diff --git a/tests/Unit/Contrib/Otlp/OtlpHttpTransportFactoryTest.php b/tests/Unit/Contrib/Otlp/OtlpHttpTransportFactoryTest.php index 771e30b33..a0c11ddeb 100644 --- a/tests/Unit/Contrib/Otlp/OtlpHttpTransportFactoryTest.php +++ b/tests/Unit/Contrib/Otlp/OtlpHttpTransportFactoryTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory; use OpenTelemetry\SDK\Common\Export\Http\PsrTransport; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Otlp\OtlpHttpTransportFactory - */ +#[CoversClass(OtlpHttpTransportFactory::class)] class OtlpHttpTransportFactoryTest extends TestCase { private OtlpHttpTransportFactory $factory; diff --git a/tests/Unit/Contrib/Otlp/OtlpUtilTest.php b/tests/Unit/Contrib/Otlp/OtlpUtilTest.php index 8b22c6383..091b70c59 100644 --- a/tests/Unit/Contrib/Otlp/OtlpUtilTest.php +++ b/tests/Unit/Contrib/Otlp/OtlpUtilTest.php @@ -4,23 +4,18 @@ namespace OpenTelemetry\Tests\Unit\Contrib\Otlp; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Signals; use OpenTelemetry\Contrib\Otlp\OtlpUtil; use OpenTelemetry\SDK\Common\Configuration\Variables; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Otlp\OtlpUtil - */ +#[CoversClass(OtlpUtil::class)] class OtlpUtilTest extends TestCase { - use EnvironmentVariables; - - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } + use TestState; public function test_get_user_agent_header(): void { @@ -35,9 +30,7 @@ public function test_method_not_defined(): void OtlpUtil::method('foo'); } - /** - * @dataProvider methodProvider - */ + #[DataProvider('methodProvider')] public function test_method(string $signal, string $expected): void { $method = OtlpUtil::method($signal); @@ -53,9 +46,7 @@ public static function methodProvider(): array ]; } - /** - * @dataProvider headersProvider - */ + #[DataProvider('headersProvider')] public function test_get_headers(string $signal, array $env, array $expected): void { foreach ($env as $var => $value) { diff --git a/tests/Unit/Contrib/Otlp/ProtobufSerializerTest.php b/tests/Unit/Contrib/Otlp/ProtobufSerializerTest.php index 97c6aef4b..7552ae208 100644 --- a/tests/Unit/Contrib/Otlp/ProtobufSerializerTest.php +++ b/tests/Unit/Contrib/Otlp/ProtobufSerializerTest.php @@ -7,11 +7,10 @@ use OpenTelemetry\Contrib\Otlp\ProtobufSerializer; use Opentelemetry\Proto\Collector\Trace\V1\ExportTraceServiceResponse; use OpenTelemetry\SDK\Common\Export\TransportInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Otlp\ProtobufSerializer - */ +#[CoversClass(ProtobufSerializer::class)] class ProtobufSerializerTest extends TestCase { public function test_empty_json_response(): void diff --git a/tests/Unit/Contrib/Otlp/SpanConverterTest.php b/tests/Unit/Contrib/Otlp/SpanConverterTest.php index 5a568e5a9..f5975c113 100644 --- a/tests/Unit/Contrib/Otlp/SpanConverterTest.php +++ b/tests/Unit/Contrib/Otlp/SpanConverterTest.php @@ -22,11 +22,11 @@ use OpenTelemetry\SDK\Resource\ResourceInfo; use OpenTelemetry\SDK\Trace\StatusData; use OpenTelemetry\Tests\Unit\SDK\Util\SpanData; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Otlp\SpanConverter - */ +#[CoversClass(SpanConverter::class)] class SpanConverterTest extends TestCase { public function test_convert_span_to_payload(): void @@ -45,8 +45,8 @@ public function test_convert_span_to_payload(): void /** @psalm-suppress InvalidArgument */ $row = $converter->convert([$span])->getResourceSpans()[0]->getScopeSpans()[0]->getSpans()[0]; - $this->assertSame($span->getContext()->getSpanId(), bin2hex($row->getSpanId())); - $this->assertSame($span->getContext()->getTraceId(), bin2hex($row->getTraceId())); + $this->assertSame($span->getContext()->getSpanId(), bin2hex((string) $row->getSpanId())); + $this->assertSame($span->getContext()->getTraceId(), bin2hex((string) $row->getTraceId())); $this->assertSame(V1\SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK, $row->getFlags()); $this->assertSame($span->getName(), $row->getName()); @@ -78,9 +78,7 @@ public function test_span_context_is_remote_flags(): void $this->assertSame(V1\SpanFlags::SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK | V1\SpanFlags::SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK | TraceFlags::SAMPLED, $row->getLinks()[1]->getFlags()); } - /** - * @dataProvider attributeAreCoercedCorrectlyDataProvider - */ + #[DataProvider('attributeAreCoercedCorrectlyDataProvider')] public function test_attribute_are_coerced_correctly($actual, $expected): void { $span = (new SpanData()) @@ -288,9 +286,7 @@ public function test_otlp_no_spans(): void $this->assertCount(0, (new SpanConverter())->convert([])->getResourceSpans()); } - /** - * @dataProvider spanKindProvider - */ + #[DataProvider('spanKindProvider')] public function test_span_kind($kind, $expected): void { $span = (new SpanData())->setKind($kind); diff --git a/tests/Unit/Contrib/Otlp/SpanExporterFactoryTest.php b/tests/Unit/Contrib/Otlp/SpanExporterFactoryTest.php index af39021fb..015801562 100644 --- a/tests/Unit/Contrib/Otlp/SpanExporterFactoryTest.php +++ b/tests/Unit/Contrib/Otlp/SpanExporterFactoryTest.php @@ -4,21 +4,23 @@ namespace OpenTelemetry\Tests\Unit\Contrib\Otlp; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\Contrib\Otlp\SpanExporterFactory; use OpenTelemetry\SDK\Common\Configuration\KnownValues; use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Common\Export\TransportFactoryInterface; use OpenTelemetry\SDK\Common\Export\TransportInterface; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\Contrib\Otlp\SpanExporterFactory * @psalm-suppress UndefinedInterfaceMethod */ +#[CoversClass(SpanExporterFactory::class)] class SpanExporterFactoryTest extends TestCase { - use EnvironmentVariables; + use TestState; private TransportFactoryInterface $transportFactory; private TransportInterface $transport; @@ -29,11 +31,6 @@ public function setUp(): void $this->transport = $this->createMock(TransportInterface::class); } - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - public function test_unknown_protocol_exception(): void { $this->expectException(\UnexpectedValueException::class); @@ -42,9 +39,7 @@ public function test_unknown_protocol_exception(): void $factory->create(); } - /** - * @dataProvider configProvider - */ + #[DataProvider('configProvider')] public function test_create(array $env, string $endpoint, string $protocol, string $compression, array $headerKeys = [], array $expectedValues = []): void { foreach ($env as $k => $v) { diff --git a/tests/Unit/Contrib/Otlp/SpanExporterTest.php b/tests/Unit/Contrib/Otlp/SpanExporterTest.php index 024c5c43d..213ee193f 100644 --- a/tests/Unit/Contrib/Otlp/SpanExporterTest.php +++ b/tests/Unit/Contrib/Otlp/SpanExporterTest.php @@ -13,13 +13,12 @@ use OpenTelemetry\SDK\Common\Future\CompletedFuture; use OpenTelemetry\SDK\Common\Future\ErrorFuture; use OpenTelemetry\Tests\Unit\SDK\Util\SpanData; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use function stream_get_contents; -/** - * @covers \OpenTelemetry\Contrib\Otlp\SpanExporter - */ +#[CoversClass(SpanExporter::class)] class SpanExporterTest extends TestCase { private MockObject $transport; diff --git a/tests/Unit/Contrib/Zipkin/ZipkinExporterTest.php b/tests/Unit/Contrib/Zipkin/ZipkinExporterTest.php index 7c990226d..e2a29eb70 100644 --- a/tests/Unit/Contrib/Zipkin/ZipkinExporterTest.php +++ b/tests/Unit/Contrib/Zipkin/ZipkinExporterTest.php @@ -8,10 +8,9 @@ use OpenTelemetry\SDK\Common\Export\TransportInterface; use OpenTelemetry\Tests\Unit\SDK\Trace\SpanExporter\AbstractExporterTestCase; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @covers \OpenTelemetry\Contrib\Zipkin\Exporter - */ +#[CoversClass(Exporter::class)] class ZipkinExporterTest extends AbstractExporterTestCase { /** diff --git a/tests/Unit/Contrib/Zipkin/ZipkinSpanConverterTest.php b/tests/Unit/Contrib/Zipkin/ZipkinSpanConverterTest.php index cbf33217d..73f9c4340 100644 --- a/tests/Unit/Contrib/Zipkin/ZipkinSpanConverterTest.php +++ b/tests/Unit/Contrib/Zipkin/ZipkinSpanConverterTest.php @@ -16,11 +16,11 @@ use OpenTelemetry\SDK\Trace\SpanDataInterface; use OpenTelemetry\SDK\Trace\StatusData; use OpenTelemetry\Tests\Unit\SDK\Util\SpanData; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Contrib\Zipkin\SpanConverter - */ +#[CoversClass(SpanConverter::class)] class ZipkinSpanConverterTest extends TestCase { public function test_should_convert_a_span_to_a_payload_for_zipkin(): void @@ -117,9 +117,7 @@ public function test_should_omit_empty_keys_from_zipkin_span(): void $this->assertArrayNotHasKey('otel.scope.version', $row); } - /** - * @dataProvider spanKindProvider - */ + #[DataProvider('spanKindProvider')] public function test_should_convert_otel_span_to_a_zipkin_span(int $internalSpanKind, string $expectedSpanKind): void { $span = (new SpanData()) @@ -141,9 +139,7 @@ public static function spanKindProvider(): array ]; } - /** - * @dataProvider unmappedSpanKindProvider - */ + #[DataProvider('unmappedSpanKindProvider')] public function test_should_convert_an_unmapped_otel_internal_span_to_a_zipkin_span_of_unspecified_kind($kind): void { $span = (new SpanData()) @@ -199,7 +195,7 @@ public function test_should_use_otel_ipv_6_correctly_for_zipkin_remote_endpoint( $converter = new SpanConverter(); $row = $converter->convert([$span])[0]; - $this->assertSame('00000000000000000000000000000001', bin2hex($row['remoteEndpoint']['ipv6'])); //Couldn't figure out how to do a direct assertion against binary data + $this->assertSame('00000000000000000000000000000001', bin2hex((string) $row['remoteEndpoint']['ipv6'])); //Couldn't figure out how to do a direct assertion against binary data } /** @@ -248,9 +244,9 @@ public function test_tags_are_coerced_correctly_to_strings(): void } /** - * @dataProvider droppedProvider * @see /~https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/common/mapping-to-non-otlp.md#dropped-attributes-count */ + #[DataProvider('droppedProvider')] public function test_displays_non_zero_dropped_counts(int $dropped, bool $expected): void { $attributes = $this->createMock(AttributesInterface::class); diff --git a/tests/Unit/Extension/Propagator/B3/B3DebugFlagContextKeyTest.php b/tests/Unit/Extension/Propagator/B3/B3DebugFlagContextKeyTest.php index 56ec69d78..7fd74ce28 100644 --- a/tests/Unit/Extension/Propagator/B3/B3DebugFlagContextKeyTest.php +++ b/tests/Unit/Extension/Propagator/B3/B3DebugFlagContextKeyTest.php @@ -5,11 +5,10 @@ namespace OpenTelemetry\Tests\Unit\Extension\Propagator\B3; use OpenTelemetry\Extension\Propagator\B3\B3DebugFlagContextKey; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\B3\B3DebugFlagContextKey - */ +#[CoversClass(B3DebugFlagContextKey::class)] class B3DebugFlagContextKeyTest extends TestCase { public function test_b3_debug_flag_key(): void diff --git a/tests/Unit/Extension/Propagator/B3/B3MultiPropagatorTest.php b/tests/Unit/Extension/Propagator/B3/B3MultiPropagatorTest.php index 83492ee6b..5ee44e54b 100644 --- a/tests/Unit/Extension/Propagator/B3/B3MultiPropagatorTest.php +++ b/tests/Unit/Extension/Propagator/B3/B3MultiPropagatorTest.php @@ -13,11 +13,11 @@ use OpenTelemetry\Extension\Propagator\B3\B3DebugFlagContextKey; use OpenTelemetry\Extension\Propagator\B3\B3MultiPropagator; use OpenTelemetry\SDK\Trace\Span; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\B3\B3MultiPropagator - */ +#[CoversClass(B3MultiPropagator::class)] class B3MultiPropagatorTest extends TestCase { private const TRACE_ID_BASE16 = 'ff000000000000000000000000000041'; @@ -246,9 +246,7 @@ public function test_extract_debug_with_non_sampled_context(): void ); } - /** - * @dataProvider sampledValueProvider - */ + #[DataProvider('sampledValueProvider')] public function test_extract_sampled_context($sampledValue): void { $carrier = [ @@ -273,9 +271,7 @@ public static function sampledValueProvider(): array ]; } - /** - * @dataProvider notSampledValueProvider - */ + #[DataProvider('notSampledValueProvider')] public function test_extract_non_sampled_context($sampledValue): void { $carrier = [ @@ -300,9 +296,7 @@ public static function notSampledValueProvider(): array ]; } - /** - * @dataProvider invalidDebugValueProvider - */ + #[DataProvider('invalidDebugValueProvider')] public function test_extract_invalid_debug_with_sampled_context($debugValue): void { $carrier = [ @@ -322,9 +316,7 @@ public function test_extract_invalid_debug_with_sampled_context($debugValue): vo ); } - /** - * @dataProvider invalidDebugValueProvider - */ + #[DataProvider('invalidDebugValueProvider')] public function test_extract_invalid_debug_with_non_sampled_context($debugValue): void { $carrier = [ @@ -354,9 +346,7 @@ public static function invalidDebugValueProvider(): array ]; } - /** - * @dataProvider invalidSampledValueProvider - */ + #[DataProvider('invalidSampledValueProvider')] public function test_extract_invalid_sampled_context($sampledValue): void { $carrier = [ diff --git a/tests/Unit/Extension/Propagator/B3/B3PropagatorTest.php b/tests/Unit/Extension/Propagator/B3/B3PropagatorTest.php index e1d7f3462..8cf8598ca 100644 --- a/tests/Unit/Extension/Propagator/B3/B3PropagatorTest.php +++ b/tests/Unit/Extension/Propagator/B3/B3PropagatorTest.php @@ -14,11 +14,11 @@ use OpenTelemetry\Extension\Propagator\B3\B3Propagator; use OpenTelemetry\Extension\Propagator\B3\B3SinglePropagator; use OpenTelemetry\SDK\Trace\Span; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\B3\B3Propagator - */ +#[CoversClass(B3Propagator::class)] class B3PropagatorTest extends TestCase { private const B3_TRACE_ID_16_CHAR = 'ff00051791e00041'; @@ -159,9 +159,7 @@ public function test_extract_only_b3multi_sampled_context_with_b3single_instance ); } - /** - * @dataProvider validTraceIdProvider - */ + #[DataProvider('validTraceIdProvider')] public function test_extract_only_b3multi_sampled_context_with_b3multi_instance(string $traceId, string $expected): void { $carrier = [ @@ -180,9 +178,7 @@ public function test_extract_only_b3multi_sampled_context_with_b3multi_instance( ); } - /** - * @dataProvider validTraceIdProvider - */ + #[DataProvider('validTraceIdProvider')] public function test_extract_b3_single(string $traceId, string $expected): void { $carrier = [ @@ -248,9 +244,7 @@ public function test_extract_both_sampled_context_with_b3multi_instance(): void ); } - /** - * @dataProvider invalidB3SingleHeaderValueProvider - */ + #[DataProvider('invalidB3SingleHeaderValueProvider')] public function test_extract_b3_single_invalid_and_b3_multi_valid_context_with_b3single_instance($headerValue): void { $carrier = [ @@ -270,9 +264,7 @@ public function test_extract_b3_single_invalid_and_b3_multi_valid_context_with_b ); } - /** - * @dataProvider invalidB3SingleHeaderValueProvider - */ + #[DataProvider('invalidB3SingleHeaderValueProvider')] public function test_extract_b3_single_invalid_and_b3_multi_valid_context_with_b3multi_instance($headerValue): void { $carrier = [ diff --git a/tests/Unit/Extension/Propagator/B3/B3SinglePropagatorTest.php b/tests/Unit/Extension/Propagator/B3/B3SinglePropagatorTest.php index ed9669b1f..c2b2033df 100644 --- a/tests/Unit/Extension/Propagator/B3/B3SinglePropagatorTest.php +++ b/tests/Unit/Extension/Propagator/B3/B3SinglePropagatorTest.php @@ -13,11 +13,11 @@ use OpenTelemetry\Extension\Propagator\B3\B3DebugFlagContextKey; use OpenTelemetry\Extension\Propagator\B3\B3SinglePropagator; use OpenTelemetry\SDK\Trace\Span; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\B3\B3SinglePropagator - */ +#[CoversClass(B3SinglePropagator::class)] class B3SinglePropagatorTest extends TestCase { private const TRACE_ID_BASE16 = 'ff000000000000000000000000000041'; @@ -144,9 +144,7 @@ public function test_extract_nothing(): void ); } - /** - * @dataProvider debugValueProvider - */ + #[DataProvider('debugValueProvider')] public function test_extract_debug_context($headerValue): void { $carrier = [ @@ -249,9 +247,7 @@ public function test_extract_defer_sampling(): void ); } - /** - * @dataProvider invalidSampledValueProvider - */ + #[DataProvider('invalidSampledValueProvider')] public function test_extract_invalid_sampled_context($headerValue): void { $carrier = [ diff --git a/tests/Unit/Extension/Propagator/CloudTrace/CloudTraceFormatterTest.php b/tests/Unit/Extension/Propagator/CloudTrace/CloudTraceFormatterTest.php index 2b4e2aad9..dc141a02d 100644 --- a/tests/Unit/Extension/Propagator/CloudTrace/CloudTraceFormatterTest.php +++ b/tests/Unit/Extension/Propagator/CloudTrace/CloudTraceFormatterTest.php @@ -8,17 +8,15 @@ use OpenTelemetry\API\Trace\SpanContextInterface; use OpenTelemetry\API\Trace\TraceFlags; use OpenTelemetry\Extension\Propagator\CloudTrace\CloudTraceFormatter; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\CloudTrace\CloudTraceFormatter - */ +#[CoversClass(CloudTraceFormatter::class)] class CloudTraceFormatterTest extends TestCase { - /** - * @dataProvider for_test_deserialize - */ + #[DataProvider('for_test_deserialize')] public function test_deserialize(string $header, string $traceId, string $spanId, int $sample) : void { $result = CloudTraceFormatter::deserialize($header); @@ -35,9 +33,7 @@ public static function for_test_deserialize() : array ]; } - /** - * @dataProvider for_test_serialize - */ + #[DataProvider('for_test_serialize')] public function test_serialize(SpanContextInterface $span, string $header) : void { $result = CloudTraceFormatter::serialize($span); diff --git a/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorOneWayTest.php b/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorOneWayTest.php index 65b72558e..cf104ac0f 100644 --- a/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorOneWayTest.php +++ b/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorOneWayTest.php @@ -13,11 +13,10 @@ use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; use OpenTelemetry\Extension\Propagator\CloudTrace\CloudTracePropagator; use OpenTelemetry\SDK\Trace\Span; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\CloudTrace\CloudTracePropagator - */ +#[CoversClass(CloudTracePropagator::class)] class CloudTracePropagatorOneWayTest extends TestCase { private const TRACE_ID_BASE16 = 'ff000000000000000000000000000041'; diff --git a/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorTest.php b/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorTest.php index 7a6317f15..66aacc5d2 100644 --- a/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorTest.php +++ b/tests/Unit/Extension/Propagator/CloudTrace/CloudTracePropagatorTest.php @@ -13,11 +13,10 @@ use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; use OpenTelemetry\Extension\Propagator\CloudTrace\CloudTracePropagator; use OpenTelemetry\SDK\Trace\Span; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\CloudTrace\CloudTracePropagator - */ +#[CoversClass(CloudTracePropagator::class)] class CloudTracePropagatorTest extends TestCase { private const TRACE_ID_BASE16 = 'ff000000000000000000000000000041'; diff --git a/tests/Unit/Extension/Propagator/CloudTrace/UtilsTest.php b/tests/Unit/Extension/Propagator/CloudTrace/UtilsTest.php index cf27a4c3c..592ed3191 100644 --- a/tests/Unit/Extension/Propagator/CloudTrace/UtilsTest.php +++ b/tests/Unit/Extension/Propagator/CloudTrace/UtilsTest.php @@ -5,17 +5,15 @@ namespace OpenTelemetry\Tests\Unit\Extension\Propagator\CloudTrace; use OpenTelemetry\Extension\Propagator\CloudTrace\Utils; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\CloudTrace\Utils - */ +#[CoversClass(Utils::class)] class UtilsTest extends TestCase { - /** - * @dataProvider for_test_left_zero_pad - */ + #[DataProvider('for_test_left_zero_pad')] public function test_left_zero_pad(string $pad, int $howMuch, string $equalsTo) : void { $this->assertEquals(Utils::leftZeroPad($pad, $howMuch), $equalsTo, "Given leftZeroPad($pad, $howMuch) != $equalsTo"); @@ -31,9 +29,7 @@ public static function for_test_left_zero_pad() : array ]; } - /** - * @dataProvider for_test_dec_to_hex - */ + #[DataProvider('for_test_dec_to_hex')] public function test_dec_to_hex(string $decNum, string $equalsTo) : void { $this->assertEquals(Utils::decToHex($decNum), $equalsTo, "Given decToHex($decNum) != $equalsTo"); @@ -50,9 +46,7 @@ public static function for_test_dec_to_hex() : array ]; } - /** - * @dataProvider for_test_hex_to_dec - */ + #[DataProvider('for_test_hex_to_dec')] public function test_hex_to_dec(string $hexNum, string $equalsTo) : void { $this->assertEquals(Utils::hexToDec($hexNum), $equalsTo, "Given hexToDec($hexNum) != $equalsTo"); @@ -76,9 +70,7 @@ public static function for_test_hex_to_dec() : array ]; } - /** - * @dataProvider for_test_is_big_num - */ + #[DataProvider('for_test_is_big_num')] public function test_is_big_num($num, bool $equalsTo) : void { $this->assertEquals(Utils::isBigNum($num), $equalsTo, "Given isBigNum($num) != $equalsTo"); @@ -99,9 +91,7 @@ public static function for_test_is_big_num() : array ]; } - /** - * @dataProvider for_test_base_convert - */ + #[DataProvider('for_test_base_convert')] public function test_base_convert(string $num, int $fromBase, int $toBase, string $equalsTo) : void { $result = Utils::baseConvert($num, $fromBase, $toBase); diff --git a/tests/Unit/Extension/Propagator/Jaeger/JaegerBaggagePropagatorTest.php b/tests/Unit/Extension/Propagator/Jaeger/JaegerBaggagePropagatorTest.php index 911067376..fdaa1b867 100644 --- a/tests/Unit/Extension/Propagator/Jaeger/JaegerBaggagePropagatorTest.php +++ b/tests/Unit/Extension/Propagator/Jaeger/JaegerBaggagePropagatorTest.php @@ -8,11 +8,10 @@ use OpenTelemetry\Context\Context; use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; use OpenTelemetry\Extension\Propagator\Jaeger\JaegerBaggagePropagator; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\Jaeger\JaegerBaggagePropagator - */ +#[CoversClass(JaegerBaggagePropagator::class)] class JaegerBaggagePropagatorTest extends TestCase { private TextMapPropagatorInterface $propagator; diff --git a/tests/Unit/Extension/Propagator/Jaeger/JaegerDebugFlagContextKeyTest.php b/tests/Unit/Extension/Propagator/Jaeger/JaegerDebugFlagContextKeyTest.php index 32424551a..51c7fd1e7 100644 --- a/tests/Unit/Extension/Propagator/Jaeger/JaegerDebugFlagContextKeyTest.php +++ b/tests/Unit/Extension/Propagator/Jaeger/JaegerDebugFlagContextKeyTest.php @@ -5,11 +5,10 @@ namespace OpenTelemetry\Tests\Unit\Extension\Propagator\Jaeger; use OpenTelemetry\Extension\Propagator\Jaeger\JaegerDebugFlagContextKey; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\Jaeger\JaegerDebugFlagContextKey - */ +#[CoversClass(JaegerDebugFlagContextKey::class)] class JaegerDebugFlagContextKeyTest extends TestCase { public function test_jaeger_debug_flag_key(): void diff --git a/tests/Unit/Extension/Propagator/Jaeger/JaegerPropagatorTest.php b/tests/Unit/Extension/Propagator/Jaeger/JaegerPropagatorTest.php index a8d8e57f2..8e18045b7 100644 --- a/tests/Unit/Extension/Propagator/Jaeger/JaegerPropagatorTest.php +++ b/tests/Unit/Extension/Propagator/Jaeger/JaegerPropagatorTest.php @@ -14,11 +14,10 @@ use OpenTelemetry\Extension\Propagator\Jaeger\JaegerDebugFlagContextKey; use OpenTelemetry\Extension\Propagator\Jaeger\JaegerPropagator; use OpenTelemetry\SDK\Trace\Span; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\Extension\Propagator\Jaeger\JaegerPropagator - */ +#[CoversClass(JaegerPropagator::class)] class JaegerPropagatorTest extends TestCase { private const TRACE_ID_BASE16 = '6bec5956ce56d66eb47802ab1cf6c4a0'; diff --git a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/DependencyResolverTest.php b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/DependencyResolverTest.php index a041b8579..dea8cf907 100644 --- a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/DependencyResolverTest.php +++ b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/DependencyResolverTest.php @@ -11,6 +11,8 @@ use OpenTelemetry\SDK\Common\Http\HttpPlug\Client\ResolverInterface as HttpPlugClientResolverInterface; use OpenTelemetry\SDK\Common\Http\Psr\Client\ResolverInterface as PsrClientResolverInterface; use OpenTelemetry\SDK\Common\Http\Psr\Message\FactoryResolverInterface as MessageFactoryResolverInterface; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface as PsrClientInterface; use Psr\Http\Message\RequestFactoryInterface; @@ -21,9 +23,7 @@ use Psr\Http\Message\UriFactoryInterface; use ReflectionClass; -/** - * @covers \OpenTelemetry\SDK\Common\Adapter\HttpDiscovery\DependencyResolver - */ +#[CoversClass(DependencyResolver::class)] class DependencyResolverTest extends TestCase { private const DEPENDENCIES = [ @@ -48,9 +48,7 @@ class DependencyResolverTest extends TestCase PsrClientResolverInterface::class => ['Client', 'PsrClient'], ]; - /** - * @dataProvider provideDependencies - */ + #[DataProvider('provideDependencies')] public function test_resolve(string $method, object $dependency, array $arguments): void { $instance = DependencyResolver::create(...$arguments); diff --git a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolverTest.php b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolverTest.php index aaa31e27a..a536fecfc 100644 --- a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolverTest.php +++ b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolverTest.php @@ -6,11 +6,10 @@ use Http\Client\HttpAsyncClient; use OpenTelemetry\SDK\Common\Adapter\HttpDiscovery\HttpPlugClientResolver; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Adapter\HttpDiscovery\HttpPlugClientResolver - */ +#[CoversClass(HttpPlugClientResolver::class)] class HttpPlugClientResolverTest extends TestCase { public function test_resolve_http_plug_async_client(): void diff --git a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php index bdec83602..ea81d137c 100644 --- a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php +++ b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php @@ -9,6 +9,8 @@ use Http\Discovery\Strategy\MockClientStrategy; use Mockery; use OpenTelemetry\SDK\Common\Adapter\HttpDiscovery\MessageFactoryResolver; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\ResponseFactoryInterface; @@ -18,9 +20,7 @@ use Psr\Http\Message\UriFactoryInterface; use ReflectionClass; -/** - * @covers \OpenTelemetry\SDK\Common\Adapter\HttpDiscovery\MessageFactoryResolver - */ +#[CoversClass(MessageFactoryResolver::class)] class MessageFactoryResolverTest extends TestCase { private const DEPENDENCIES = [ @@ -37,9 +37,7 @@ public function setUp(): void Psr18ClientDiscovery::prependStrategy(MockClientStrategy::class); } - /** - * @dataProvider provideDependencies - */ + #[DataProvider('provideDependencies')] public function test_resolve(string $method, object $dependency, array $arguments): void { $instance = MessageFactoryResolver::create(...$arguments); diff --git a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/PsrClientResolverTest.php b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/PsrClientResolverTest.php index 48c5c0ba5..aeb0878fe 100644 --- a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/PsrClientResolverTest.php +++ b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/PsrClientResolverTest.php @@ -7,12 +7,11 @@ use Http\Discovery\HttpClientDiscovery; use Http\Discovery\Strategy\MockClientStrategy; use OpenTelemetry\SDK\Common\Adapter\HttpDiscovery\PsrClientResolver; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; -/** - * @covers \OpenTelemetry\SDK\Common\Adapter\HttpDiscovery\PsrClientResolver - */ +#[CoversClass(PsrClientResolver::class)] class PsrClientResolverTest extends TestCase { public function setUp(): void diff --git a/tests/Unit/SDK/Common/Attribute/AttributeValidatorTest.php b/tests/Unit/SDK/Common/Attribute/AttributeValidatorTest.php index ba2389f67..b2ebbe7db 100644 --- a/tests/Unit/SDK/Common/Attribute/AttributeValidatorTest.php +++ b/tests/Unit/SDK/Common/Attribute/AttributeValidatorTest.php @@ -5,11 +5,11 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Attribute; use OpenTelemetry\SDK\Common\Attribute\AttributeValidator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Attribute\AttributeValidator - */ +#[CoversClass(AttributeValidator::class)] class AttributeValidatorTest extends TestCase { private AttributeValidator $validator; @@ -19,9 +19,7 @@ public function setUp(): void $this->validator = new AttributeValidator(); } - /** - * @dataProvider primitiveProvider - */ + #[DataProvider('primitiveProvider')] public function test_validate_primitives($value): void { $this->assertTrue($this->validator->validate($value)); @@ -38,9 +36,7 @@ public static function primitiveProvider(): array ]; } - /** - * @dataProvider nonPrimitiveProvider - */ + #[DataProvider('nonPrimitiveProvider')] public function test_validate_non_primitives($value): void { $this->assertFalse($this->validator->validate($value)); @@ -55,9 +51,7 @@ public static function nonPrimitiveProvider(): array ]; } - /** - * @dataProvider arrayProvider - */ + #[DataProvider('arrayProvider')] public function test_validate_array($value, bool $expected): void { $this->assertSame($expected, $this->validator->validate($value)); diff --git a/tests/Unit/SDK/Common/Attribute/AttributesTest.php b/tests/Unit/SDK/Common/Attribute/AttributesTest.php index 727920749..6fcc627fb 100644 --- a/tests/Unit/SDK/Common/Attribute/AttributesTest.php +++ b/tests/Unit/SDK/Common/Attribute/AttributesTest.php @@ -5,13 +5,14 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Attribute; use OpenTelemetry\SDK\Common\Attribute\Attributes; +use OpenTelemetry\SDK\Common\Attribute\AttributesBuilder; +use OpenTelemetry\SDK\Common\Attribute\AttributesFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Attribute\Attributes - * @covers \OpenTelemetry\SDK\Common\Attribute\AttributesBuilder - * @covers \OpenTelemetry\SDK\Common\Attribute\AttributesFactory - */ +#[CoversClass(Attributes::class)] +#[CoversClass(AttributesBuilder::class)] +#[CoversClass(AttributesFactory::class)] class AttributesTest extends TestCase { public function test_has_attribute(): void diff --git a/tests/Unit/SDK/Common/Attribute/FilteredAttributesTest.php b/tests/Unit/SDK/Common/Attribute/FilteredAttributesTest.php index 4500c8edd..fb5902a20 100644 --- a/tests/Unit/SDK/Common/Attribute/FilteredAttributesTest.php +++ b/tests/Unit/SDK/Common/Attribute/FilteredAttributesTest.php @@ -5,13 +5,13 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Attribute; use OpenTelemetry\SDK\Common\Attribute\Attributes; +use OpenTelemetry\SDK\Common\Attribute\FilteredAttributesBuilder; use OpenTelemetry\SDK\Common\Attribute\FilteredAttributesFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Attribute\FilteredAttributesBuilder - * @covers \OpenTelemetry\SDK\Common\Attribute\FilteredAttributesFactory - */ +#[CoversClass(FilteredAttributesBuilder::class)] +#[CoversClass(FilteredAttributesFactory::class)] class FilteredAttributesTest extends TestCase { public function test_rejected_keys_are_dropped(): void diff --git a/tests/Unit/SDK/Common/Configuration/ConfigurationTest.php b/tests/Unit/SDK/Common/Configuration/ConfigurationTest.php index 994186782..5cdd43f25 100644 --- a/tests/Unit/SDK/Common/Configuration/ConfigurationTest.php +++ b/tests/Unit/SDK/Common/Configuration/ConfigurationTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use Exception; use Generator; use OpenTelemetry\SDK\Common\Configuration\Configuration; @@ -12,15 +11,16 @@ use OpenTelemetry\SDK\Common\Configuration\KnownValues; use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Common\Configuration\VariableTypes; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use UnexpectedValueException; -/** - * @covers \OpenTelemetry\SDK\Common\Configuration\Configuration - */ +#[CoversClass(Configuration::class)] class ConfigurationTest extends TestCase { - use EnvironmentVariables; + use TestState; private const ALLOW_EMPTY = [ VariableTypes::LIST, @@ -97,11 +97,6 @@ class ConfigurationTest extends TestCase 'trace processor' => [Variables::OTEL_PHP_TRACES_PROCESSOR, KnownValues::OTEL_PHP_TRACES_PROCESSOR], ]; - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - public function test_has_variable_from_environment(): void { $this->assertFalse(Configuration::has('FOO_VAR')); @@ -137,8 +132,8 @@ public function test_string_get(): void /** * The SDK MUST interpret an empty value of an environment variable the same way as when the variable is unset - * @dataProvider emptyProvider */ + #[DataProvider('emptyProvider')] public function test_string_uses_default_when_empty_value(?string $input): void { $this->setEnvironmentVariable('OTEL_FOO', $input); @@ -146,9 +141,7 @@ public function test_string_uses_default_when_empty_value(?string $input): void $this->assertSame('bar', $value); } - /** - * @dataProvider emptyProvider - */ + #[DataProvider('emptyProvider')] public function test_int_uses_default_when_empty_value(?string $input): void { $this->setEnvironmentVariable('OTEL_FOO', $input); @@ -156,9 +149,7 @@ public function test_int_uses_default_when_empty_value(?string $input): void $this->assertSame(99, $value); } - /** - * @dataProvider emptyProvider - */ + #[DataProvider('emptyProvider')] public function test_bool_uses_default_when_empty_value(?string $input): void { $this->setEnvironmentVariable('OTEL_FOO', $input); @@ -174,9 +165,7 @@ public static function emptyProvider(): array ]; } - /** - * @dataProvider booleanProvider - */ + #[DataProvider('booleanProvider')] public function test_bool_get(string $input, bool $default, bool $expected): void { $this->setEnvironmentVariable('OTEL_BOOL', $input); @@ -217,9 +206,7 @@ public function test_ratio_get(): void $this->assertSame(0.5, Configuration::getRatio('OTEL_RATIO')); } - /** - * @dataProvider userEnvValueProvider - */ + #[DataProvider('userEnvValueProvider')] public function test_return_user_env_vars(string $methodName, string $variable, string $value, $result): void { $this->setEnvironmentVariable($variable, $value); @@ -230,9 +217,7 @@ public function test_return_user_env_vars(string $methodName, string $variable, ); } - /** - * @dataProvider userValueProvider - */ + #[DataProvider('userValueProvider')] public function test_return_user_default_value(string $methodName, string $variable, $defaultValue, $result): void { $this->assertSame( @@ -241,9 +226,7 @@ public function test_return_user_default_value(string $methodName, string $varia ); } - /** - * @dataProvider libraryDefaultValueProvider - */ + #[DataProvider('libraryDefaultValueProvider')] public function test_return_library_default_value(string $methodName, string $variable, $result): void { $this->assertSame( @@ -252,9 +235,7 @@ public function test_return_library_default_value(string $methodName, string $va ); } - /** - * @dataProvider nonEmptyMethodNameProvider - */ + #[DataProvider('nonEmptyMethodNameProvider')] public function test_no_value_throws_exception(string $methodName): void { $this->expectException(UnexpectedValueException::class); @@ -262,9 +243,7 @@ public function test_no_value_throws_exception(string $methodName): void call_user_func([Configuration::class, $methodName], 'FOO_BAR_' . $methodName); } - /** - * @dataProvider invalidTypeProvider - */ + #[DataProvider('invalidTypeProvider')] public function test_invalid_type_throws_exception(string $methodName, string $variable): void { $this->expectException(UnexpectedValueException::class); @@ -272,9 +251,7 @@ public function test_invalid_type_throws_exception(string $methodName, string $v call_user_func([Configuration::class, $methodName], $variable); } - /** - * @dataProvider noDefaultProvider - */ + #[DataProvider('noDefaultProvider')] public function test_null_result_throws_exception(string $methodName, string $variable): void { $this->expectException(UnexpectedValueException::class); @@ -369,9 +346,7 @@ public function test_default_ratio_for_non_existent_variable(): void $this->assertSame(0.0, $value); } - /** - * @dataProvider knownValuesProvider - */ + #[DataProvider('knownValuesProvider')] public function test_get_known_values(string $varName, array $varValue): void { $this->assertSame( @@ -400,9 +375,7 @@ public function test_retrieve_value_library_default(): void ); } - /** - * @dataProvider typeProvider - */ + #[DataProvider('typeProvider')] public function test_get_type(string $varName, string $type): void { $this->assertSame( @@ -424,9 +397,7 @@ public static function typeProvider(): array ]; } - /** - * @dataProvider defaultValueProvider - */ + #[DataProvider('defaultValueProvider')] public function test_get_default_value_with_empty_var(string $varName, $varValue): void { $this->setEnvironmentVariable($varName, ''); @@ -437,9 +408,7 @@ public function test_get_default_value_with_empty_var(string $varName, $varValue ); } - /** - * @dataProvider defaultValueProvider - */ + #[DataProvider('defaultValueProvider')] public function test_get_default_value(string $varName, $varValue): void { $this->assertSame( @@ -453,9 +422,7 @@ public static function defaultValueProvider(): array return self::DEFAULT_VALUES; } - /** - * @dataProvider nonStringProvider - */ + #[DataProvider('nonStringProvider')] public function test_get_non_string_value(string $method, $value): void { $_SERVER['OTEL_FOO'] = $value; diff --git a/tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php b/tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php index 97fde7e44..8c41cac21 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php +++ b/tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php @@ -6,11 +6,11 @@ use InvalidArgumentException; use OpenTelemetry\SDK\Common\Configuration\Parser\BooleanParser; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Configuration\Parser\BooleanParser - */ +#[CoversClass(BooleanParser::class)] class BooleanParserTest extends TestCase { private const TRUTHY_VALUES = [ @@ -42,9 +42,7 @@ class BooleanParserTest extends TestCase ['0'], ]; - /** - * @dataProvider truthyValueProvider - */ + #[DataProvider('truthyValueProvider')] public function test_truthy_values_return_true(string $value): void { $this->assertTrue( @@ -52,9 +50,7 @@ public function test_truthy_values_return_true(string $value): void ); } - /** - * @dataProvider falsyValueProvider - */ + #[DataProvider('falsyValueProvider')] public function test_falsy_values_return_false(string $value): void { $this->assertFalse( @@ -62,9 +58,7 @@ public function test_falsy_values_return_false(string $value): void ); } - /** - * @dataProvider disallowedBooleanProvider - */ + #[DataProvider('disallowedBooleanProvider')] public function test_disallowed_boolean_type_values_throw_exception(string $value): void { $this->expectException(InvalidArgumentException::class); @@ -76,9 +70,7 @@ public static function disallowedBooleanProvider(): array return self::DISALLOWED_BOOLEAN_VALUES; } - /** - * @dataProvider nonBooleanValueProvider - */ + #[DataProvider('nonBooleanValueProvider')] public function test_non_boolean_values_throw_exception(string $value): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php b/tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php index 17eb7a834..7577ef541 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php +++ b/tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php @@ -4,11 +4,12 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration\Parser; +use OpenTelemetry\SDK\Common\Configuration\Parser\ListParser; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Configuration\Parser\ListParser - */ +#[CoversClass(ListParser::class)] class ListParserTest extends TestCase { private const LIST_VALUES = [ @@ -34,13 +35,11 @@ class ListParserTest extends TestCase ], ]; - /** - * @dataProvider listValueProvider - */ + #[DataProvider('listValueProvider')] public function test_comma_separated_list_returns_array(string $value, array $expected): void { $this->assertSame( - \OpenTelemetry\SDK\Common\Configuration\Parser\ListParser::parse($value), + ListParser::parse($value), $expected ); } diff --git a/tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php b/tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php index 85f8f941f..53f9cc6e8 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php +++ b/tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php @@ -5,11 +5,12 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration\Parser; use InvalidArgumentException; +use OpenTelemetry\SDK\Common\Configuration\Parser\MapParser; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Configuration\Parser\MapParser - */ +#[CoversClass(MapParser::class)] class MapParserTest extends TestCase { private const MAP_VALUES = [ @@ -40,25 +41,21 @@ class MapParserTest extends TestCase 'no equals' => ['foo=bar,barbaz'], ]; - /** - * @dataProvider mapValueProvider - */ + #[DataProvider('mapValueProvider')] public function test_map_values_return_array(string $value, array $expected): void { $this->assertSame( - \OpenTelemetry\SDK\Common\Configuration\Parser\MapParser::parse($value), + MapParser::parse($value), $expected ); } - /** - * @dataProvider invalidValueProvider - */ + #[DataProvider('invalidValueProvider')] public function test_invalid_values_throw_exception(string $value): void { $this->expectException(InvalidArgumentException::class); - \OpenTelemetry\SDK\Common\Configuration\Parser\MapParser::parse($value); + MapParser::parse($value); } public static function mapValueProvider(): array diff --git a/tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php b/tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php index 36300225b..2ce05f292 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php +++ b/tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php @@ -6,12 +6,12 @@ use InvalidArgumentException; use OpenTelemetry\SDK\Common\Configuration\Parser\RatioParser; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use RangeException; -/** - * @covers \OpenTelemetry\SDK\Common\Configuration\Parser\RatioParser - */ +#[CoversClass(RatioParser::class)] class RatioParserTest extends TestCase { private const RATIO_VALUES = [ @@ -30,9 +30,7 @@ class RatioParserTest extends TestCase 'too high' => ['1.1'], ]; - /** - * @dataProvider ratioValueProvider - */ + #[DataProvider('ratioValueProvider')] public function test_ratio_values_return_float(string $value): void { $this->assertIsFloat( @@ -40,9 +38,7 @@ public function test_ratio_values_return_float(string $value): void ); } - /** - * @dataProvider nonNumericValueProvider - */ + #[DataProvider('nonNumericValueProvider')] public function test_non_numeric_values_throw_exception(string $value): void { $this->expectException(InvalidArgumentException::class); @@ -50,9 +46,7 @@ public function test_non_numeric_values_throw_exception(string $value): void RatioParser::parse($value); } - /** - * @dataProvider outOfRangeValueProvider - */ + #[DataProvider('outOfRangeValueProvider')] public function test_out_of_range_values_throw_exception(string $value): void { $this->expectException(RangeException::class); diff --git a/tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php b/tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php index 74d8d5c0f..479a3a8e5 100644 --- a/tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php +++ b/tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php @@ -8,12 +8,14 @@ use OpenTelemetry\SDK\Common\Configuration\Resolver\CompositeResolver; use OpenTelemetry\SDK\Common\Configuration\Resolver\ResolverInterface; use OpenTelemetry\SDK\Common\Configuration\Variables; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Common\Configuration\Resolver\CompositeResolver * @psalm-suppress UndefinedInterfaceMethod */ +#[CoversClass(CompositeResolver::class)] class CompositeResolverTest extends TestCase { private ResolverInterface $one; @@ -71,9 +73,7 @@ public function test_resolve_uses_default_when_not_empty(): void $this->assertSame('foo', $this->resolver->resolve(Variables::OTEL_EXPORTER_OTLP_PROTOCOL, 'foo')); } - /** - * @dataProvider emptyProvider - */ + #[DataProvider('emptyProvider')] public function test_resolve_uses_library_default_when_empty(?string $value): void { $this->one->method('hasVariable')->willReturn(false); diff --git a/tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php b/tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php index 280c21476..3681927a5 100644 --- a/tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php +++ b/tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php @@ -4,16 +4,16 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Configuration\Resolver; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\SDK\Common\Configuration\Resolver\EnvironmentResolver; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Configuration\Resolver\EnvironmentResolver - */ +#[CoversClass(EnvironmentResolver::class)] class EnvironmentResolverTest extends TestCase { - use EnvironmentVariables; + use TestState; private const RAW_VALUES = [ 'string' => ['STRING_VAR', 'foo'], @@ -30,11 +30,6 @@ public function setUp(): void $this->resolver = new EnvironmentResolver(); } - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - public function test_has_variable(): void { $this->assertFalse( @@ -61,9 +56,7 @@ public function test_has_variable_with_injected_value(): void ); } - /** - * @dataProvider rawValueProvider - */ + #[DataProvider('rawValueProvider')] public function test_retrieve_value(string $varName, string $varValue): void { $this->setEnvironmentVariable($varName, $varValue); diff --git a/tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php b/tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php index 33b7489fc..cd008b60d 100644 --- a/tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php +++ b/tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php @@ -6,12 +6,14 @@ use OpenTelemetry\SDK\Common\Configuration\Resolver\PhpIniAccessor; use OpenTelemetry\SDK\Common\Configuration\Resolver\PhpIniResolver; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Common\Configuration\Resolver\PhpIniResolver * @psalm-suppress UndefinedMethod */ +#[CoversClass(PhpIniResolver::class)] class PhpIniResolverTest extends TestCase { private PhpIniAccessor $accessor; @@ -35,9 +37,7 @@ public function test_retrieve_string(): void $this->assertSame('foo', $this->resolver->retrieveValue('OTEL_FOO')); } - /** - * @dataProvider hasVariableProvider - */ + #[DataProvider('hasVariableProvider')] public function test_has_variable($value, bool $expected): void { $this->accessor->method('get')->willReturn($value); diff --git a/tests/Unit/SDK/Common/Dev/Compatibility/UtilTest.php b/tests/Unit/SDK/Common/Dev/Compatibility/UtilTest.php index 6243868a3..e45ed18b6 100644 --- a/tests/Unit/SDK/Common/Dev/Compatibility/UtilTest.php +++ b/tests/Unit/SDK/Common/Dev/Compatibility/UtilTest.php @@ -7,11 +7,11 @@ use Exception; use Generator; use OpenTelemetry\SDK\Common\Dev\Compatibility\Util; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Dev\Compatibility\Util - */ +#[CoversClass(Util::class)] class UtilTest extends TestCase { public function setUp(): void @@ -27,9 +27,7 @@ public function tearDown(): void restore_error_handler(); } - /** - * @dataProvider errorLevelProvider - */ + #[DataProvider('errorLevelProvider')] public function test_set_error_level(int $level): void { Util::setErrorLevel($level); @@ -47,9 +45,7 @@ public function test_set_error_level_throws_exception_on_incorrect_level(): void Util::setErrorLevel(1); } - /** - * @dataProvider errorLevelProvider - */ + #[DataProvider('errorLevelProvider')] public function test_trigger_class_deprecation_notice(int $level): void { Util::setErrorLevel($level); @@ -59,9 +55,7 @@ public function test_trigger_class_deprecation_notice(int $level): void Util::triggerClassDeprecationNotice(Util::class, self::class); } - /** - * @dataProvider errorLevelProvider - */ + #[DataProvider('errorLevelProvider')] public function test_trigger_method_deprecation_notice_without_class(int $level): void { Util::setErrorLevel($level); @@ -71,9 +65,7 @@ public function test_trigger_method_deprecation_notice_without_class(int $level) Util::triggerMethodDeprecationNotice(Util::class, __METHOD__); } - /** - * @dataProvider errorLevelProvider - */ + #[DataProvider('errorLevelProvider')] public function test_trigger_method_deprecation_notice_with_class(int $level): void { Util::setErrorLevel($level); diff --git a/tests/Unit/SDK/Common/Export/Http/PsrTransportTest.php b/tests/Unit/SDK/Common/Export/Http/PsrTransportTest.php index adbc97c1f..744426719 100644 --- a/tests/Unit/SDK/Common/Export/Http/PsrTransportTest.php +++ b/tests/Unit/SDK/Common/Export/Http/PsrTransportTest.php @@ -12,17 +12,17 @@ use function gzencode; use InvalidArgumentException; use Nyholm\Psr7\Response; +use OpenTelemetry\SDK\Common\Export\Http\PsrTransport; use OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; -/** - * @covers \OpenTelemetry\SDK\Common\Export\Http\PsrTransportFactory - * @covers \OpenTelemetry\SDK\Common\Export\Http\PsrTransport - */ +#[CoversClass(PsrTransportFactory::class)] +#[CoversClass(PsrTransport::class)] final class PsrTransportTest extends TestCase { private MockObject $client; diff --git a/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php b/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php index 3f743ccd2..6b018fbd3 100644 --- a/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php +++ b/tests/Unit/SDK/Common/Export/Http/PsrUtilsTest.php @@ -12,13 +12,13 @@ use function gzencode; use Nyholm\Psr7\Response; use OpenTelemetry\SDK\Common\Export\Http\PsrUtils; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function time; use UnexpectedValueException; -/** - * @covers \OpenTelemetry\SDK\Common\Export\Http\PsrUtils - */ +#[CoversClass(PsrUtils::class)] final class PsrUtilsTest extends TestCase { public function test_retry_delay_initial(): void @@ -92,9 +92,7 @@ public function test_decode_stream_unknown_encoding(): void PsrUtils::decode('', ['invalid']); } - /** - * @dataProvider compressionProvider - */ + #[DataProvider('compressionProvider')] public function test_resolve_compression($input, $expected): void { $this->assertSame($expected, PsrUtils::compression($input)); diff --git a/tests/Unit/SDK/Common/Export/Stream/StreamTransportFactoryTest.php b/tests/Unit/SDK/Common/Export/Stream/StreamTransportFactoryTest.php index 00d0eada8..cd6b2cc0a 100644 --- a/tests/Unit/SDK/Common/Export/Stream/StreamTransportFactoryTest.php +++ b/tests/Unit/SDK/Common/Export/Stream/StreamTransportFactoryTest.php @@ -5,11 +5,10 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Export\Stream; use OpenTelemetry\SDK\Common\Export\Stream\StreamTransportFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Export\Stream\StreamTransportFactory - */ +#[CoversClass(StreamTransportFactory::class)] class StreamTransportFactoryTest extends TestCase { public function test_creates_stream(): void diff --git a/tests/Unit/SDK/Common/Future/FutureTest.php b/tests/Unit/SDK/Common/Future/FutureTest.php index 8feb6c9f5..bf9686e1a 100644 --- a/tests/Unit/SDK/Common/Future/FutureTest.php +++ b/tests/Unit/SDK/Common/Future/FutureTest.php @@ -7,12 +7,11 @@ use Exception; use OpenTelemetry\SDK\Common\Future\CompletedFuture; use OpenTelemetry\SDK\Common\Future\ErrorFuture; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Future\CompletedFuture - * @covers \OpenTelemetry\SDK\Common\Future\ErrorFuture - */ +#[CoversClass(CompletedFuture::class)] +#[CoversClass(ErrorFuture::class)] final class FutureTest extends TestCase { public function test_future_await(): void @@ -22,7 +21,7 @@ public function test_future_await(): void $this->assertSame(2, $future->await()); } - public function test_future_await_error(): void + public function test_future_await_error(): never { $future = new ErrorFuture(new Exception()); @@ -41,7 +40,7 @@ public function test_future_map(): void public function test_future_map_throw_is_rethrown_on_wait(): void { $future = new CompletedFuture(2); - $future = $future->map(function () { + $future = $future->map(function (): never { throw new Exception(); }); @@ -52,7 +51,7 @@ public function test_future_map_throw_is_rethrown_on_wait(): void public function test_future_map_error_is_noop(): void { $future = new ErrorFuture(new Exception()); - $future = $future->map(function (): void { + $future = $future->map(function (): never { $this->fail(); }); @@ -72,7 +71,7 @@ public function test_future_catch(): void public function test_future_catch_throw_is_rethrown_on_wait(): void { $future = new ErrorFuture(new Exception()); - $future = $future->catch(function () { + $future = $future->catch(function (): never { throw new Exception('from catch'); }); @@ -84,7 +83,7 @@ public function test_future_catch_throw_is_rethrown_on_wait(): void public function test_future_catch_no_error_is_noop(): void { $future = new CompletedFuture(2); - $future = $future->catch(function (): void { + $future = $future->catch(function (): never { $this->fail(); }); diff --git a/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/BuzzTest.php b/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/BuzzTest.php index 1ea9b2662..9c192c617 100644 --- a/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/BuzzTest.php +++ b/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/BuzzTest.php @@ -6,10 +6,9 @@ use OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\Buzz; use OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\DiscoveryInterface; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @covers \OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\Buzz - */ +#[CoversClass(Buzz::class)] class BuzzTest extends AbstractDiscoveryTestCase { public function getInstance(): DiscoveryInterface diff --git a/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/CurlClientTest.php b/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/CurlClientTest.php index ac4a2e84b..0c9bb72c1 100644 --- a/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/CurlClientTest.php +++ b/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/CurlClientTest.php @@ -6,10 +6,9 @@ use OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\CurlClient; use OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\DiscoveryInterface; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @covers \OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\CurlClient - */ +#[CoversClass(CurlClient::class)] class CurlClientTest extends AbstractDiscoveryTestCase { public function getInstance(): DiscoveryInterface diff --git a/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/GuzzleTest.php b/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/GuzzleTest.php index fbb8f8d15..d2d17742a 100644 --- a/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/GuzzleTest.php +++ b/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/GuzzleTest.php @@ -6,10 +6,9 @@ use OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\DiscoveryInterface; use OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\Guzzle; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @covers \OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\Guzzle - */ +#[CoversClass(Guzzle::class)] class GuzzleTest extends AbstractDiscoveryTestCase { public function getInstance(): DiscoveryInterface diff --git a/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/SymfonyTest.php b/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/SymfonyTest.php index bcb33393a..6cc611712 100644 --- a/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/SymfonyTest.php +++ b/tests/Unit/SDK/Common/Http/Psr/Client/Discovery/SymfonyTest.php @@ -6,10 +6,9 @@ use OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\DiscoveryInterface; use OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\Symfony; +use PHPUnit\Framework\Attributes\CoversClass; -/** - * @covers \OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\Symfony - */ +#[CoversClass(Symfony::class)] class SymfonyTest extends AbstractDiscoveryTestCase { public function getInstance(): DiscoveryInterface diff --git a/tests/Unit/SDK/Common/Http/Psr/Client/DiscoveryTest.php b/tests/Unit/SDK/Common/Http/Psr/Client/DiscoveryTest.php index 4042a58ab..a10b40919 100644 --- a/tests/Unit/SDK/Common/Http/Psr/Client/DiscoveryTest.php +++ b/tests/Unit/SDK/Common/Http/Psr/Client/DiscoveryTest.php @@ -6,18 +6,15 @@ use OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery; use OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery\DiscoveryInterface; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; -/** - * @covers \OpenTelemetry\SDK\Common\Http\Psr\Client\Discovery - */ +#[CoversClass(Discovery::class)] class DiscoveryTest extends TestCase { - public function tearDown(): void - { - Discovery::reset(); - } + use TestState; public function test_discover_with_defaults(): void { diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/MessageFactoryTest.php b/tests/Unit/SDK/Common/Http/Psr/Message/MessageFactoryTest.php index e2a4b8059..6b1ec2a60 100644 --- a/tests/Unit/SDK/Common/Http/Psr/Message/MessageFactoryTest.php +++ b/tests/Unit/SDK/Common/Http/Psr/Message/MessageFactoryTest.php @@ -5,6 +5,7 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Http\Psr\Message; use OpenTelemetry\SDK\Common\Http\Psr\Message\MessageFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; @@ -13,9 +14,7 @@ use Psr\Http\Message\ServerRequestFactoryInterface; use Psr\Http\Message\ServerRequestInterface; -/** - * @covers \OpenTelemetry\SDK\Common\Http\Psr\Message\MessageFactory - */ +#[CoversClass(MessageFactory::class)] class MessageFactoryTest extends TestCase { use UsesRequestFactoryTrait; diff --git a/tests/Unit/SDK/Common/Instrumentation/InstrumentationScopeTest.php b/tests/Unit/SDK/Common/Instrumentation/InstrumentationScopeTest.php index 592cda3d7..eea14837e 100644 --- a/tests/Unit/SDK/Common/Instrumentation/InstrumentationScopeTest.php +++ b/tests/Unit/SDK/Common/Instrumentation/InstrumentationScopeTest.php @@ -5,13 +5,13 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Instrumentation; use OpenTelemetry\SDK\Common\Attribute\Attributes; +use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScope; use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScope - * @covers \OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScopeFactory - */ +#[CoversClass(InstrumentationScope::class)] +#[CoversClass(InstrumentationScopeFactory::class)] class InstrumentationScopeTest extends TestCase { public function test_getters(): void diff --git a/tests/Unit/SDK/Common/Util/ClassConstantAccessorTest.php b/tests/Unit/SDK/Common/Util/ClassConstantAccessorTest.php index 801d25253..1ba0a00d5 100644 --- a/tests/Unit/SDK/Common/Util/ClassConstantAccessorTest.php +++ b/tests/Unit/SDK/Common/Util/ClassConstantAccessorTest.php @@ -6,11 +6,10 @@ use LogicException; use OpenTelemetry\SDK\Common\Util\ClassConstantAccessor; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Common\Util\ClassConstantAccessor - */ +#[CoversClass(ClassConstantAccessor::class)] class ClassConstantAccessorTest extends TestCase { public function test_get_value_return_correct_value(): void diff --git a/tests/Unit/SDK/Common/Util/ShutdownHandlerTest.php b/tests/Unit/SDK/Common/Util/ShutdownHandlerTest.php index 225306a81..dbca3446c 100644 --- a/tests/Unit/SDK/Common/Util/ShutdownHandlerTest.php +++ b/tests/Unit/SDK/Common/Util/ShutdownHandlerTest.php @@ -5,12 +5,11 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Util; use OpenTelemetry\SDK\Common\Util\ShutdownHandler; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use WeakReference; -/** - * @covers \OpenTelemetry\SDK\Common\Util\ShutdownHandler - */ +#[CoversClass(ShutdownHandler::class)] final class ShutdownHandlerTest extends TestCase { public function test_shutdown_handler_does_not_keep_reference_to_shutdown_function_this(): void @@ -21,7 +20,7 @@ public function foo(): void } }; - ShutdownHandler::register([$object, 'foo']); + ShutdownHandler::register($object->foo(...)); $reference = WeakReference::create($object); $object = null; diff --git a/tests/Unit/SDK/Common/Util/WeakenTest.php b/tests/Unit/SDK/Common/Util/WeakenTest.php index 5c8ee1cb7..58a2cc72e 100644 --- a/tests/Unit/SDK/Common/Util/WeakenTest.php +++ b/tests/Unit/SDK/Common/Util/WeakenTest.php @@ -7,13 +7,11 @@ use Closure; use function OpenTelemetry\SDK\Common\Util\closure; use function OpenTelemetry\SDK\Common\Util\weaken; +use PHPUnit\Framework\Attributes\CoversFunction; use PHPUnit\Framework\TestCase; use WeakReference; -/** - * @covers \OpenTelemetry\SDK\Common\Util\closure - * @covers \OpenTelemetry\SDK\Common\Util\weaken - */ +#[CoversFunction('\OpenTelemetry\SDK\Common\Util\weaken')] final class WeakenTest extends TestCase { public function test_weakened_closure_calls_original_closure(): void @@ -25,7 +23,7 @@ public function foo(): int } }; - $weakened = weaken(closure([$object, 'foo'])); + $weakened = weaken(closure($object->foo(...))); $this->assertSame(5, $weakened()); } @@ -39,7 +37,7 @@ public function foo(): int } }; - $weakened = weaken(closure([$object, 'foo'])); + $weakened = weaken(closure($object->foo(...))); $reference = WeakReference::create($object); $object = null; @@ -57,7 +55,7 @@ public function foo(): int } }; - weaken(closure([$object, 'foo']), $target); + weaken(closure($object->foo(...)), $target); $this->assertSame($object, $target); } @@ -80,7 +78,7 @@ class A { public function closure(): \Closure { - return Closure::fromCallable([$this, 'private']); + return Closure::fromCallable($this->private(...)); } private function private(): int { diff --git a/tests/Unit/SDK/FactoryRegistryTest.php b/tests/Unit/SDK/FactoryRegistryTest.php index 698f98a97..d58842375 100644 --- a/tests/Unit/SDK/FactoryRegistryTest.php +++ b/tests/Unit/SDK/FactoryRegistryTest.php @@ -10,17 +10,15 @@ use OpenTelemetry\SDK\Metrics\MetricExporterFactoryInterface; use OpenTelemetry\SDK\Registry; use OpenTelemetry\SDK\Trace\SpanExporter\SpanExporterFactoryInterface; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use TypeError; -/** - * @covers \OpenTelemetry\SDK\Registry - */ +#[CoversClass(Registry::class)] class FactoryRegistryTest extends TestCase { - /** - * @dataProvider transportProtocolsProvider - */ + #[DataProvider('transportProtocolsProvider')] public function test_default_transport_factories(string $name): void { $factory = Registry::transportFactory($name); @@ -39,9 +37,7 @@ public static function transportProtocolsProvider(): array ]; } - /** - * @dataProvider spanExporterProvider - */ + #[DataProvider('spanExporterProvider')] public function test_default_span_exporter_factories(string $name): void { $factory = Registry::spanExporterFactory($name); @@ -58,9 +54,7 @@ public static function spanExporterProvider(): array ]; } - /** - * @dataProvider metricExporterProvider - */ + #[DataProvider('metricExporterProvider')] public function test_default_metric_exporter_factories(string $name): void { $factory = Registry::metricExporterFactory($name); @@ -76,9 +70,7 @@ public static function metricExporterProvider(): array ]; } - /** - * @dataProvider logRecordExporterProvider - */ + #[DataProvider('logRecordExporterProvider')] public function test_default_log_record_exporter_factories(string $name): void { $factory = Registry::logRecordExporterFactory($name); @@ -93,9 +85,7 @@ public static function logRecordExporterProvider(): array ]; } - /** - * @dataProvider textMapPropagator - */ + #[DataProvider('textMapPropagator')] public function test_default_text_map_propagator(string $name): void { $propagator = Registry::textMapPropagator($name); @@ -116,36 +106,28 @@ public static function textMapPropagator(): array ]; } - /** - * @dataProvider invalidFactoryProvider - */ + #[DataProvider('invalidFactoryProvider')] public function test_register_invalid_transport_factory($factory): void { $this->expectException(TypeError::class); Registry::registerTransportFactory('http', $factory, true); } - /** - * @dataProvider invalidFactoryProvider - */ + #[DataProvider('invalidFactoryProvider')] public function test_register_invalid_span_exporter_factory($factory): void { $this->expectException(TypeError::class); Registry::registerSpanExporterFactory('foo', $factory, true); } - /** - * @dataProvider invalidFactoryProvider - */ + #[DataProvider('invalidFactoryProvider')] public function test_register_invalid_metric_exporter_factory($factory): void { $this->expectException(TypeError::class); Registry::registerMetricExporterFactory('foo', $factory, true); } - /** - * @dataProvider invalidFactoryProvider - */ + #[DataProvider('invalidFactoryProvider')] public function test_register_invalid_log_record_exporter_factory($factory): void { $this->expectException(TypeError::class); diff --git a/tests/Unit/SDK/Logs/EventLoggerProviderFactoryTest.php b/tests/Unit/SDK/Logs/EventLoggerProviderFactoryTest.php index dc7ae94bb..321a13481 100644 --- a/tests/Unit/SDK/Logs/EventLoggerProviderFactoryTest.php +++ b/tests/Unit/SDK/Logs/EventLoggerProviderFactoryTest.php @@ -4,30 +4,25 @@ namespace OpenTelemetry\Tests\Unit\SDK\Logs; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Logs\LoggerProviderInterface; use OpenTelemetry\API\Logs\NoopEventLoggerProvider; use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Logs\EventLoggerProvider; use OpenTelemetry\SDK\Logs\EventLoggerProviderFactory; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\EventLoggerProviderFactory - */ +#[CoversClass(EventLoggerProviderFactory::class)] class EventLoggerProviderFactoryTest extends TestCase { - use EnvironmentVariables; - - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } + use TestState; /** - * @dataProvider createProvider * @psalm-suppress ArgumentTypeCoercion */ + #[DataProvider('createProvider')] public function test_create(string $disabled, string $expected): void { $this->setEnvironmentVariable(Variables::OTEL_SDK_DISABLED, $disabled); diff --git a/tests/Unit/SDK/Logs/EventLoggerProviderTest.php b/tests/Unit/SDK/Logs/EventLoggerProviderTest.php index a63b7e368..03c51793b 100644 --- a/tests/Unit/SDK/Logs/EventLoggerProviderTest.php +++ b/tests/Unit/SDK/Logs/EventLoggerProviderTest.php @@ -7,11 +7,10 @@ use OpenTelemetry\API\Logs\LoggerInterface; use OpenTelemetry\API\Logs\LoggerProviderInterface; use OpenTelemetry\SDK\Logs\EventLoggerProvider; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\EventLoggerProvider - */ +#[CoversClass(EventLoggerProvider::class)] class EventLoggerProviderTest extends TestCase { public function test_emit(): void diff --git a/tests/Unit/SDK/Logs/EventLoggerTest.php b/tests/Unit/SDK/Logs/EventLoggerTest.php index ea9dbac77..fffe91f04 100644 --- a/tests/Unit/SDK/Logs/EventLoggerTest.php +++ b/tests/Unit/SDK/Logs/EventLoggerTest.php @@ -11,13 +11,13 @@ use OpenTelemetry\API\Logs\LogRecord; use OpenTelemetry\API\Logs\Severity; use OpenTelemetry\Context\Context; +use OpenTelemetry\SDK\Logs\EventLogger; use OpenTelemetry\SDK\Logs\EventLoggerProvider; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\EventLogger - */ +#[CoversClass(EventLogger::class)] class EventLoggerTest extends TestCase { private LoggerInterface&MockObject $logger; @@ -34,11 +34,6 @@ public function setUp(): void $this->eventLoggerProvider = new EventLoggerProvider($loggerProvider); } - public function tearDown(): void - { - Clock::reset(); - } - public function test_emit(): void { $this->logger->expects($this->once())->method('emit')->with($this->callback(function (LogRecord $logRecord) { diff --git a/tests/Unit/SDK/Logs/Exporter/ConsoleExporterFactoryTest.php b/tests/Unit/SDK/Logs/Exporter/ConsoleExporterFactoryTest.php index b193d6082..0d8625132 100644 --- a/tests/Unit/SDK/Logs/Exporter/ConsoleExporterFactoryTest.php +++ b/tests/Unit/SDK/Logs/Exporter/ConsoleExporterFactoryTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\SDK\Logs\Exporter\ConsoleExporter; use OpenTelemetry\SDK\Logs\Exporter\ConsoleExporterFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\Exporter\ConsoleExporterFactory - */ +#[CoversClass(ConsoleExporterFactory::class)] class ConsoleExporterFactoryTest extends TestCase { public function test_create(): void diff --git a/tests/Unit/SDK/Logs/Exporter/ConsoleExporterTest.php b/tests/Unit/SDK/Logs/Exporter/ConsoleExporterTest.php index 0c580dc0e..0ccb2566a 100644 --- a/tests/Unit/SDK/Logs/Exporter/ConsoleExporterTest.php +++ b/tests/Unit/SDK/Logs/Exporter/ConsoleExporterTest.php @@ -10,12 +10,13 @@ use OpenTelemetry\SDK\Logs\Exporter\ConsoleExporter; use OpenTelemetry\SDK\Logs\LoggerSharedState; use OpenTelemetry\SDK\Logs\ReadableLogRecord; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Logs\Exporter\ConsoleExporter * @psalm-suppress UndefinedInterfaceMethod */ +#[CoversClass(ConsoleExporter::class)] class ConsoleExporterTest extends TestCase { private TransportInterface $transport; diff --git a/tests/Unit/SDK/Logs/Exporter/InMemoryExporterFactoryTest.php b/tests/Unit/SDK/Logs/Exporter/InMemoryExporterFactoryTest.php index 11813f5fe..6150049bb 100644 --- a/tests/Unit/SDK/Logs/Exporter/InMemoryExporterFactoryTest.php +++ b/tests/Unit/SDK/Logs/Exporter/InMemoryExporterFactoryTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\SDK\Logs\Exporter\InMemoryExporterFactory; use OpenTelemetry\SDK\Logs\LogRecordExporterInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\Exporter\InMemoryExporterFactory - */ +#[CoversClass(InMemoryExporterFactory::class)] class InMemoryExporterFactoryTest extends TestCase { public function test_create(): void diff --git a/tests/Unit/SDK/Logs/Exporter/InMemoryExporterTest.php b/tests/Unit/SDK/Logs/Exporter/InMemoryExporterTest.php index 01dca0051..dfb2162f9 100644 --- a/tests/Unit/SDK/Logs/Exporter/InMemoryExporterTest.php +++ b/tests/Unit/SDK/Logs/Exporter/InMemoryExporterTest.php @@ -9,12 +9,13 @@ use OpenTelemetry\SDK\Logs\Exporter\InMemoryExporter; use OpenTelemetry\SDK\Logs\LoggerSharedState; use OpenTelemetry\SDK\Logs\ReadableLogRecord; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Logs\Exporter\InMemoryExporter * @psalm-suppress UndefinedInterfaceMethod */ +#[CoversClass(InMemoryExporter::class)] class InMemoryExporterTest extends TestCase { public function test_export(): void diff --git a/tests/Unit/SDK/Logs/Exporter/NoopExporterTest.php b/tests/Unit/SDK/Logs/Exporter/NoopExporterTest.php index 70701efe7..dee1b6f97 100644 --- a/tests/Unit/SDK/Logs/Exporter/NoopExporterTest.php +++ b/tests/Unit/SDK/Logs/Exporter/NoopExporterTest.php @@ -5,11 +5,10 @@ namespace OpenTelemetry\Tests\Unit\SDK\Logs\Exporter; use OpenTelemetry\SDK\Logs\Exporter\NoopExporter; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\Exporter\NoopExporter - */ +#[CoversClass(NoopExporter::class)] class NoopExporterTest extends TestCase { private NoopExporter $exporter; diff --git a/tests/Unit/SDK/Logs/ExporterFactoryTest.php b/tests/Unit/SDK/Logs/ExporterFactoryTest.php index f65417764..59a10cb5f 100644 --- a/tests/Unit/SDK/Logs/ExporterFactoryTest.php +++ b/tests/Unit/SDK/Logs/ExporterFactoryTest.php @@ -4,28 +4,23 @@ namespace OpenTelemetry\Tests\Unit\SDK\Logs; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\SDK\Logs\Exporter\ConsoleExporter; use OpenTelemetry\SDK\Logs\Exporter\NoopExporter; use OpenTelemetry\SDK\Logs\ExporterFactory; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\ExporterFactory - */ +#[CoversClass(ExporterFactory::class)] class ExporterFactoryTest extends TestCase { - use EnvironmentVariables; - - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } + use TestState; /** - * @dataProvider exporterProvider * @param class-string $expected */ + #[DataProvider('exporterProvider')] public function test_create(string $name, string $expected): void { $this->setEnvironmentVariable('OTEL_LOGS_EXPORTER', $name); diff --git a/tests/Unit/SDK/Logs/LogRecordLimitsBuilderTest.php b/tests/Unit/SDK/Logs/LogRecordLimitsBuilderTest.php index e9dd61600..af4ce0842 100644 --- a/tests/Unit/SDK/Logs/LogRecordLimitsBuilderTest.php +++ b/tests/Unit/SDK/Logs/LogRecordLimitsBuilderTest.php @@ -4,13 +4,13 @@ namespace OpenTelemetry\Tests\Unit\SDK\Logs; +use OpenTelemetry\SDK\Logs\LogRecordLimits; use OpenTelemetry\SDK\Logs\LogRecordLimitsBuilder; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\LogRecordLimitsBuilder - * @covers \OpenTelemetry\SDK\Logs\LogRecordLimits - */ +#[CoversClass(LogRecordLimitsBuilder::class)] +#[CoversClass(LogRecordLimits::class)] class LogRecordLimitsBuilderTest extends TestCase { public function test_builder(): void diff --git a/tests/Unit/SDK/Logs/LogRecordProcessorFactoryTest.php b/tests/Unit/SDK/Logs/LogRecordProcessorFactoryTest.php index 3154066fd..a9c372aba 100644 --- a/tests/Unit/SDK/Logs/LogRecordProcessorFactoryTest.php +++ b/tests/Unit/SDK/Logs/LogRecordProcessorFactoryTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Unit\SDK\Logs; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Logs\LogRecordExporterInterface; use OpenTelemetry\SDK\Logs\LogRecordProcessorFactory; @@ -12,25 +11,21 @@ use OpenTelemetry\SDK\Logs\Processor\MultiLogRecordProcessor; use OpenTelemetry\SDK\Logs\Processor\NoopLogRecordProcessor; use OpenTelemetry\SDK\Logs\Processor\SimpleLogRecordProcessor; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use ReflectionClass; -/** - * @covers \OpenTelemetry\SDK\Logs\LogRecordProcessorFactory - */ +#[CoversClass(LogRecordProcessorFactory::class)] class LogRecordProcessorFactoryTest extends TestCase { - use EnvironmentVariables; - - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } + use TestState; /** - * @dataProvider exporterProvider * @param class-string $expected */ + #[DataProvider('exporterProvider')] public function test_create(string $name, string $expected): void { $exporter = $this->createMock(LogRecordExporterInterface::class); diff --git a/tests/Unit/SDK/Logs/LoggerProviderBuilderTest.php b/tests/Unit/SDK/Logs/LoggerProviderBuilderTest.php index e9c55d4b2..e958f8c32 100644 --- a/tests/Unit/SDK/Logs/LoggerProviderBuilderTest.php +++ b/tests/Unit/SDK/Logs/LoggerProviderBuilderTest.php @@ -5,14 +5,14 @@ namespace OpenTelemetry\Tests\Unit\SDK\Logs; use OpenTelemetry\SDK\Logs\LoggerProvider; +use OpenTelemetry\SDK\Logs\LoggerProviderBuilder; use OpenTelemetry\SDK\Logs\LoggerProviderInterface; use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface; use OpenTelemetry\SDK\Resource\ResourceInfo; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\LoggerProviderBuilder - */ +#[CoversClass(LoggerProviderBuilder::class)] class LoggerProviderBuilderTest extends TestCase { public function test_builder(): void diff --git a/tests/Unit/SDK/Logs/LoggerProviderFactoryTest.php b/tests/Unit/SDK/Logs/LoggerProviderFactoryTest.php index d6fb342e1..42f91d93e 100644 --- a/tests/Unit/SDK/Logs/LoggerProviderFactoryTest.php +++ b/tests/Unit/SDK/Logs/LoggerProviderFactoryTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\API\Logs\LoggerProviderInterface; use OpenTelemetry\SDK\Logs\LoggerProviderFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\LoggerProviderFactory - */ +#[CoversClass(LoggerProviderFactory::class)] class LoggerProviderFactoryTest extends TestCase { public function test_create(): void diff --git a/tests/Unit/SDK/Logs/LoggerProviderTest.php b/tests/Unit/SDK/Logs/LoggerProviderTest.php index 5cdc1fc5b..08a7fda92 100644 --- a/tests/Unit/SDK/Logs/LoggerProviderTest.php +++ b/tests/Unit/SDK/Logs/LoggerProviderTest.php @@ -10,14 +10,15 @@ use OpenTelemetry\SDK\Logs\LoggerProvider; use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface; use OpenTelemetry\SDK\Resource\ResourceInfo; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Logs\LoggerProvider * @psalm-suppress UndefinedInterfaceMethod * @psalm-suppress PossiblyUndefinedMethod */ +#[CoversClass(LoggerProvider::class)] class LoggerProviderTest extends TestCase { /** @var LogRecordProcessorInterface&MockObject $processor */ diff --git a/tests/Unit/SDK/Logs/LoggerSharedStateTest.php b/tests/Unit/SDK/Logs/LoggerSharedStateTest.php index 73192bd5a..4e36f0cbe 100644 --- a/tests/Unit/SDK/Logs/LoggerSharedStateTest.php +++ b/tests/Unit/SDK/Logs/LoggerSharedStateTest.php @@ -8,12 +8,13 @@ use OpenTelemetry\SDK\Logs\LogRecordLimits; use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface; use OpenTelemetry\SDK\Resource\ResourceInfo; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Logs\LoggerSharedState * @psalm-suppress UndefinedInterfaceMethod */ +#[CoversClass(LoggerSharedState::class)] class LoggerSharedStateTest extends TestCase { private ResourceInfo $resource; diff --git a/tests/Unit/SDK/Logs/LoggerTest.php b/tests/Unit/SDK/Logs/LoggerTest.php index 50be2f38b..362b73653 100644 --- a/tests/Unit/SDK/Logs/LoggerTest.php +++ b/tests/Unit/SDK/Logs/LoggerTest.php @@ -12,12 +12,13 @@ use OpenTelemetry\SDK\Logs\LoggerSharedState; use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface; use OpenTelemetry\SDK\Logs\ReadWriteLogRecord; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Logs\Logger * @psalm-suppress UndefinedInterfaceMethod */ +#[CoversClass(Logger::class)] class LoggerTest extends TestCase { private LoggerSharedState $sharedState; diff --git a/tests/Unit/SDK/Logs/NoopLoggerProviderTest.php b/tests/Unit/SDK/Logs/NoopLoggerProviderTest.php index edcf8ea01..8b346d384 100644 --- a/tests/Unit/SDK/Logs/NoopLoggerProviderTest.php +++ b/tests/Unit/SDK/Logs/NoopLoggerProviderTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\API\Logs\NoopLogger; use OpenTelemetry\SDK\Logs\NoopLoggerProvider; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\NoopLoggerProvider - */ +#[CoversClass(NoopLoggerProvider::class)] class NoopLoggerProviderTest extends TestCase { public function test_get_instance(): void diff --git a/tests/Unit/SDK/Logs/Processor/BatchLogRecordProcessorTest.php b/tests/Unit/SDK/Logs/Processor/BatchLogRecordProcessorTest.php index 57e74c4c8..e0416f8e4 100644 --- a/tests/Unit/SDK/Logs/Processor/BatchLogRecordProcessorTest.php +++ b/tests/Unit/SDK/Logs/Processor/BatchLogRecordProcessorTest.php @@ -27,12 +27,12 @@ use OpenTelemetry\SDK\Metrics\StalenessHandler\ImmediateStalenessHandlerFactory; use OpenTelemetry\SDK\Metrics\View\CriteriaViewRegistry; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LogLevel; -/** - * @covers \OpenTelemetry\SDK\Logs\Processor\BatchLogRecordProcessor - */ +#[CoversClass(BatchLogRecordProcessor::class)] class BatchLogRecordProcessorTest extends MockeryTestCase { private TestClock $testClock; @@ -48,12 +48,6 @@ protected function setUp(): void Clock::setDefault($this->testClock); } - protected function tearDown(): void - { - Clock::reset(); - Logging::reset(); - } - public function test_export_batch_size_met(): void { $batchSize = 3; @@ -83,9 +77,7 @@ public function test_export_batch_size_met(): void } } - /** - * @dataProvider scheduledDelayProvider - */ + #[DataProvider('scheduledDelayProvider')] public function test_export_scheduled_delay(int $exportDelay, int $advanceByNano, bool $expectedFlush): void { $batchSize = 2; @@ -386,7 +378,7 @@ public function test_throwing_exporter_flush_rethrows_in_original_caller(): void { $exporter = $this->createMock(LogRecordExporterInterface::class); $processor = null; - $exporter->method('forceFlush')->willReturnCallback(function () use (&$processor) { + $exporter->method('forceFlush')->willReturnCallback(function () use (&$processor): never { /** @var LogRecordProcessorInterface $processor */ $record = $this->createMock(ReadWriteLogRecord::class); $processor->onEmit($record); diff --git a/tests/Unit/SDK/Logs/Processor/MultiLogRecordProcessorTest.php b/tests/Unit/SDK/Logs/Processor/MultiLogRecordProcessorTest.php index bb6be732a..21d1ae535 100644 --- a/tests/Unit/SDK/Logs/Processor/MultiLogRecordProcessorTest.php +++ b/tests/Unit/SDK/Logs/Processor/MultiLogRecordProcessorTest.php @@ -10,10 +10,10 @@ use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface; use OpenTelemetry\SDK\Logs\Processor\MultiLogRecordProcessor; use OpenTelemetry\SDK\Logs\ReadWriteLogRecord; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; -/** - * @covers \OpenTelemetry\SDK\Logs\Processor\MultiLogRecordProcessor - */ +#[CoversClass(MultiLogRecordProcessor::class)] class MultiLogRecordProcessorTest extends MockeryTestCase { private array $processors; @@ -28,9 +28,7 @@ public function setUp(): void $this->multi = new MultiLogRecordProcessor($this->processors); } - /** - * @dataProvider methodProvider - */ + #[DataProvider('methodProvider')] public function test_method_calls_method_on_all_processors(string $method, object $param): void { //$record = $this->createMock(ReadWriteLogRecord::class); diff --git a/tests/Unit/SDK/Logs/Processor/NoopLogRecordProcessorTest.php b/tests/Unit/SDK/Logs/Processor/NoopLogRecordProcessorTest.php index 2a6f94d1c..9418dd094 100644 --- a/tests/Unit/SDK/Logs/Processor/NoopLogRecordProcessorTest.php +++ b/tests/Unit/SDK/Logs/Processor/NoopLogRecordProcessorTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\SDK\Logs\LogRecordProcessorInterface; use OpenTelemetry\SDK\Logs\Processor\NoopLogRecordProcessor; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\Processor\NoopLogRecordProcessor - */ +#[CoversClass(NoopLogRecordProcessor::class)] class NoopLogRecordProcessorTest extends TestCase { public function test_get_instance(): void diff --git a/tests/Unit/SDK/Logs/Processor/SimpleLogRecordProcessorTest.php b/tests/Unit/SDK/Logs/Processor/SimpleLogRecordProcessorTest.php index fa3866418..d490b4dc8 100644 --- a/tests/Unit/SDK/Logs/Processor/SimpleLogRecordProcessorTest.php +++ b/tests/Unit/SDK/Logs/Processor/SimpleLogRecordProcessorTest.php @@ -7,14 +7,15 @@ use OpenTelemetry\SDK\Logs\LogRecordExporterInterface; use OpenTelemetry\SDK\Logs\Processor\SimpleLogRecordProcessor; use OpenTelemetry\SDK\Logs\ReadWriteLogRecord; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** - * @covers \OpenTelemetry\SDK\Logs\Processor\SimpleLogRecordProcessor * @psalm-suppress UndefinedInterfaceMethod * @psalm-suppress PossiblyUndefinedMethod */ +#[CoversClass(SimpleLogRecordProcessor::class)] class SimpleLogRecordProcessorTest extends TestCase { private SimpleLogRecordProcessor $processor; diff --git a/tests/Unit/SDK/Logs/ReadableLogRecordTest.php b/tests/Unit/SDK/Logs/ReadableLogRecordTest.php index 1c946278c..dab9bffa8 100644 --- a/tests/Unit/SDK/Logs/ReadableLogRecordTest.php +++ b/tests/Unit/SDK/Logs/ReadableLogRecordTest.php @@ -12,11 +12,11 @@ use OpenTelemetry\SDK\Logs\LogRecordLimits; use OpenTelemetry\SDK\Logs\ReadableLogRecord; use OpenTelemetry\SDK\Resource\ResourceInfo; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Logs\ReadableLogRecord - */ +#[CoversClass(ReadableLogRecord::class)] class ReadableLogRecordTest extends TestCase { private InstrumentationScopeInterface $scope; @@ -58,9 +58,7 @@ public function test_getters(): void $this->assertEquals(['foo' => 'bar'], $record->getAttributes()->toArray()); } - /** - * @group logs-compliance - */ + #[Group('logs-compliance')] public function test_log_record_can_accept_complex_attributes(): void { $homogeneous = [1,2,3,4,5]; diff --git a/tests/Unit/SDK/Logs/SimplePsrFileLoggerTest.php b/tests/Unit/SDK/Logs/SimplePsrFileLoggerTest.php index 59b1113a0..57fab345a 100644 --- a/tests/Unit/SDK/Logs/SimplePsrFileLoggerTest.php +++ b/tests/Unit/SDK/Logs/SimplePsrFileLoggerTest.php @@ -7,13 +7,13 @@ use OpenTelemetry\SDK\Logs\SimplePsrFileLogger; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamDirectory; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Log\InvalidArgumentException; use Psr\Log\LogLevel; -/** - * @covers \OpenTelemetry\SDK\Logs\SimplePsrFileLogger - */ +#[CoversClass(SimplePsrFileLogger::class)] class SimplePsrFileLoggerTest extends TestCase { private const ROOT_DIR = 'var'; @@ -41,9 +41,7 @@ public function setUp(): void ); } - /** - * @dataProvider logLevelProvider - */ + #[DataProvider('logLevelProvider')] public function test_log(string $logLevel): void { $this->assertFalse($this->root->hasChild(self::LOG_FILE)); diff --git a/tests/Unit/SDK/Metrics/Aggregation/ExplicitBucketHistogramAggregationTest.php b/tests/Unit/SDK/Metrics/Aggregation/ExplicitBucketHistogramAggregationTest.php index bf5a6e12e..813be5c64 100644 --- a/tests/Unit/SDK/Metrics/Aggregation/ExplicitBucketHistogramAggregationTest.php +++ b/tests/Unit/SDK/Metrics/Aggregation/ExplicitBucketHistogramAggregationTest.php @@ -12,12 +12,11 @@ use OpenTelemetry\SDK\Metrics\Data\Histogram; use OpenTelemetry\SDK\Metrics\Data\HistogramDataPoint; use OpenTelemetry\SDK\Metrics\Data\Temporality; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Aggregation\ExplicitBucketHistogramAggregation - * @covers \OpenTelemetry\SDK\Metrics\Aggregation\ExplicitBucketHistogramSummary - */ +#[CoversClass(ExplicitBucketHistogramAggregation::class)] +#[CoversClass(ExplicitBucketHistogramSummary::class)] final class ExplicitBucketHistogramAggregationTest extends TestCase { public function test_initialize(): void diff --git a/tests/Unit/SDK/Metrics/Aggregation/LastValueAggregationTest.php b/tests/Unit/SDK/Metrics/Aggregation/LastValueAggregationTest.php index f11b7dd81..21ea3a9a9 100644 --- a/tests/Unit/SDK/Metrics/Aggregation/LastValueAggregationTest.php +++ b/tests/Unit/SDK/Metrics/Aggregation/LastValueAggregationTest.php @@ -11,12 +11,11 @@ use OpenTelemetry\SDK\Metrics\Data\Gauge; use OpenTelemetry\SDK\Metrics\Data\NumberDataPoint; use OpenTelemetry\SDK\Metrics\Data\Temporality; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Aggregation\LastValueAggregation - * @covers \OpenTelemetry\SDK\Metrics\Aggregation\LastValueSummary - */ +#[CoversClass(LastValueAggregation::class)] +#[CoversClass(LastValueSummary::class)] final class LastValueAggregationTest extends TestCase { public function test_initialize(): void diff --git a/tests/Unit/SDK/Metrics/Aggregation/SumAggregationTest.php b/tests/Unit/SDK/Metrics/Aggregation/SumAggregationTest.php index 993ad14d1..e339e999e 100644 --- a/tests/Unit/SDK/Metrics/Aggregation/SumAggregationTest.php +++ b/tests/Unit/SDK/Metrics/Aggregation/SumAggregationTest.php @@ -11,12 +11,11 @@ use OpenTelemetry\SDK\Metrics\Data\NumberDataPoint; use OpenTelemetry\SDK\Metrics\Data\Sum; use OpenTelemetry\SDK\Metrics\Data\Temporality; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Aggregation\SumAggregation - * @covers \OpenTelemetry\SDK\Metrics\Aggregation\SumSummary - */ +#[CoversClass(SumAggregation::class)] +#[CoversClass(SumSummary::class)] final class SumAggregationTest extends TestCase { public function test_initialize(): void diff --git a/tests/Unit/SDK/Metrics/AttributeProcessor/FilteredAttributeProcessorTest.php b/tests/Unit/SDK/Metrics/AttributeProcessor/FilteredAttributeProcessorTest.php index 524d23ad6..1588bd171 100644 --- a/tests/Unit/SDK/Metrics/AttributeProcessor/FilteredAttributeProcessorTest.php +++ b/tests/Unit/SDK/Metrics/AttributeProcessor/FilteredAttributeProcessorTest.php @@ -6,19 +6,18 @@ use OpenTelemetry\Context\Context; use OpenTelemetry\SDK\Common\Attribute\Attributes; -use OpenTelemetry\SDK\Metrics\AttributeProcessor; +use OpenTelemetry\SDK\Metrics\AttributeProcessor\FilteredAttributeProcessor; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\AttributeProcessor\FilteredAttributeProcessor - */ +#[CoversClass(FilteredAttributeProcessor::class)] final class FilteredAttributeProcessorTest extends TestCase { public function test_attribute_processor_test(): void { $this->assertEquals( ['foo' => 3], - (new AttributeProcessor\FilteredAttributeProcessor(['foo'])) + (new FilteredAttributeProcessor(['foo'])) ->process(Attributes::create(['foo' => 3, 'bar' => 5]), Context::getRoot()) ->toArray(), ); diff --git a/tests/Unit/SDK/Metrics/AttributeProcessor/IdentityAttributeProcessorTest.php b/tests/Unit/SDK/Metrics/AttributeProcessor/IdentityAttributeProcessorTest.php index f526e503b..78f633979 100644 --- a/tests/Unit/SDK/Metrics/AttributeProcessor/IdentityAttributeProcessorTest.php +++ b/tests/Unit/SDK/Metrics/AttributeProcessor/IdentityAttributeProcessorTest.php @@ -6,19 +6,18 @@ use OpenTelemetry\Context\Context; use OpenTelemetry\SDK\Common\Attribute\Attributes; -use OpenTelemetry\SDK\Metrics\AttributeProcessor; +use OpenTelemetry\SDK\Metrics\AttributeProcessor\IdentityAttributeProcessor; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\AttributeProcessor\IdentityAttributeProcessor - */ +#[CoversClass(IdentityAttributeProcessor::class)] final class IdentityAttributeProcessorTest extends TestCase { public function test_attribute_processor_test(): void { $this->assertEquals( ['foo' => 3, 'bar' => 5], - (new AttributeProcessor\IdentityAttributeProcessor()) + (new IdentityAttributeProcessor()) ->process(Attributes::create(['foo' => 3, 'bar' => 5]), Context::getRoot()) ->toArray(), ); diff --git a/tests/Unit/SDK/Metrics/Exemplar/BucketStorageTest.php b/tests/Unit/SDK/Metrics/Exemplar/BucketStorageTest.php index 47edfa821..c04770c2d 100644 --- a/tests/Unit/SDK/Metrics/Exemplar/BucketStorageTest.php +++ b/tests/Unit/SDK/Metrics/Exemplar/BucketStorageTest.php @@ -10,11 +10,10 @@ use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Metrics\Data\Exemplar; use OpenTelemetry\SDK\Metrics\Exemplar\BucketStorage; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Exemplar\BucketStorage - */ +#[CoversClass(BucketStorage::class)] final class BucketStorageTest extends TestCase { public function test_empty_storage_returns_no_exemplars(): void diff --git a/tests/Unit/SDK/Metrics/Exemplar/FilteredReservoirTest.php b/tests/Unit/SDK/Metrics/Exemplar/FilteredReservoirTest.php index b2df2fa51..1cdc832eb 100644 --- a/tests/Unit/SDK/Metrics/Exemplar/FilteredReservoirTest.php +++ b/tests/Unit/SDK/Metrics/Exemplar/FilteredReservoirTest.php @@ -15,17 +15,16 @@ use OpenTelemetry\SDK\Metrics\Exemplar\ExemplarFilter\WithSampledTraceExemplarFilter; use OpenTelemetry\SDK\Metrics\Exemplar\FilteredReservoir; use OpenTelemetry\SDK\Metrics\Exemplar\FixedSizeReservoir; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Exemplar\FilteredReservoir - */ +#[CoversClass(FilteredReservoir::class)] +#[CoversClass(AllExemplarFilter::class)] +#[CoversClass(NoneExemplarFilter::class)] +#[CoversClass(WithSampledTraceExemplarFilter::class)] final class FilteredReservoirTest extends TestCase { - /** - * @covers \OpenTelemetry\SDK\Metrics\Exemplar\ExemplarFilter\AllExemplarFilter - */ public function test_all_reservoir_returns_exemplars(): void { $reservoir = new FilteredReservoir(new FixedSizeReservoir(4), new AllExemplarFilter()); @@ -38,9 +37,6 @@ public function test_all_reservoir_returns_exemplars(): void ], Exemplar::groupByIndex($reservoir->collect([0 => Attributes::create([])]))); } - /** - * @covers \OpenTelemetry\SDK\Metrics\Exemplar\ExemplarFilter\NoneExemplarFilter - */ public function test_none_reservoir_doesnt_return_exemplars(): void { $reservoir = new FilteredReservoir(new FixedSizeReservoir(4), new NoneExemplarFilter()); @@ -50,9 +46,6 @@ public function test_none_reservoir_doesnt_return_exemplars(): void ], Exemplar::groupByIndex($reservoir->collect([0 => Attributes::create([])]))); } - /** - * @covers \OpenTelemetry\SDK\Metrics\Exemplar\ExemplarFilter\WithSampledTraceExemplarFilter - */ public function test_with_sampled_trace_reservoir_returns_sampled_exemplars(): void { $reservoir = new FilteredReservoir(new FixedSizeReservoir(4), new WithSampledTraceExemplarFilter()); @@ -69,9 +62,6 @@ public function test_with_sampled_trace_reservoir_returns_sampled_exemplars(): v ], Exemplar::groupByIndex($reservoir->collect([0 => Attributes::create([])]))); } - /** - * @covers \OpenTelemetry\SDK\Metrics\Exemplar\ExemplarFilter\WithSampledTraceExemplarFilter - */ public function test_with_sampled_trace_reservoir_doesnt_return_not_sampled_exemplars(): void { $reservoir = new FilteredReservoir(new FixedSizeReservoir(4), new WithSampledTraceExemplarFilter()); diff --git a/tests/Unit/SDK/Metrics/Exemplar/FixedSizeReservoirTest.php b/tests/Unit/SDK/Metrics/Exemplar/FixedSizeReservoirTest.php index 97c6d5d85..c7d272d3c 100644 --- a/tests/Unit/SDK/Metrics/Exemplar/FixedSizeReservoirTest.php +++ b/tests/Unit/SDK/Metrics/Exemplar/FixedSizeReservoirTest.php @@ -8,11 +8,10 @@ use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Metrics\Data\Exemplar; use OpenTelemetry\SDK\Metrics\Exemplar\FixedSizeReservoir; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Exemplar\FixedSizeReservoir - */ +#[CoversClass(FixedSizeReservoir::class)] final class FixedSizeReservoirTest extends TestCase { public function test_reservoir_returns_exemplars(): void diff --git a/tests/Unit/SDK/Metrics/Exemplar/HistogramBucketReservoirTest.php b/tests/Unit/SDK/Metrics/Exemplar/HistogramBucketReservoirTest.php index e71ca0c77..50b22364e 100644 --- a/tests/Unit/SDK/Metrics/Exemplar/HistogramBucketReservoirTest.php +++ b/tests/Unit/SDK/Metrics/Exemplar/HistogramBucketReservoirTest.php @@ -8,11 +8,10 @@ use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Metrics\Data\Exemplar; use OpenTelemetry\SDK\Metrics\Exemplar\HistogramBucketReservoir; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Exemplar\HistogramBucketReservoir - */ +#[CoversClass(HistogramBucketReservoir::class)] final class HistogramBucketReservoirTest extends TestCase { public function test_reservoir_returns_exemplars(): void diff --git a/tests/Unit/SDK/Metrics/Exemplar/NoopReservoirTest.php b/tests/Unit/SDK/Metrics/Exemplar/NoopReservoirTest.php index f713e7094..336a3169e 100644 --- a/tests/Unit/SDK/Metrics/Exemplar/NoopReservoirTest.php +++ b/tests/Unit/SDK/Metrics/Exemplar/NoopReservoirTest.php @@ -7,11 +7,10 @@ use OpenTelemetry\Context\Context; use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Metrics\Exemplar\NoopReservoir; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Exemplar\NoopReservoir - */ +#[CoversClass(NoopReservoir::class)] final class NoopReservoirTest extends TestCase { public function test_reservoir_does_not_return_exemplars(): void diff --git a/tests/Unit/SDK/Metrics/InstrumentTest.php b/tests/Unit/SDK/Metrics/InstrumentTest.php index cca7e8ad5..362653539 100644 --- a/tests/Unit/SDK/Metrics/InstrumentTest.php +++ b/tests/Unit/SDK/Metrics/InstrumentTest.php @@ -26,16 +26,19 @@ use OpenTelemetry\SDK\Metrics\Stream\MetricAggregatorFactory; use OpenTelemetry\SDK\Metrics\Stream\SynchronousMetricStream; use OpenTelemetry\SDK\Metrics\UpDownCounter; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use stdClass; use WeakMap; +#[CoversClass(Counter::class)] +#[CoversClass(ObservableCounter::class)] +#[CoversClass(UpDownCounter::class)] +#[CoversClass(Histogram::class)] +#[CoversClass(ObservableCallback::class)] final class InstrumentTest extends TestCase { - /** - * @covers \OpenTelemetry\SDK\Metrics\Counter - */ public function test_counter(): void { $a = new MetricAggregator(null, new SumAggregation(true)); @@ -65,9 +68,6 @@ public function test_counter(): void ), $s->collect($r)); } - /** - * @covers \OpenTelemetry\SDK\Metrics\ObservableCounter - */ public function test_asynchronous_counter(): void { $a = new MetricAggregatorFactory(null, new SumAggregation(true)); @@ -97,9 +97,6 @@ public function test_asynchronous_counter(): void ), $s->collect($r)); } - /** - * @covers \OpenTelemetry\SDK\Metrics\ObservableCounter - */ public function test_asynchronous_counter_weaken(): void { $a = new MetricAggregatorFactory(null, new SumAggregation(true)); @@ -128,9 +125,6 @@ public function __invoke(ObserverInterface $observer) ), $s->collect($r)); } - /** - * @covers \OpenTelemetry\SDK\Metrics\UpDownCounter - */ public function test_up_down_counter(): void { $a = new MetricAggregator(null, new SumAggregation(false)); @@ -160,9 +154,6 @@ public function test_up_down_counter(): void ), $s->collect($r)); } - /** - * @covers \OpenTelemetry\SDK\Metrics\Histogram - */ public function test_histogram(): void { $a = new MetricAggregator(null, new ExplicitBucketHistogramAggregation([3, 6, 9])); @@ -200,9 +191,6 @@ public function test_histogram(): void ), $s->collect($r)); } - /** - * @covers \OpenTelemetry\SDK\Metrics\ObservableCallback - */ public function test_observable_callback_releases_on_detach(): void { $writer = $this->createMock(MetricWriterInterface::class); @@ -214,9 +202,6 @@ public function test_observable_callback_releases_on_detach(): void $callback->detach(); } - /** - * @covers \OpenTelemetry\SDK\Metrics\ObservableCallback - */ public function test_observable_callback_removes_callback_destructor_token_on_detach(): void { $writer = $this->createMock(MetricWriterInterface::class); @@ -231,9 +216,6 @@ public function test_observable_callback_removes_callback_destructor_token_on_de $this->assertArrayNotHasKey(1, $callbackDestructor->callbackIds); } - /** - * @covers \OpenTelemetry\SDK\Metrics\ObservableCallback - */ public function test_observable_callback_acquires_persistent_on_destruct(): void { $writer = $this->createMock(MetricWriterInterface::class); @@ -245,9 +227,6 @@ public function test_observable_callback_acquires_persistent_on_destruct(): void new ObservableCallback($writer, $referenceCounter, 1, null, null); } - /** - * @covers \OpenTelemetry\SDK\Metrics\ObservableCallback - */ public function test_observable_callback_does_not_acquire_persistent_on_destruct_if_callback_destructor_set(): void { $writer = $this->createMock(MetricWriterInterface::class); diff --git a/tests/Unit/SDK/Metrics/MeterProviderFactoryTest.php b/tests/Unit/SDK/Metrics/MeterProviderFactoryTest.php index dbc597773..e02eed9bf 100644 --- a/tests/Unit/SDK/Metrics/MeterProviderFactoryTest.php +++ b/tests/Unit/SDK/Metrics/MeterProviderFactoryTest.php @@ -4,35 +4,30 @@ namespace OpenTelemetry\Tests\Unit\SDK\Metrics; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Behavior\Internal\Logging; use OpenTelemetry\API\Metrics\MeterInterface; use OpenTelemetry\SDK\Common\Configuration\KnownValues; use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Metrics\MeterProviderFactory; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\MeterProviderFactory - */ +#[CoversClass(MeterProviderFactory::class)] class MeterProviderFactoryTest extends TestCase { - use EnvironmentVariables; + use TestState; public function setUp(): void { Logging::disable(); } - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - /** - * @dataProvider exporterProvider * @psalm-suppress ArgumentTypeCoercion */ + #[DataProvider('exporterProvider')] public function test_create(string $exporter): void { $_SERVER[Variables::OTEL_METRICS_EXPORTER] = $exporter; diff --git a/tests/Unit/SDK/Metrics/MeterProviderTest.php b/tests/Unit/SDK/Metrics/MeterProviderTest.php index 30d4fd9f3..df551d9d8 100644 --- a/tests/Unit/SDK/Metrics/MeterProviderTest.php +++ b/tests/Unit/SDK/Metrics/MeterProviderTest.php @@ -17,11 +17,10 @@ use OpenTelemetry\SDK\Metrics\StalenessHandler\ImmediateStalenessHandlerFactory; use OpenTelemetry\SDK\Metrics\View\CriteriaViewRegistry; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\MeterProvider - */ +#[CoversClass(MeterProvider::class)] final class MeterProviderTest extends TestCase { public function test_get_meter_creates_instrumentation_scope_with_given_arguments(): void diff --git a/tests/Unit/SDK/Metrics/MeterTest.php b/tests/Unit/SDK/Metrics/MeterTest.php index 37340de94..9e9362c81 100644 --- a/tests/Unit/SDK/Metrics/MeterTest.php +++ b/tests/Unit/SDK/Metrics/MeterTest.php @@ -13,6 +13,7 @@ use OpenTelemetry\SDK\Metrics\DefaultAggregationProviderInterface; use OpenTelemetry\SDK\Metrics\Instrument; use OpenTelemetry\SDK\Metrics\InstrumentType; +use OpenTelemetry\SDK\Metrics\Meter; use OpenTelemetry\SDK\Metrics\MeterProvider; use OpenTelemetry\SDK\Metrics\MetricFactoryInterface; use OpenTelemetry\SDK\Metrics\MetricReaderInterface; @@ -22,11 +23,10 @@ use OpenTelemetry\SDK\Metrics\ViewProjection; use OpenTelemetry\SDK\Metrics\ViewRegistryInterface; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Meter - */ +#[CoversClass(Meter::class)] final class MeterTest extends TestCase { public function test_create_counter(): void diff --git a/tests/Unit/SDK/Metrics/MetricExporter/ConsoleMetricExporterFactoryTest.php b/tests/Unit/SDK/Metrics/MetricExporter/ConsoleMetricExporterFactoryTest.php index f224684a6..5087e2044 100644 --- a/tests/Unit/SDK/Metrics/MetricExporter/ConsoleMetricExporterFactoryTest.php +++ b/tests/Unit/SDK/Metrics/MetricExporter/ConsoleMetricExporterFactoryTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\SDK\Metrics\MetricExporter\ConsoleMetricExporterFactory; use OpenTelemetry\SDK\Metrics\MetricExporterInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\MetricExporter\ConsoleMetricExporterFactory - */ +#[CoversClass(ConsoleMetricExporterFactory::class)] class ConsoleMetricExporterFactoryTest extends TestCase { public function test_create(): void diff --git a/tests/Unit/SDK/Metrics/MetricExporter/InMemoryExporterFactoryTest.php b/tests/Unit/SDK/Metrics/MetricExporter/InMemoryExporterFactoryTest.php index e5f05bbcf..dac703047 100644 --- a/tests/Unit/SDK/Metrics/MetricExporter/InMemoryExporterFactoryTest.php +++ b/tests/Unit/SDK/Metrics/MetricExporter/InMemoryExporterFactoryTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\SDK\Metrics\MetricExporter\InMemoryExporterFactory; use OpenTelemetry\SDK\Metrics\MetricExporterInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\MetricExporter\InMemoryExporterFactory - */ +#[CoversClass(InMemoryExporterFactory::class)] class InMemoryExporterFactoryTest extends TestCase { public function test_create(): void diff --git a/tests/Unit/SDK/Metrics/MetricExporter/InMemoryExporterTest.php b/tests/Unit/SDK/Metrics/MetricExporter/InMemoryExporterTest.php index 54f495434..fa1b5f4aa 100644 --- a/tests/Unit/SDK/Metrics/MetricExporter/InMemoryExporterTest.php +++ b/tests/Unit/SDK/Metrics/MetricExporter/InMemoryExporterTest.php @@ -9,12 +9,11 @@ use OpenTelemetry\SDK\Metrics\Data\Metric; use OpenTelemetry\SDK\Metrics\MetricExporter\InMemoryExporter; use OpenTelemetry\SDK\Resource\ResourceInfo; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use function sprintf; -/** - * @covers \OpenTelemetry\SDK\Metrics\MetricExporter\InMemoryExporter - */ +#[CoversClass(InMemoryExporter::class)] final class InMemoryExporterTest extends TestCase { public function test_empty_exporter_collect_returns_empty_metrics(): void diff --git a/tests/Unit/SDK/Metrics/MetricExporter/NoopMetricExporterFactoryTest.php b/tests/Unit/SDK/Metrics/MetricExporter/NoopMetricExporterFactoryTest.php index 5284afe23..d928a5887 100644 --- a/tests/Unit/SDK/Metrics/MetricExporter/NoopMetricExporterFactoryTest.php +++ b/tests/Unit/SDK/Metrics/MetricExporter/NoopMetricExporterFactoryTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\SDK\Metrics\MetricExporter\NoopMetricExporterFactory; use OpenTelemetry\SDK\Metrics\MetricExporterInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\MetricExporter\NoopMetricExporterFactory - */ +#[CoversClass(NoopMetricExporterFactory::class)] class NoopMetricExporterFactoryTest extends TestCase { public function test_create(): void diff --git a/tests/Unit/SDK/Metrics/MetricFactory/StreamFactoryTest.php b/tests/Unit/SDK/Metrics/MetricFactory/StreamFactoryTest.php index c1cf3e7fc..439d04afa 100644 --- a/tests/Unit/SDK/Metrics/MetricFactory/StreamFactoryTest.php +++ b/tests/Unit/SDK/Metrics/MetricFactory/StreamFactoryTest.php @@ -18,6 +18,8 @@ use OpenTelemetry\SDK\Metrics\Instrument; use OpenTelemetry\SDK\Metrics\InstrumentType; use OpenTelemetry\SDK\Metrics\MetricFactory\StreamFactory; +use OpenTelemetry\SDK\Metrics\MetricFactory\StreamMetricSource; +use OpenTelemetry\SDK\Metrics\MetricFactory\StreamMetricSourceProvider; use OpenTelemetry\SDK\Metrics\MetricMetadataInterface; use OpenTelemetry\SDK\Metrics\MetricRegistration\RegistryRegistration; use OpenTelemetry\SDK\Metrics\MetricRegistry\MetricRegistry; @@ -27,13 +29,12 @@ use OpenTelemetry\SDK\Metrics\StalenessHandlerInterface; use OpenTelemetry\SDK\Metrics\ViewProjection; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\MetricFactory\StreamFactory - * @covers \OpenTelemetry\SDK\Metrics\MetricFactory\StreamMetricSource - * @covers \OpenTelemetry\SDK\Metrics\MetricFactory\StreamMetricSourceProvider - */ +#[CoversClass(StreamFactory::class)] +#[CoversClass(StreamMetricSource::class)] +#[CoversClass(StreamMetricSourceProvider::class)] final class StreamFactoryTest extends TestCase { public function test_create_asynchronous_observer(): void diff --git a/tests/Unit/SDK/Metrics/MetricReader/ExportingReaderTest.php b/tests/Unit/SDK/Metrics/MetricReader/ExportingReaderTest.php index 2c16fea28..d9bb3e05a 100644 --- a/tests/Unit/SDK/Metrics/MetricReader/ExportingReaderTest.php +++ b/tests/Unit/SDK/Metrics/MetricReader/ExportingReaderTest.php @@ -24,11 +24,10 @@ use OpenTelemetry\SDK\Metrics\StalenessHandler\ImmediateStalenessHandler; use OpenTelemetry\SDK\Metrics\StalenessHandlerInterface; use OpenTelemetry\SDK\Resource\ResourceInfo; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\MetricReader\ExportingReader - */ +#[CoversClass(ExportingReader::class)] final class ExportingReaderTest extends TestCase { public function test_empty_reader_collects_empty_metrics(): void diff --git a/tests/Unit/SDK/Metrics/MetricRegistry/MetricRegistryTest.php b/tests/Unit/SDK/Metrics/MetricRegistry/MetricRegistryTest.php index 788209d35..6a9cc6849 100644 --- a/tests/Unit/SDK/Metrics/MetricRegistry/MetricRegistryTest.php +++ b/tests/Unit/SDK/Metrics/MetricRegistry/MetricRegistryTest.php @@ -14,18 +14,19 @@ use OpenTelemetry\SDK\Metrics\Instrument; use OpenTelemetry\SDK\Metrics\InstrumentType; use OpenTelemetry\SDK\Metrics\MetricRegistry\MetricRegistry; +use OpenTelemetry\SDK\Metrics\MetricRegistry\MultiObserver; +use OpenTelemetry\SDK\Metrics\MetricRegistry\NoopObserver; use OpenTelemetry\SDK\Metrics\Stream\AsynchronousMetricStream; use OpenTelemetry\SDK\Metrics\Stream\MetricAggregator; use OpenTelemetry\SDK\Metrics\Stream\MetricAggregatorFactory; use OpenTelemetry\SDK\Metrics\Stream\SynchronousMetricStream; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use function printf; -/** - * @covers \OpenTelemetry\SDK\Metrics\MetricRegistry\MetricRegistry - * @covers \OpenTelemetry\SDK\Metrics\MetricRegistry\MultiObserver - * @covers \OpenTelemetry\SDK\Metrics\MetricRegistry\NoopObserver - */ +#[CoversClass(MetricRegistry::class)] +#[CoversClass(MultiObserver::class)] +#[CoversClass(NoopObserver::class)] final class MetricRegistryTest extends TestCase { public function test_collect_and_push_recorded_value(): void diff --git a/tests/Unit/SDK/Metrics/StalenessHandler/DelayedStalenessHandlerTest.php b/tests/Unit/SDK/Metrics/StalenessHandler/DelayedStalenessHandlerTest.php index 46817b70e..d669aca97 100644 --- a/tests/Unit/SDK/Metrics/StalenessHandler/DelayedStalenessHandlerTest.php +++ b/tests/Unit/SDK/Metrics/StalenessHandler/DelayedStalenessHandlerTest.php @@ -5,15 +5,15 @@ namespace OpenTelemetry\Tests\Unit\SDK\Metrics\StalenessHandler; use OpenTelemetry\API\Common\Time\TestClock; +use OpenTelemetry\SDK\Metrics\StalenessHandler\DelayedStalenessHandler; use OpenTelemetry\SDK\Metrics\StalenessHandler\DelayedStalenessHandlerFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use stdClass; use WeakReference; -/** - * @covers \OpenTelemetry\SDK\Metrics\StalenessHandler\DelayedStalenessHandler - * @covers \OpenTelemetry\SDK\Metrics\StalenessHandler\DelayedStalenessHandlerFactory - */ +#[CoversClass(DelayedStalenessHandler::class)] +#[CoversClass(DelayedStalenessHandlerFactory::class)] final class DelayedStalenessHandlerTest extends TestCase { public function test_on_stale(): void diff --git a/tests/Unit/SDK/Metrics/StalenessHandler/ImmediateStalenessHandlerTest.php b/tests/Unit/SDK/Metrics/StalenessHandler/ImmediateStalenessHandlerTest.php index 8cac806ce..18eebd2ae 100644 --- a/tests/Unit/SDK/Metrics/StalenessHandler/ImmediateStalenessHandlerTest.php +++ b/tests/Unit/SDK/Metrics/StalenessHandler/ImmediateStalenessHandlerTest.php @@ -4,15 +4,15 @@ namespace OpenTelemetry\Tests\Unit\SDK\Metrics\StalenessHandler; +use OpenTelemetry\SDK\Metrics\StalenessHandler\ImmediateStalenessHandler; use OpenTelemetry\SDK\Metrics\StalenessHandler\ImmediateStalenessHandlerFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use stdClass; use WeakReference; -/** - * @covers \OpenTelemetry\SDK\Metrics\StalenessHandler\ImmediateStalenessHandler - * @covers \OpenTelemetry\SDK\Metrics\StalenessHandler\ImmediateStalenessHandlerFactory - */ +#[CoversClass(ImmediateStalenessHandler::class)] +#[CoversClass(ImmediateStalenessHandlerFactory::class)] final class ImmediateStalenessHandlerTest extends TestCase { public function test_on_stale(): void diff --git a/tests/Unit/SDK/Metrics/StalenessHandler/NoopStalenessHandlerTest.php b/tests/Unit/SDK/Metrics/StalenessHandler/NoopStalenessHandlerTest.php index 7dbeed001..a2bddaec4 100644 --- a/tests/Unit/SDK/Metrics/StalenessHandler/NoopStalenessHandlerTest.php +++ b/tests/Unit/SDK/Metrics/StalenessHandler/NoopStalenessHandlerTest.php @@ -4,13 +4,13 @@ namespace OpenTelemetry\Tests\Unit\SDK\Metrics\StalenessHandler; +use OpenTelemetry\SDK\Metrics\StalenessHandler\NoopStalenessHandler; use OpenTelemetry\SDK\Metrics\StalenessHandler\NoopStalenessHandlerFactory; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\StalenessHandler\NoopStalenessHandler - * @covers \OpenTelemetry\SDK\Metrics\StalenessHandler\NoopStalenessHandlerFactory - */ +#[CoversClass(NoopStalenessHandler::class)] +#[CoversClass(NoopStalenessHandlerFactory::class)] final class NoopStalenessHandlerTest extends TestCase { public function test_on_stale(): void diff --git a/tests/Unit/SDK/Metrics/Stream/DeltaStorageTest.php b/tests/Unit/SDK/Metrics/Stream/DeltaStorageTest.php index 77b52bf17..30eda1f28 100644 --- a/tests/Unit/SDK/Metrics/Stream/DeltaStorageTest.php +++ b/tests/Unit/SDK/Metrics/Stream/DeltaStorageTest.php @@ -8,18 +8,18 @@ use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Metrics\Aggregation\SumAggregation; use OpenTelemetry\SDK\Metrics\Aggregation\SumSummary; +use OpenTelemetry\SDK\Metrics\Stream\Delta; use OpenTelemetry\SDK\Metrics\Stream\DeltaStorage; use OpenTelemetry\SDK\Metrics\Stream\Metric; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Stream\DeltaStorage - * @covers \OpenTelemetry\SDK\Metrics\Stream\Delta - * @covers \OpenTelemetry\SDK\Metrics\Stream\Metric - * - * @uses \OpenTelemetry\SDK\Metrics\Aggregation\SumAggregation - * @uses \OpenTelemetry\SDK\Metrics\Aggregation\SumSummary - */ +#[CoversClass(DeltaStorage::class)] +#[CoversClass(Delta::class)] +#[CoversClass(Metric::class)] +#[UsesClass(SumAggregation::class)] +#[UsesClass(SumSummary::class)] final class DeltaStorageTest extends TestCase { public function test_empty_storage_returns_empty_metrics(): void diff --git a/tests/Unit/SDK/Metrics/Stream/MetricStreamTest.php b/tests/Unit/SDK/Metrics/Stream/MetricStreamTest.php index bf3ae7967..55c80472a 100644 --- a/tests/Unit/SDK/Metrics/Stream/MetricStreamTest.php +++ b/tests/Unit/SDK/Metrics/Stream/MetricStreamTest.php @@ -9,40 +9,40 @@ use OpenTelemetry\API\Behavior\Internal\Logging; use OpenTelemetry\Context\Context; use OpenTelemetry\SDK\Common\Attribute\Attributes; +use OpenTelemetry\SDK\Common\Attribute\AttributesBuilder; +use OpenTelemetry\SDK\Common\Attribute\AttributesFactory; use OpenTelemetry\SDK\Metrics\Aggregation\SumAggregation; use OpenTelemetry\SDK\Metrics\Aggregation\SumSummary; use OpenTelemetry\SDK\Metrics\AttributeProcessor\FilteredAttributeProcessor; -use OpenTelemetry\SDK\Metrics\Data; +use OpenTelemetry\SDK\Metrics\Data\NumberDataPoint; +use OpenTelemetry\SDK\Metrics\Data\Sum; use OpenTelemetry\SDK\Metrics\Data\Temporality; use OpenTelemetry\SDK\Metrics\Exemplar\ExemplarReservoirInterface; use OpenTelemetry\SDK\Metrics\Stream\AsynchronousMetricStream; +use OpenTelemetry\SDK\Metrics\Stream\Delta; +use OpenTelemetry\SDK\Metrics\Stream\DeltaStorage; use OpenTelemetry\SDK\Metrics\Stream\Metric; use OpenTelemetry\SDK\Metrics\Stream\MetricAggregator; use OpenTelemetry\SDK\Metrics\Stream\SynchronousMetricStream; use const PHP_INT_SIZE; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\Stream\AsynchronousMetricStream - * @covers \OpenTelemetry\SDK\Metrics\Stream\SynchronousMetricStream - * - * @covers \OpenTelemetry\SDK\Metrics\Stream\Metric - * @covers \OpenTelemetry\SDK\Metrics\Stream\MetricAggregator - * - * @uses \OpenTelemetry\SDK\Metrics\Stream\Delta - * @uses \OpenTelemetry\SDK\Metrics\Stream\DeltaStorage - * - * @uses \OpenTelemetry\SDK\Metrics\Data\NumberDataPoint - * @uses \OpenTelemetry\SDK\Metrics\Data\Sum - * @uses \OpenTelemetry\SDK\Metrics\Data\Temporality - * - * @uses \OpenTelemetry\SDK\Metrics\Aggregation\SumAggregation - * @uses \OpenTelemetry\SDK\Metrics\Aggregation\SumSummary - * - * @uses \OpenTelemetry\SDK\Common\Attribute\Attributes - * @uses \OpenTelemetry\SDK\Common\Attribute\AttributesBuilder - * @uses \OpenTelemetry\SDK\Common\Attribute\AttributesFactory - */ +#[CoversClass(AsynchronousMetricStream::class)] +#[CoversClass(SynchronousMetricStream::class)] +#[CoversClass(Metric::class)] +#[CoversClass(MetricAggregator::class)] +#[UsesClass(Delta::class)] +#[UsesClass(DeltaStorage::class)] +#[UsesClass(NumberDataPoint::class)] +#[UsesClass(Sum::class)] +#[UsesClass(Temporality::class)] +#[UsesClass(SumAggregation::class)] +#[UsesClass(SumSummary::class)] +#[UsesClass(Attributes::class)] +#[UsesClass(AttributesBuilder::class)] +#[UsesClass(AttributesFactory::class)] final class MetricStreamTest extends TestCase { public function setUp(): void @@ -58,27 +58,27 @@ public function test_asynchronous_single_data_point(): void $c = $s->register(Temporality::CUMULATIVE); $s->push(new Metric([Attributes::create([])], [new SumSummary(5)], 5)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(5, Attributes::create([]), 3, 5), + $this->assertEquals(new Sum([ + new NumberDataPoint(5, Attributes::create([]), 3, 5), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(5, Attributes::create([]), 3, 5), + $this->assertEquals(new Sum([ + new NumberDataPoint(5, Attributes::create([]), 3, 5), ], Temporality::CUMULATIVE, false), $s->collect($c)); $s->push(new Metric([Attributes::create([])], [new SumSummary(7)], 8)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(2, Attributes::create([]), 5, 8), + $this->assertEquals(new Sum([ + new NumberDataPoint(2, Attributes::create([]), 5, 8), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(7, Attributes::create([]), 3, 8), + $this->assertEquals(new Sum([ + new NumberDataPoint(7, Attributes::create([]), 3, 8), ], Temporality::CUMULATIVE, false), $s->collect($c)); $s->push(new Metric([Attributes::create([])], [new SumSummary(3)], 12)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(-4, Attributes::create([]), 8, 12), + $this->assertEquals(new Sum([ + new NumberDataPoint(-4, Attributes::create([]), 8, 12), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(3, Attributes::create([]), 3, 12), + $this->assertEquals(new Sum([ + new NumberDataPoint(3, Attributes::create([]), 3, 12), ], Temporality::CUMULATIVE, false), $s->collect($c)); } @@ -90,23 +90,23 @@ public function test_asynchronous_multiple_data_points(): void $c = $s->register(Temporality::CUMULATIVE); $s->push(new Metric([Attributes::create(['status' => 300]), Attributes::create(['status' => 400])], [new SumSummary(5), new SumSummary(2)], 5)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(5, Attributes::create(['status' => 300]), 3, 5), - new Data\NumberDataPoint(2, Attributes::create(['status' => 400]), 3, 5), + $this->assertEquals(new Sum([ + new NumberDataPoint(5, Attributes::create(['status' => 300]), 3, 5), + new NumberDataPoint(2, Attributes::create(['status' => 400]), 3, 5), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(5, Attributes::create(['status' => 300]), 3, 5), - new Data\NumberDataPoint(2, Attributes::create(['status' => 400]), 3, 5), + $this->assertEquals(new Sum([ + new NumberDataPoint(5, Attributes::create(['status' => 300]), 3, 5), + new NumberDataPoint(2, Attributes::create(['status' => 400]), 3, 5), ], Temporality::CUMULATIVE, false), $s->collect($c)); $s->push(new Metric([Attributes::create(['status' => 300]), Attributes::create(['status' => 400])], [new SumSummary(2), new SumSummary(7)], 8)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(-3, Attributes::create(['status' => 300]), 5, 8), - new Data\NumberDataPoint(5, Attributes::create(['status' => 400]), 5, 8), + $this->assertEquals(new Sum([ + new NumberDataPoint(-3, Attributes::create(['status' => 300]), 5, 8), + new NumberDataPoint(5, Attributes::create(['status' => 400]), 5, 8), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(2, Attributes::create(['status' => 300]), 3, 8), - new Data\NumberDataPoint(7, Attributes::create(['status' => 400]), 3, 8), + $this->assertEquals(new Sum([ + new NumberDataPoint(2, Attributes::create(['status' => 300]), 3, 8), + new NumberDataPoint(7, Attributes::create(['status' => 400]), 3, 8), ], Temporality::CUMULATIVE, false), $s->collect($c)); } @@ -122,17 +122,17 @@ public function test_asynchronous_omit_data_point(): void $s->collect($c); $s->push(new Metric([], [], 7)); - $this->assertEquals(new Data\Sum([ + $this->assertEquals(new Sum([ ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ + $this->assertEquals(new Sum([ ], Temporality::CUMULATIVE, false), $s->collect($c)); $s->push(new Metric([Attributes::create([])], [new SumSummary(3)], 12)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(3, Attributes::create([]), 7, 12), + $this->assertEquals(new Sum([ + new NumberDataPoint(3, Attributes::create([]), 7, 12), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(3, Attributes::create([]), 3, 12), + $this->assertEquals(new Sum([ + new NumberDataPoint(3, Attributes::create([]), 3, 12), ], Temporality::CUMULATIVE, false), $s->collect($c)); } @@ -144,27 +144,27 @@ public function test_synchronous_single_data_point(): void $c = $s->register(Temporality::CUMULATIVE); $s->push(new Metric([Attributes::create([])], [new SumSummary(5)], 5)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(5, Attributes::create([]), 3, 5), + $this->assertEquals(new Sum([ + new NumberDataPoint(5, Attributes::create([]), 3, 5), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(5, Attributes::create([]), 3, 5), + $this->assertEquals(new Sum([ + new NumberDataPoint(5, Attributes::create([]), 3, 5), ], Temporality::CUMULATIVE, false), $s->collect($c)); $s->push(new Metric([Attributes::create([])], [new SumSummary(2)], 8)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(2, Attributes::create([]), 5, 8), + $this->assertEquals(new Sum([ + new NumberDataPoint(2, Attributes::create([]), 5, 8), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(7, Attributes::create([]), 3, 8), + $this->assertEquals(new Sum([ + new NumberDataPoint(7, Attributes::create([]), 3, 8), ], Temporality::CUMULATIVE, false), $s->collect($c)); $s->push(new Metric([Attributes::create([])], [new SumSummary(-4)], 12)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(-4, Attributes::create([]), 8, 12), + $this->assertEquals(new Sum([ + new NumberDataPoint(-4, Attributes::create([]), 8, 12), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(3, Attributes::create([]), 3, 12), + $this->assertEquals(new Sum([ + new NumberDataPoint(3, Attributes::create([]), 3, 12), ], Temporality::CUMULATIVE, false), $s->collect($c)); } @@ -176,23 +176,23 @@ public function test_synchronous_multiple_data_points(): void $c = $s->register(Temporality::CUMULATIVE); $s->push(new Metric([Attributes::create(['status' => 300]), Attributes::create(['status' => 400])], [new SumSummary(5), new SumSummary(2)], 5)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(5, Attributes::create(['status' => 300]), 3, 5), - new Data\NumberDataPoint(2, Attributes::create(['status' => 400]), 3, 5), + $this->assertEquals(new Sum([ + new NumberDataPoint(5, Attributes::create(['status' => 300]), 3, 5), + new NumberDataPoint(2, Attributes::create(['status' => 400]), 3, 5), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(5, Attributes::create(['status' => 300]), 3, 5), - new Data\NumberDataPoint(2, Attributes::create(['status' => 400]), 3, 5), + $this->assertEquals(new Sum([ + new NumberDataPoint(5, Attributes::create(['status' => 300]), 3, 5), + new NumberDataPoint(2, Attributes::create(['status' => 400]), 3, 5), ], Temporality::CUMULATIVE, false), $s->collect($c)); $s->push(new Metric([Attributes::create(['status' => 300]), Attributes::create(['status' => 400])], [new SumSummary(-3), new SumSummary(5)], 8)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(-3, Attributes::create(['status' => 300]), 5, 8), - new Data\NumberDataPoint(5, Attributes::create(['status' => 400]), 5, 8), + $this->assertEquals(new Sum([ + new NumberDataPoint(-3, Attributes::create(['status' => 300]), 5, 8), + new NumberDataPoint(5, Attributes::create(['status' => 400]), 5, 8), ], Temporality::DELTA, false), $s->collect($d)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(2, Attributes::create(['status' => 300]), 3, 8), - new Data\NumberDataPoint(7, Attributes::create(['status' => 400]), 3, 8), + $this->assertEquals(new Sum([ + new NumberDataPoint(2, Attributes::create(['status' => 300]), 3, 8), + new NumberDataPoint(7, Attributes::create(['status' => 400]), 3, 8), ], Temporality::CUMULATIVE, false), $s->collect($c)); } @@ -240,8 +240,8 @@ public function test_asynchronous_unregister_removes_reader(): void $s->push(new Metric([Attributes::create([])], [new SumSummary(5)], 7)); // Implementation treats unknown reader as cumulative reader - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(5, Attributes::create([]), 3, 7), + $this->assertEquals(new Sum([ + new NumberDataPoint(5, Attributes::create([]), 3, 7), ], Temporality::CUMULATIVE, false), $s->collect($d)); } @@ -255,7 +255,7 @@ public function test_synchronous_unregister_removes_reader(): void $s->unregister($c); $s->push(new Metric([Attributes::create([])], [new SumSummary(-5)], 7)); - $this->assertEquals(new Data\Sum([ + $this->assertEquals(new Sum([ ], Temporality::DELTA, false), $s->collect($c)); } @@ -269,8 +269,8 @@ public function test_asynchronous_unregister_invalid_does_not_affect_reader(): v $s->unregister($d + 1); $s->push(new Metric([Attributes::create([])], [new SumSummary(5)], 7)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(0, Attributes::create([]), 5, 7), + $this->assertEquals(new Sum([ + new NumberDataPoint(0, Attributes::create([]), 5, 7), ], Temporality::DELTA, false), $s->collect($d)); } @@ -284,8 +284,8 @@ public function test_synchronous_unregister_invalid_does_not_affect_reader(): vo $s->unregister($c + 1); $s->push(new Metric([Attributes::create([])], [new SumSummary(-5)], 7)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(0, Attributes::create([]), 3, 7), + $this->assertEquals(new Sum([ + new NumberDataPoint(0, Attributes::create([]), 3, 7), ], Temporality::CUMULATIVE, false), $s->collect($c)); } @@ -320,7 +320,7 @@ public function test_synchronous_reader_limit_exceeded_returns_noop_reader(): vo $d = @$s->register(Temporality::DELTA); $s->push(new Metric([Attributes::create([])], [new SumSummary(5)], 5)); - $this->assertEquals(new Data\Sum([ + $this->assertEquals(new Sum([ ], Temporality::DELTA, false), $s->collect($d)); } @@ -339,8 +339,8 @@ public function test_synchronous_reader_limit_does_not_apply_if_gmp_available(): $d = $s->register(Temporality::DELTA); $s->push(new Metric([Attributes::create([])], [new SumSummary(5)], 5)); - $this->assertEquals(new Data\Sum([ - new Data\NumberDataPoint(5, Attributes::create([]), 3, 5), + $this->assertEquals(new Sum([ + new NumberDataPoint(5, Attributes::create([]), 3, 5), ], Temporality::DELTA, false), $s->collect($d)); } diff --git a/tests/Unit/SDK/Metrics/View/CriteriaViewRegistryTest.php b/tests/Unit/SDK/Metrics/View/CriteriaViewRegistryTest.php index 276b67566..bcec858c6 100644 --- a/tests/Unit/SDK/Metrics/View/CriteriaViewRegistryTest.php +++ b/tests/Unit/SDK/Metrics/View/CriteriaViewRegistryTest.php @@ -12,11 +12,10 @@ use OpenTelemetry\SDK\Metrics\View\SelectionCriteria\InstrumentNameCriteria; use OpenTelemetry\SDK\Metrics\View\ViewTemplate; use OpenTelemetry\SDK\Metrics\ViewProjection; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\View\CriteriaViewRegistry - */ +#[CoversClass(CriteriaViewRegistry::class)] final class CriteriaViewRegistryTest extends TestCase { public function test_empty_registry_returns_null(): void diff --git a/tests/Unit/SDK/Metrics/View/SelectionCriteriaTest.php b/tests/Unit/SDK/Metrics/View/SelectionCriteriaTest.php index f17a292dc..3038483c3 100644 --- a/tests/Unit/SDK/Metrics/View/SelectionCriteriaTest.php +++ b/tests/Unit/SDK/Metrics/View/SelectionCriteriaTest.php @@ -15,16 +15,21 @@ use OpenTelemetry\SDK\Metrics\View\SelectionCriteria\InstrumentNameCriteria; use OpenTelemetry\SDK\Metrics\View\SelectionCriteria\InstrumentTypeCriteria; use OpenTelemetry\SDK\Metrics\View\SelectionCriteriaInterface; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Prophecy\PhpUnit\ProphecyTrait; +#[CoversClass(InstrumentationScopeNameCriteria::class)] +#[CoversClass(InstrumentationScopeVersionCriteria::class)] +#[CoversClass(InstrumentationScopeSchemaUrlCriteria::class)] +#[CoversClass(InstrumentNameCriteria::class)] +#[CoversClass(InstrumentTypeCriteria::class)] +#[CoversClass(AllCriteria::class)] final class SelectionCriteriaTest extends TestCase { use ProphecyTrait; - /** - * @covers \OpenTelemetry\SDK\Metrics\View\SelectionCriteria\InstrumentationScopeNameCriteria - */ public function test_instrument_scope_name_criteria(): void { $this->assertTrue((new InstrumentationScopeNameCriteria('scopeName'))->accepts( @@ -37,9 +42,6 @@ public function test_instrument_scope_name_criteria(): void )); } - /** - * @covers \OpenTelemetry\SDK\Metrics\View\SelectionCriteria\InstrumentationScopeVersionCriteria - */ public function test_instrument_scope_version_criteria(): void { $this->assertTrue((new InstrumentationScopeVersionCriteria('1.0.0'))->accepts( @@ -52,9 +54,6 @@ public function test_instrument_scope_version_criteria(): void )); } - /** - * @covers \OpenTelemetry\SDK\Metrics\View\SelectionCriteria\InstrumentationScopeSchemaUrlCriteria - */ public function test_instrument_scope_schema_url_criteria(): void { $this->assertTrue((new InstrumentationScopeSchemaUrlCriteria('https://schema-url.test/1.0'))->accepts( @@ -69,9 +68,8 @@ public function test_instrument_scope_schema_url_criteria(): void /** * @param non-empty-string $pattern - * @covers \OpenTelemetry\SDK\Metrics\View\SelectionCriteria\InstrumentNameCriteria - * @dataProvider instrumentNameProvider */ + #[DataProvider('instrumentNameProvider')] public function test_instrument_name_criteria(string $pattern, string $name, bool $expected): void { $this->assertSame($expected, (new InstrumentNameCriteria($pattern))->accepts( @@ -94,9 +92,6 @@ public static function instrumentNameProvider(): iterable yield 'match all - matching' => ['*', 'foobar', true]; } - /** - * @covers \OpenTelemetry\SDK\Metrics\View\SelectionCriteria\InstrumentTypeCriteria - */ public function test_instrument_type_criteria_wildcard(): void { $this->assertTrue((new InstrumentTypeCriteria(InstrumentType::COUNTER))->accepts( @@ -109,9 +104,6 @@ public function test_instrument_type_criteria_wildcard(): void )); } - /** - * @covers \OpenTelemetry\SDK\Metrics\View\SelectionCriteria\AllCriteria - */ public function test_all_criteria_accepts_if_all_criteria_accept(): void { $instrument = new Instrument(InstrumentType::COUNTER, 'name', null, null); @@ -133,9 +125,6 @@ public function test_all_criteria_accepts_if_all_criteria_accept(): void $this->assertTrue((new AllCriteria($criterias))->accepts($instrument, $instrumentScope)); } - /** - * @covers \OpenTelemetry\SDK\Metrics\View\SelectionCriteria\AllCriteria - */ public function test_all_criteria_rejects_if_any_criteria_rejects(): void { $instrument = new Instrument(InstrumentType::COUNTER, 'name', null, null); diff --git a/tests/Unit/SDK/Metrics/View/ViewTemplateTest.php b/tests/Unit/SDK/Metrics/View/ViewTemplateTest.php index 3048fa76f..03a8f44d8 100644 --- a/tests/Unit/SDK/Metrics/View/ViewTemplateTest.php +++ b/tests/Unit/SDK/Metrics/View/ViewTemplateTest.php @@ -9,11 +9,10 @@ use OpenTelemetry\SDK\Metrics\InstrumentType; use OpenTelemetry\SDK\Metrics\View\ViewTemplate; use OpenTelemetry\SDK\Metrics\ViewProjection; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Metrics\View\ViewTemplate - */ +#[CoversClass(ViewTemplate::class)] final class ViewTemplateTest extends TestCase { public function test_empty_template_returns_instrument_defaults(): void diff --git a/tests/Unit/SDK/Propagation/PropagatorFactoryTest.php b/tests/Unit/SDK/Propagation/PropagatorFactoryTest.php index 8634f375e..37accfa9f 100644 --- a/tests/Unit/SDK/Propagation/PropagatorFactoryTest.php +++ b/tests/Unit/SDK/Propagation/PropagatorFactoryTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Unit\SDK\Propagation; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Baggage\Propagation\BaggagePropagator; use OpenTelemetry\API\Behavior\Internal\Logging; use OpenTelemetry\API\LoggerHolder; @@ -18,14 +17,15 @@ use OpenTelemetry\SDK\Common\Configuration\KnownValues; use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Propagation\PropagatorFactory; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Propagation\PropagatorFactory - */ +#[CoversClass(PropagatorFactory::class)] class PropagatorFactoryTest extends TestCase { - use EnvironmentVariables; + use TestState; public function setUp(): void { @@ -33,15 +33,10 @@ public function setUp(): void Logging::disable(); } - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - /** - * @dataProvider propagatorsProvider * @psalm-suppress ArgumentTypeCoercion */ + #[DataProvider('propagatorsProvider')] public function test_create(string $propagators, string $expected): void { $this->setEnvironmentVariable(Variables::OTEL_PROPAGATORS, $propagators); @@ -66,9 +61,7 @@ public static function propagatorsProvider(): array ]; } - /** - * @dataProvider unimplementedPropagatorProvider - */ + #[DataProvider('unimplementedPropagatorProvider')] public function test_unimplemented_propagators(string $propagator): void { $this->setEnvironmentVariable(Variables::OTEL_PROPAGATORS, $propagator); diff --git a/tests/Unit/SDK/Resource/Detectors/ComposerTest.php b/tests/Unit/SDK/Resource/Detectors/ComposerTest.php index 3c6f7e419..a328dcad7 100644 --- a/tests/Unit/SDK/Resource/Detectors/ComposerTest.php +++ b/tests/Unit/SDK/Resource/Detectors/ComposerTest.php @@ -5,19 +5,18 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource\Detectors; use Composer\InstalledVersions; -use OpenTelemetry\SDK\Resource\Detectors; +use OpenTelemetry\SDK\Resource\Detectors\Composer; use OpenTelemetry\SemConv\ResourceAttributes; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\Detectors\Composer - */ +#[CoversClass(Composer::class)] class ComposerTest extends TestCase { public function test_composer_get_resource(): void { - $resouceDetector = new Detectors\Composer(); - $resource = $resouceDetector->getResource(); + $resourceDetector = new Composer(); + $resource = $resourceDetector->getResource(); $name = 'open-telemetry/opentelemetry'; $version = InstalledVersions::getPrettyVersion($name); @@ -28,7 +27,7 @@ public function test_composer_get_resource(): void public function test_composer_detector(): void { - $resource = (new Detectors\Composer())->getResource(); + $resource = (new Composer())->getResource(); $this->assertNotNull($resource->getAttributes()->get(ResourceAttributes::SERVICE_NAME)); $this->assertNotNull($resource->getAttributes()->get(ResourceAttributes::SERVICE_VERSION)); diff --git a/tests/Unit/SDK/Resource/Detectors/CompositeTest.php b/tests/Unit/SDK/Resource/Detectors/CompositeTest.php index 50955ed93..c2187fc53 100644 --- a/tests/Unit/SDK/Resource/Detectors/CompositeTest.php +++ b/tests/Unit/SDK/Resource/Detectors/CompositeTest.php @@ -5,20 +5,19 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource\Detectors; use OpenTelemetry\SDK\Common\Attribute\Attributes; -use OpenTelemetry\SDK\Resource\Detectors; +use OpenTelemetry\SDK\Resource\Detectors\Composite; use OpenTelemetry\SDK\Resource\ResourceDetectorInterface; use OpenTelemetry\SDK\Resource\ResourceInfo; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\Detectors\Composite - */ +#[CoversClass(Composite::class)] class CompositeTest extends TestCase { public function test_composite_with_empty_resource_detectors(): void { - $resouceDetector = new Detectors\Composite([]); - $resource = $resouceDetector->getResource(); + $resourceDetector = new Composite([]); + $resource = $resourceDetector->getResource(); $this->assertNull($resource->getSchemaUrl()); $this->assertEmpty($resource->getAttributes()); @@ -31,7 +30,7 @@ public function test_composite_get_resource(): void $resourceDetector = $this->createMock(ResourceDetectorInterface::class); $resourceDetector->method('getResource')->willReturn($resource); - $resource = (new Detectors\Composite([$resourceDetector]))->getResource(); + $resource = (new Composite([$resourceDetector]))->getResource(); $this->assertSame('user-foo', $resource->getAttributes()->get('foo')); $this->assertSame('user-bar', $resource->getAttributes()->get('bar')); diff --git a/tests/Unit/SDK/Resource/Detectors/ConstantTest.php b/tests/Unit/SDK/Resource/Detectors/ConstantTest.php index b57f3a211..b95ee1346 100644 --- a/tests/Unit/SDK/Resource/Detectors/ConstantTest.php +++ b/tests/Unit/SDK/Resource/Detectors/ConstantTest.php @@ -5,19 +5,18 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource\Detectors; use OpenTelemetry\SDK\Common\Attribute\Attributes; -use OpenTelemetry\SDK\Resource\Detectors; +use OpenTelemetry\SDK\Resource\Detectors\Constant; use OpenTelemetry\SDK\Resource\ResourceInfo; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\Detectors\Constant - */ +#[CoversClass(Constant::class)] class ConstantTest extends TestCase { public function test_constant_get_resource_with_empty_resource(): void { - $resouceDetector = new Detectors\Constant(ResourceInfo::create(Attributes::create([]))); - $resource = $resouceDetector->getResource(); + $resourceDetector = new Constant(ResourceInfo::create(Attributes::create([]))); + $resource = $resourceDetector->getResource(); $this->assertNull($resource->getSchemaUrl()); $this->assertEmpty($resource->getAttributes()); @@ -25,8 +24,8 @@ public function test_constant_get_resource_with_empty_resource(): void public function test_constant_get_resource_with_custom_resource(): void { - $resouceDetector = new Detectors\Constant(ResourceInfo::create(Attributes::create(['foo' => 'user-foo', 'bar' => 'user-bar']))); - $resource = $resouceDetector->getResource(); + $resourceDetector = new Constant(ResourceInfo::create(Attributes::create(['foo' => 'user-foo', 'bar' => 'user-bar']))); + $resource = $resourceDetector->getResource(); $this->assertNull($resource->getSchemaUrl()); diff --git a/tests/Unit/SDK/Resource/Detectors/EnvironmentTest.php b/tests/Unit/SDK/Resource/Detectors/EnvironmentTest.php index c2693876b..fd1da2914 100644 --- a/tests/Unit/SDK/Resource/Detectors/EnvironmentTest.php +++ b/tests/Unit/SDK/Resource/Detectors/EnvironmentTest.php @@ -4,28 +4,23 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource\Detectors; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; -use OpenTelemetry\SDK\Resource\Detectors; +use OpenTelemetry\SDK\Resource\Detectors\Environment; use OpenTelemetry\SemConv\ResourceAttributes; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\Detectors\Environment - */ +#[CoversClass(Environment::class)] class EnvironmentTest extends TestCase { - use EnvironmentVariables; + use TestState; - private Detectors\Environment $detector; + private Environment $detector; public function setUp(): void { - $this->detector = new Detectors\Environment(); - } - - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); + $this->detector = new Environment(); } public function test_environment_default_get_resource(): void @@ -47,9 +42,7 @@ public function test_environment_get_resource_with_resource_attributes(): void $this->assertSame('value_bar', $resource->getAttributes()->get('key_bar')); } - /** - * @dataProvider encodedResourceValueProvider - */ + #[DataProvider('encodedResourceValueProvider')] public function test_environment_get_resource_with_encoded_value(string $value, string $expected): void { $key = 'key'; diff --git a/tests/Unit/SDK/Resource/Detectors/HostTest.php b/tests/Unit/SDK/Resource/Detectors/HostTest.php index 589a48453..dfc0b199d 100644 --- a/tests/Unit/SDK/Resource/Detectors/HostTest.php +++ b/tests/Unit/SDK/Resource/Detectors/HostTest.php @@ -4,19 +4,19 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource\Detectors; -use OpenTelemetry\SDK\Resource\Detectors; +use OpenTelemetry\SDK\Resource\Detectors\Host; use OpenTelemetry\SemConv\ResourceAttributes; use org\bovigo\vfs\vfsStream; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\Detectors\Host - */ +#[CoversClass(Host::class)] class HostTest extends TestCase { public function test_host_get_resource(): void { - $resourceDetector = new Detectors\Host(); + $resourceDetector = new Host(); $resource = $resourceDetector->getResource(); $this->assertSame(ResourceAttributes::SCHEMA_URL, $resource->getSchemaUrl()); @@ -24,13 +24,11 @@ public function test_host_get_resource(): void $this->assertIsString($resource->getAttributes()->get(ResourceAttributes::HOST_ARCH)); } - /** - * @dataProvider hostIdData - */ + #[DataProvider('hostIdData')] public function test_host_id_filesystem(string $os, array $files, ?string $expectedId): void { $root = vfsStream::setup('/', null, $files); - $resourceDetector = new Detectors\Host($root->url(), $os); + $resourceDetector = new Host($root->url(), $os); $resource = $resourceDetector->getResource(); if ($expectedId === null) { diff --git a/tests/Unit/SDK/Resource/Detectors/OperatingSystemTest.php b/tests/Unit/SDK/Resource/Detectors/OperatingSystemTest.php index d9fc52d92..878d91030 100644 --- a/tests/Unit/SDK/Resource/Detectors/OperatingSystemTest.php +++ b/tests/Unit/SDK/Resource/Detectors/OperatingSystemTest.php @@ -4,19 +4,18 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource\Detectors; -use OpenTelemetry\SDK\Resource\Detectors; +use OpenTelemetry\SDK\Resource\Detectors\OperatingSystem; use OpenTelemetry\SemConv\ResourceAttributes; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\Detectors\OperatingSystem - */ +#[CoversClass(OperatingSystem::class)] class OperatingSystemTest extends TestCase { public function test_operating_system_get_resource(): void { - $resouceDetector = new Detectors\OperatingSystem(); - $resource = $resouceDetector->getResource(); + $resourceDetector = new OperatingSystem(); + $resource = $resourceDetector->getResource(); $this->assertSame(ResourceAttributes::SCHEMA_URL, $resource->getSchemaUrl()); $this->assertIsString($resource->getAttributes()->get(ResourceAttributes::OS_TYPE)); diff --git a/tests/Unit/SDK/Resource/Detectors/ProcessRuntimeTest.php b/tests/Unit/SDK/Resource/Detectors/ProcessRuntimeTest.php index 6f50910b1..a2ff575cb 100644 --- a/tests/Unit/SDK/Resource/Detectors/ProcessRuntimeTest.php +++ b/tests/Unit/SDK/Resource/Detectors/ProcessRuntimeTest.php @@ -4,19 +4,18 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource\Detectors; -use OpenTelemetry\SDK\Resource\Detectors; +use OpenTelemetry\SDK\Resource\Detectors\ProcessRuntime; use OpenTelemetry\SemConv\ResourceAttributes; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\Detectors\ProcessRuntime - */ +#[CoversClass(ProcessRuntime::class)] class ProcessRuntimeTest extends TestCase { public function test_process_runtime_get_resource(): void { - $resouceDetector = new Detectors\ProcessRuntime(); - $resource = $resouceDetector->getResource(); + $resourceDetector = new ProcessRuntime(); + $resource = $resourceDetector->getResource(); $this->assertSame(ResourceAttributes::SCHEMA_URL, $resource->getSchemaUrl()); $this->assertIsString($resource->getAttributes()->get(ResourceAttributes::PROCESS_RUNTIME_NAME)); diff --git a/tests/Unit/SDK/Resource/Detectors/ProcessTest.php b/tests/Unit/SDK/Resource/Detectors/ProcessTest.php index 81a7046c9..70183d94f 100644 --- a/tests/Unit/SDK/Resource/Detectors/ProcessTest.php +++ b/tests/Unit/SDK/Resource/Detectors/ProcessTest.php @@ -4,19 +4,18 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource\Detectors; -use OpenTelemetry\SDK\Resource\Detectors; +use OpenTelemetry\SDK\Resource\Detectors\Process; use OpenTelemetry\SemConv\ResourceAttributes; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\Detectors\Process - */ +#[CoversClass(Process::class)] class ProcessTest extends TestCase { public function test_process_get_resource(): void { - $resouceDetector = new Detectors\Process(); - $resource = $resouceDetector->getResource(); + $resourceDetector = new Process(); + $resource = $resourceDetector->getResource(); $this->assertSame(ResourceAttributes::SCHEMA_URL, $resource->getSchemaUrl()); $this->assertIsInt($resource->getAttributes()->get(ResourceAttributes::PROCESS_PID)); diff --git a/tests/Unit/SDK/Resource/Detectors/SdkProvidedTest.php b/tests/Unit/SDK/Resource/Detectors/SdkProvidedTest.php index eab7f4ee7..46742a2e8 100644 --- a/tests/Unit/SDK/Resource/Detectors/SdkProvidedTest.php +++ b/tests/Unit/SDK/Resource/Detectors/SdkProvidedTest.php @@ -4,18 +4,17 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource\Detectors; -use OpenTelemetry\SDK\Resource\Detectors; +use OpenTelemetry\SDK\Resource\Detectors\SdkProvided; use OpenTelemetry\SemConv\ResourceAttributes; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\Detectors\SdkProvided - */ +#[CoversClass(SdkProvided::class)] class SdkProvidedTest extends TestCase { public function test_sdk_provided_get_resource(): void { - $resourceDetector = new Detectors\SdkProvided(); + $resourceDetector = new SdkProvided(); $resource = $resourceDetector->getResource(); $this->assertSame(ResourceAttributes::SCHEMA_URL, $resource->getSchemaUrl()); diff --git a/tests/Unit/SDK/Resource/Detectors/SdkTest.php b/tests/Unit/SDK/Resource/Detectors/SdkTest.php index 733a62a4e..da2ba17fb 100644 --- a/tests/Unit/SDK/Resource/Detectors/SdkTest.php +++ b/tests/Unit/SDK/Resource/Detectors/SdkTest.php @@ -5,19 +5,18 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource\Detectors; use Composer\InstalledVersions; -use OpenTelemetry\SDK\Resource\Detectors; +use OpenTelemetry\SDK\Resource\Detectors\Sdk; use OpenTelemetry\SemConv\ResourceAttributes; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\Detectors\Sdk - */ +#[CoversClass(Sdk::class)] class SdkTest extends TestCase { public function test_sdk_get_resource(): void { - $resouceDetector = new Detectors\Sdk(); - $resource = $resouceDetector->getResource(); + $resourceDetector = new Sdk(); + $resource = $resourceDetector->getResource(); $version = InstalledVersions::getPrettyVersion('open-telemetry/opentelemetry'); $this->assertSame(ResourceAttributes::SCHEMA_URL, $resource->getSchemaUrl()); diff --git a/tests/Unit/SDK/Resource/ResourceInfoFactoryTest.php b/tests/Unit/SDK/Resource/ResourceInfoFactoryTest.php index 70e5c6097..b046c0718 100644 --- a/tests/Unit/SDK/Resource/ResourceInfoFactoryTest.php +++ b/tests/Unit/SDK/Resource/ResourceInfoFactoryTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use Generator; use InvalidArgumentException; use OpenTelemetry\API\Behavior\Internal\Logging; @@ -14,15 +13,17 @@ use OpenTelemetry\SDK\Resource\ResourceDetectorInterface; use OpenTelemetry\SDK\Resource\ResourceInfo; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\ResourceInfoFactory - */ +#[CoversClass(ResourceInfoFactory::class)] class ResourceInfoFactoryTest extends TestCase { - use EnvironmentVariables; + use TestState; /** @var LogWriterInterface&MockObject $logWriter */ private LogWriterInterface $logWriter; @@ -34,12 +35,6 @@ public function setUp(): void Logging::setLogWriter($this->logWriter); } - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - Logging::reset(); - } - public function test_empty_resource(): void { $resource = ResourceInfoFactory::emptyResource(); @@ -62,9 +57,7 @@ public function test_merge(): void $this->assertEquals('', $empty); } - /** - * @dataProvider schemaUrlsToMergeProvider - */ + #[DataProvider('schemaUrlsToMergeProvider')] public function test_merge_schema_url(array $schemaUrlsToMerge, ?string $expectedSchemaUrl): void { $resource = ResourceInfoFactory::emptyResource(); @@ -88,27 +81,21 @@ public static function schemaUrlsToMergeProvider(): Generator yield 'Schema url is undefined and implementation-specific after merging error' => [['http://url-1', 'http://url-2', 'http://url-2'], self::UNDEFINED]; } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_resource_service_name_default(): void { $resource = ResourceInfoFactory::defaultResource(); $this->assertEquals('open-telemetry/opentelemetry', $resource->getAttributes()->get('service.name')); } - /** - * @group compliance - */ + #[Group('compliance')] public function test_resource_with_empty_environment_variable(): void { $this->setEnvironmentVariable('OTEL_RESOURCE_ATTRIBUTES', ''); $this->assertInstanceOf(ResourceInfo::class, ResourceInfoFactory::defaultResource()); } - /** - * @group compliance - */ + #[Group('compliance')] public function test_resource_with_invalid_environment_variable(): void { $this->setEnvironmentVariable('OTEL_RESOURCE_ATTRIBUTES', 'foo'); @@ -116,9 +103,7 @@ public function test_resource_with_invalid_environment_variable(): void $this->assertInstanceOf(ResourceInfo::class, ResourceInfoFactory::defaultResource()); } - /** - * @group compliance - */ + #[Group('compliance')] public function test_resource_from_environment_service_name_takes_precedence_over_resource_attribute(): void { $this->setEnvironmentVariable('OTEL_RESOURCE_ATTRIBUTES', 'service.name=bar'); @@ -127,9 +112,7 @@ public function test_resource_from_environment_service_name_takes_precedence_ove $this->assertEquals('foo', $resource->getAttributes()->get('service.name')); } - /** - * @group compliance - */ + #[Group('compliance')] public function test_resource_from_environment_resource_attribute_takes_precedence_over_default(): void { $this->setEnvironmentVariable('OTEL_RESOURCE_ATTRIBUTES', 'service.name=foo'); diff --git a/tests/Unit/SDK/Resource/ResourceInfoTest.php b/tests/Unit/SDK/Resource/ResourceInfoTest.php index ee223472b..e98f75884 100644 --- a/tests/Unit/SDK/Resource/ResourceInfoTest.php +++ b/tests/Unit/SDK/Resource/ResourceInfoTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Unit\SDK\Resource; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use Composer\InstalledVersions; use Generator; use OpenTelemetry\API\Behavior\Internal\Logging; @@ -13,25 +12,22 @@ use OpenTelemetry\SDK\Resource\ResourceInfo; use OpenTelemetry\SDK\Resource\ResourceInfoFactory; use OpenTelemetry\SemConv\ResourceAttributes; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Resource\ResourceInfo - */ +#[CoversClass(ResourceInfo::class)] class ResourceInfoTest extends TestCase { - use EnvironmentVariables; + use TestState; public function setUp(): void { Logging::disable(); } - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - public function test_get_attributes(): void { $attributes = Attributes::create(['name' => 'test']); @@ -55,9 +51,7 @@ public function test_get_attributes(): void $this->assertSame('test', $name); } - /** - * @dataProvider sameResourcesProvider - */ + #[DataProvider('sameResourcesProvider')] public function test_serialize_returns_same_output_for_objects_representing_the_same_resource(ResourceInfo $resource1, ResourceInfo $resource2): void { $this->assertSame($resource1->serialize(), $resource2->serialize()); @@ -79,9 +73,7 @@ public static function sameResourcesProvider(): iterable ]; } - /** - * @dataProvider differentResourcesProvider - */ + #[DataProvider('differentResourcesProvider')] public function test_serialize_returns_different_output_for_objects_representing_different_resources(ResourceInfo $resource1, ResourceInfo $resource2): void { $this->assertNotSame($resource1->serialize(), $resource2->serialize()); @@ -124,9 +116,9 @@ public function test_merge(): void } /** - * @group compliance * "If a key exists on both the old and updating resource, the value of the updating resource MUST be picked (even if the updated value is empty)" */ + #[Group('compliance')] public function test_merge_uses_value_of_updating_resource(): void { $old = ResourceInfo::create(Attributes::create(['name' => 'original', 'foo' => 'bar'])); @@ -147,9 +139,7 @@ public function test_merge_with_numeric_attribute_keys(): void $this->assertSame('two.upd', $merged->getAttributes()->get('2')); } - /** - * @dataProvider schemaUrlsToMergeProvider - */ + #[DataProvider('schemaUrlsToMergeProvider')] public function test_merge_schema_url(array $schemaUrlsToMerge, ?string $expectedSchemaUrl): void { $old = ResourceInfo::create(Attributes::create([]), $schemaUrlsToMerge[0]); diff --git a/tests/Unit/SDK/SdkAutoloaderTest.php b/tests/Unit/SDK/SdkAutoloaderTest.php index 5d59fbe76..f77eedbd5 100644 --- a/tests/Unit/SDK/SdkAutoloaderTest.php +++ b/tests/Unit/SDK/SdkAutoloaderTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Unit\SDK; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Behavior\Internal\Logging; use OpenTelemetry\API\Globals; use OpenTelemetry\API\Logs\NoopEventLoggerProvider; @@ -14,14 +13,15 @@ use OpenTelemetry\Context\Propagation\NoopTextMapPropagator; use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\SdkAutoloader; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\SdkAutoloader - */ +#[CoversClass(SdkAutoloader::class)] class SdkAutoloaderTest extends TestCase { - use EnvironmentVariables; + use TestState; public function setUp(): void { @@ -29,11 +29,6 @@ public function setUp(): void Globals::reset(); } - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - public function test_disabled_by_default(): void { $this->assertFalse(SdkAutoloader::isEnabled()); @@ -95,9 +90,7 @@ public function test_exclude_urls_without_request_uri(): void $this->assertFalse(SdkAutoloader::isExcludedUrl()); } - /** - * @dataProvider excludeUrlsProvider - */ + #[DataProvider('excludeUrlsProvider')] public function test_exclude_urls(string $exclude, string $uri, bool $expected): void { $this->setEnvironmentVariable(Variables::OTEL_PHP_EXCLUDED_URLS, $exclude); diff --git a/tests/Unit/SDK/SdkBuilderTest.php b/tests/Unit/SDK/SdkBuilderTest.php index 48baabaae..d9e3fa6f6 100644 --- a/tests/Unit/SDK/SdkBuilderTest.php +++ b/tests/Unit/SDK/SdkBuilderTest.php @@ -11,11 +11,10 @@ use OpenTelemetry\SDK\Metrics\MeterProviderInterface; use OpenTelemetry\SDK\SdkBuilder; use OpenTelemetry\SDK\Trace\TracerProviderInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\SdkBuilder - */ +#[CoversClass(SdkBuilder::class)] class SdkBuilderTest extends TestCase { private TextMapPropagatorInterface $propagator; diff --git a/tests/Unit/SDK/SdkTest.php b/tests/Unit/SDK/SdkTest.php index be35ab3bb..ab89c7d0e 100644 --- a/tests/Unit/SDK/SdkTest.php +++ b/tests/Unit/SDK/SdkTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Unit\SDK; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Logs\EventLoggerProviderInterface; use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; use OpenTelemetry\SDK\Common\Configuration\Variables; @@ -13,28 +12,22 @@ use OpenTelemetry\SDK\Sdk; use OpenTelemetry\SDK\SdkBuilder; use OpenTelemetry\SDK\Trace\TracerProviderInterface; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Sdk - */ +#[CoversClass(Sdk::class)] class SdkTest extends TestCase { - use EnvironmentVariables; - - public function tearDown(): void - { - self::restoreEnvironmentVariables(); - } + use TestState; public function test_is_not_disabled_by_default(): void { $this->assertFalse(Sdk::isDisabled()); } - /** - * @dataProvider disabledProvider - */ + #[DataProvider('disabledProvider')] public function test_is_disabled(string $value, bool $expected): void { self::setEnvironmentVariable('OTEL_SDK_DISABLED', $value); @@ -49,9 +42,7 @@ public static function disabledProvider(): array ]; } - /** - * @dataProvider instrumentationDisabledProvider - */ + #[DataProvider('instrumentationDisabledProvider')] public function test_is_instrumentation_disabled(string $value, string $name, bool $expected): void { $this->setEnvironmentVariable(Variables::OTEL_PHP_DISABLED_INSTRUMENTATIONS, $value); diff --git a/tests/Unit/SDK/Trace/Behavior/UsesSpanConverterTraitTest.php b/tests/Unit/SDK/Trace/Behavior/UsesSpanConverterTraitTest.php index f91e2be13..0abf02fc2 100644 --- a/tests/Unit/SDK/Trace/Behavior/UsesSpanConverterTraitTest.php +++ b/tests/Unit/SDK/Trace/Behavior/UsesSpanConverterTraitTest.php @@ -7,16 +7,12 @@ use OpenTelemetry\SDK\Trace\Behavior\UsesSpanConverterTrait; use OpenTelemetry\SDK\Trace\SpanConverterInterface; use OpenTelemetry\SDK\Trace\SpanExporter\NullSpanConverter; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass OpenTelemetry\SDK\Trace\Behavior\UsesSpanConverterTrait - */ +#[CoversClass(UsesSpanConverterTrait::class)] class UsesSpanConverterTraitTest extends TestCase { - /** - * @covers ::getSpanConverter - */ public function test_accessors(): void { $instance = $this->createInstance(); @@ -30,9 +26,6 @@ public function test_accessors(): void ); } - /** - * @covers ::getSpanConverter - */ public function test_fallback_converter(): void { $this->assertInstanceOf( diff --git a/tests/Unit/SDK/Trace/EventTest.php b/tests/Unit/SDK/Trace/EventTest.php index 02eb1acf8..f1345be95 100644 --- a/tests/Unit/SDK/Trace/EventTest.php +++ b/tests/Unit/SDK/Trace/EventTest.php @@ -7,11 +7,10 @@ use OpenTelemetry\API\Common\Time\TestClock; use OpenTelemetry\SDK\Common\Attribute\AttributesInterface; use OpenTelemetry\SDK\Trace\Event; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\Event - */ +#[CoversClass(Event::class)] class EventTest extends TestCase { private const EVENT_NAME = 'test-event'; diff --git a/tests/Unit/SDK/Trace/ExporterFactoryTest.php b/tests/Unit/SDK/Trace/ExporterFactoryTest.php index 8e1956b6b..882992346 100644 --- a/tests/Unit/SDK/Trace/ExporterFactoryTest.php +++ b/tests/Unit/SDK/Trace/ExporterFactoryTest.php @@ -4,35 +4,29 @@ namespace OpenTelemetry\Tests\Unit\SDK\Trace; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use Exception; use Http\Discovery\Psr18ClientDiscovery; use Http\Discovery\Strategy\MockClientStrategy; use OpenTelemetry\Contrib; use OpenTelemetry\SDK\Trace\ExporterFactory; use OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporter; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\ExporterFactory - */ +#[CoversClass(ExporterFactory::class)] class ExporterFactoryTest extends TestCase { - use EnvironmentVariables; - - public function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } + use TestState; public function setUp(): void { Psr18ClientDiscovery::prependStrategy(MockClientStrategy::class); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_accepts_none_exporter_env_var(): void { $this->setEnvironmentVariable('OTEL_TRACES_EXPORTER', 'none'); @@ -41,10 +35,10 @@ public function test_accepts_none_exporter_env_var(): void } /** - * @dataProvider envProvider * @psalm-param class-string $expected - * @group trace-compliance */ + #[DataProvider('envProvider')] + #[Group('trace-compliance')] public function test_create_from_environment(string $exporter, array $env, string $expected): void { $this->setEnvironmentVariable('OTEL_TRACES_EXPORTER', $exporter); @@ -89,10 +83,8 @@ public static function envProvider(): array ]; } - /** - * @dataProvider invalidEnvProvider - * @group trace-compliance - */ + #[DataProvider('invalidEnvProvider')] + #[Group('trace-compliance')] public function test_throws_exception_for_invalid_or_unsupported_exporter_configs(string $exporter, array $env = []): void { $this->setEnvironmentVariable('OTEL_TRACES_EXPORTER', $exporter); diff --git a/tests/Unit/SDK/Trace/ImmutableSpanTest.php b/tests/Unit/SDK/Trace/ImmutableSpanTest.php index bf3c294e4..133a3b170 100644 --- a/tests/Unit/SDK/Trace/ImmutableSpanTest.php +++ b/tests/Unit/SDK/Trace/ImmutableSpanTest.php @@ -12,11 +12,10 @@ use OpenTelemetry\SDK\Trace\ImmutableSpan; use OpenTelemetry\SDK\Trace\Span; use OpenTelemetry\SDK\Trace\StatusDataInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\ImmutableSpan - */ +#[CoversClass(ImmutableSpan::class)] class ImmutableSpanTest extends TestCase { private Span $span; diff --git a/tests/Unit/SDK/Trace/LinkTest.php b/tests/Unit/SDK/Trace/LinkTest.php index 8f99fa547..c7f8d301a 100644 --- a/tests/Unit/SDK/Trace/LinkTest.php +++ b/tests/Unit/SDK/Trace/LinkTest.php @@ -7,11 +7,10 @@ use OpenTelemetry\API\Trace as API; use OpenTelemetry\SDK\Common\Attribute\AttributesInterface; use OpenTelemetry\SDK\Trace\Link; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\Link - */ +#[CoversClass(Link::class)] class LinkTest extends TestCase { private API\SpanContextInterface $context; diff --git a/tests/Unit/SDK/Trace/NonRecordingSpanTest.php b/tests/Unit/SDK/Trace/NonRecordingSpanTest.php index b7e1fd271..d2870b047 100644 --- a/tests/Unit/SDK/Trace/NonRecordingSpanTest.php +++ b/tests/Unit/SDK/Trace/NonRecordingSpanTest.php @@ -5,21 +5,21 @@ namespace OpenTelemetry\Tests\Unit\SDK\Trace; use OpenTelemetry\API\Trace as API; +use OpenTelemetry\API\Trace\NonRecordingSpan; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\API\Trace\NonRecordingSpan - */ +#[CoversClass(NonRecordingSpan::class)] class NonRecordingSpanTest extends TestCase { public function test_is_not_recording(): void { - $this->assertFalse(API\NonRecordingSpan::getInvalid()->isRecording()); + $this->assertFalse(NonRecordingSpan::getInvalid()->isRecording()); } public function test_has_invalid_context_and_default_span_options(): void { - $context = API\NonRecordingSpan::getInvalid()->getContext(); + $context = NonRecordingSpan::getInvalid()->getContext(); $this->assertSame(API\TraceFlags::DEFAULT, $context->getTraceFlags()); $this->assertNull($context->getTraceState()); } diff --git a/tests/Unit/SDK/Trace/RandomIdGeneratorTest.php b/tests/Unit/SDK/Trace/RandomIdGeneratorTest.php index 690dcf6a0..dff39f290 100644 --- a/tests/Unit/SDK/Trace/RandomIdGeneratorTest.php +++ b/tests/Unit/SDK/Trace/RandomIdGeneratorTest.php @@ -6,16 +6,14 @@ use OpenTelemetry\API\Trace\SpanContextValidator; use OpenTelemetry\SDK\Trace\RandomIdGenerator; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\RandomIdGenerator - */ +#[CoversClass(RandomIdGenerator::class)] class RandomIdGeneratorTest extends TestCase { - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_generated_trace_id_is_valid(): void { $idGenerator = new RandomIdGenerator(); @@ -24,9 +22,7 @@ public function test_generated_trace_id_is_valid(): void $this->assertEquals(1, preg_match(SpanContextValidator::VALID_TRACE, $traceId)); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_generated_span_id_is_valid(): void { $idGenerator = new RandomIdGenerator(); @@ -43,9 +39,9 @@ public function test_fallback_algorithm(): void $method->setAccessible(true); $traceId = $method->invokeArgs($idGenerator, [$reflection->getConstant('TRACE_ID_HEX_LENGTH')]); - $this->assertEquals(1, preg_match(SpanContextValidator::VALID_TRACE, $traceId)); + $this->assertEquals(1, preg_match(SpanContextValidator::VALID_TRACE, (string) $traceId)); $spanId = $method->invokeArgs($idGenerator, [$reflection->getConstant('SPAN_ID_HEX_LENGTH')]); - $this->assertEquals(1, preg_match(SpanContextValidator::VALID_SPAN, $spanId)); + $this->assertEquals(1, preg_match(SpanContextValidator::VALID_SPAN, (string) $spanId)); } } diff --git a/tests/Unit/SDK/Trace/Sampler/AlwaysOffSamplerTest.php b/tests/Unit/SDK/Trace/Sampler/AlwaysOffSamplerTest.php index fb9cc927c..1b56894e5 100644 --- a/tests/Unit/SDK/Trace/Sampler/AlwaysOffSamplerTest.php +++ b/tests/Unit/SDK/Trace/Sampler/AlwaysOffSamplerTest.php @@ -9,16 +9,12 @@ use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Trace\Sampler\AlwaysOffSampler; use OpenTelemetry\SDK\Trace\SamplingResult; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass OpenTelemetry\SDK\Trace\Sampler\AlwaysOffSampler - */ +#[CoversClass(AlwaysOffSampler::class)] class AlwaysOffSamplerTest extends TestCase { - /** - * @covers ::shouldSample - */ public function test_should_sample(): void { $parentContext = Context::getRoot(); @@ -35,9 +31,6 @@ public function test_should_sample(): void $this->assertEquals(SamplingResult::DROP, $decision->getDecision()); } - /** - * @covers ::getDescription - */ public function test_get_description(): void { $sampler = new AlwaysOffSampler(); diff --git a/tests/Unit/SDK/Trace/Sampler/AlwaysOnSamplerTest.php b/tests/Unit/SDK/Trace/Sampler/AlwaysOnSamplerTest.php index aefd39a84..9cbc1af1d 100644 --- a/tests/Unit/SDK/Trace/Sampler/AlwaysOnSamplerTest.php +++ b/tests/Unit/SDK/Trace/Sampler/AlwaysOnSamplerTest.php @@ -9,16 +9,12 @@ use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Trace\Sampler\AlwaysOnSampler; use OpenTelemetry\SDK\Trace\SamplingResult; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass OpenTelemetry\SDK\Trace\Sampler\AlwaysOnSampler - */ +#[CoversClass(AlwaysOnSampler::class)] class AlwaysOnSamplerTest extends TestCase { - /** - * @covers ::shouldSample - */ public function test_should_sample(): void { $parentContext = Context::getRoot(); @@ -35,9 +31,6 @@ public function test_should_sample(): void $this->assertEquals(SamplingResult::RECORD_AND_SAMPLE, $decision->getDecision()); } - /** - * @covers ::getDescription - */ public function test_get_description(): void { $sampler = new AlwaysOnSampler(); diff --git a/tests/Unit/SDK/Trace/Sampler/ParentBasedTest.php b/tests/Unit/SDK/Trace/Sampler/ParentBasedTest.php index 71dee07f9..bff4429c4 100644 --- a/tests/Unit/SDK/Trace/Sampler/ParentBasedTest.php +++ b/tests/Unit/SDK/Trace/Sampler/ParentBasedTest.php @@ -15,10 +15,11 @@ use OpenTelemetry\SDK\Trace\Sampler\ParentBased; use OpenTelemetry\SDK\Trace\SamplerInterface; use OpenTelemetry\SDK\Trace\SamplingResult; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; -/** - * @coversDefaultClass \OpenTelemetry\SDK\Trace\Sampler\ParentBased - */ +#[CoversClass(ParentBased::class)] class ParentBasedTest extends MockeryTestCase { private SamplerInterface $rootSampler; @@ -29,20 +30,13 @@ public function setUp(): void $this->rootSampler->method('getDescription')->willReturn('Foo'); } - /** - * @covers ::getDescription - */ public function test_get_description(): void { $sampler = new ParentBased($this->rootSampler); $this->assertSame('ParentBased+Foo', $sampler->getDescription()); } - /** - * @covers ::shouldSample - * @covers ::__construct - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_parent_based_root_span(): void { $rootSampler = self::createMockSamplerInvokedOnce(SamplingResult::RECORD_AND_SAMPLE); @@ -60,10 +54,7 @@ public function test_parent_based_root_span(): void $this->assertSame(SamplingResult::RECORD_AND_SAMPLE, $decision->getDecision()); } - /** - * @covers ::shouldSample - * @dataProvider parentContextProvider - */ + #[DataProvider('parentContextProvider')] public function test_should_sample_parent_based( $parentContext, ?SamplerInterface $remoteParentSampled = null, diff --git a/tests/Unit/SDK/Trace/Sampler/TraceIdRatioBasedSamplerTest.php b/tests/Unit/SDK/Trace/Sampler/TraceIdRatioBasedSamplerTest.php index 7c258282c..bf43fc723 100644 --- a/tests/Unit/SDK/Trace/Sampler/TraceIdRatioBasedSamplerTest.php +++ b/tests/Unit/SDK/Trace/Sampler/TraceIdRatioBasedSamplerTest.php @@ -10,17 +10,13 @@ use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Trace\Sampler\TraceIdRatioBasedSampler; use OpenTelemetry\SDK\Trace\SamplingResult; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass OpenTelemetry\SDK\Trace\Sampler\TraceIdRatioBasedSampler - */ +#[CoversClass(TraceIdRatioBasedSampler::class)] class TraceIdRatioBasedSamplerTest extends TestCase { - /** - * @covers ::__construct - * @covers ::shouldSample - */ public function test_should_sample(): void { $sampler = new TraceIdRatioBasedSampler(1.0); @@ -35,10 +31,7 @@ public function test_should_sample(): void $this->assertEquals(SamplingResult::RECORD_AND_SAMPLE, $decision->getDecision()); } - /** - * @covers ::__construct - * @dataProvider invalidProbabilityProvider - */ + #[DataProvider('invalidProbabilityProvider')] public function test_invalid_probability_trace_id_ratio_based_sampler(float $probability): void { $this->expectException(InvalidArgumentException::class); @@ -53,9 +46,6 @@ public static function invalidProbabilityProvider(): array ]; } - /** - * @covers ::getDescription - */ public function test_get_description(): void { $sampler = new TraceIdRatioBasedSampler(0.0001); diff --git a/tests/Unit/SDK/Trace/SamplerFactoryTest.php b/tests/Unit/SDK/Trace/SamplerFactoryTest.php index 88ec591f6..6e73906a1 100644 --- a/tests/Unit/SDK/Trace/SamplerFactoryTest.php +++ b/tests/Unit/SDK/Trace/SamplerFactoryTest.php @@ -4,27 +4,19 @@ namespace OpenTelemetry\Tests\Unit\SDK\Trace; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use Exception; use OpenTelemetry\SDK\Trace\SamplerFactory; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass OpenTelemetry\SDK\Trace\SamplerFactory - */ +#[CoversClass(SamplerFactory::class)] class SamplerFactoryTest extends TestCase { - use EnvironmentVariables; + use TestState; - protected function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } - - /** - * @covers ::create - * @dataProvider samplerProvider - */ + #[DataProvider('samplerProvider')] public function test_create_sampler_from_environment(string $samplerName, string $expected, string $arg = null): void { $this->setEnvironmentVariable('OTEL_TRACES_SAMPLER', $samplerName); @@ -46,10 +38,7 @@ public static function samplerProvider(): array 'parent based trade id ratio' => ['parentbased_traceidratio', 'ParentBased+TraceIdRatio', '0.95'], ]; } - /** - * @covers ::create - * @dataProvider invalidSamplerProvider - */ + #[DataProvider('invalidSamplerProvider')] public function test_throws_exception_for_invalid_or_unsupported(?string $sampler, string $arg = null): void { $this->setEnvironmentVariable('OTEL_TRACES_SAMPLER', $sampler); diff --git a/tests/Unit/SDK/Trace/SamplingResultTest.php b/tests/Unit/SDK/Trace/SamplingResultTest.php index 7cb86814a..5c72e177c 100644 --- a/tests/Unit/SDK/Trace/SamplingResultTest.php +++ b/tests/Unit/SDK/Trace/SamplingResultTest.php @@ -7,16 +7,14 @@ use Mockery; use OpenTelemetry\API\Trace\TraceStateInterface; use OpenTelemetry\SDK\Trace\SamplingResult; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SamplingResult - */ +#[CoversClass(SamplingResult::class)] class SamplingResultTest extends TestCase { - /** - * @dataProvider provideAttributesAndLinks - */ + #[DataProvider('provideAttributesAndLinks')] public function test_attributes_and_links_getters($attributes, $traceState): void { $result = new SamplingResult(SamplingResult::DROP, $attributes, $traceState); diff --git a/tests/Unit/SDK/Trace/SpanBuilderTest.php b/tests/Unit/SDK/Trace/SpanBuilderTest.php index ea1cd16d0..205977293 100644 --- a/tests/Unit/SDK/Trace/SpanBuilderTest.php +++ b/tests/Unit/SDK/Trace/SpanBuilderTest.php @@ -18,12 +18,11 @@ use OpenTelemetry\SDK\Trace\SpanLimits; use OpenTelemetry\SDK\Trace\SpanProcessorInterface; use OpenTelemetry\SDK\Trace\TracerSharedState; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanBuilder - */ +#[CoversClass(SpanBuilder::class)] class SpanBuilderTest extends TestCase { private const TRACE_ID = 'e4a8d4e0d75c0702200af2882cb16c6b'; diff --git a/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTestCase.php b/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTestCase.php index ece1eb14d..92925e616 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTestCase.php +++ b/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTestCase.php @@ -13,6 +13,7 @@ use OpenTelemetry\SDK\Common\Future\FutureInterface; use OpenTelemetry\SDK\Trace\SpanExporterInterface; use OpenTelemetry\Tests\Unit\SDK\Util\SpanData; +use PHPUnit\Framework\Attributes\DataProvider; /** * @psalm-suppress UndefinedInterfaceMethod @@ -67,9 +68,7 @@ public function test_force_flush(): void ); } - /** - * @dataProvider futureProvider - */ + #[DataProvider('futureProvider')] public function test_export(FutureInterface $future, bool $expected): void { $transport = Mockery::mock(TransportInterface::class); diff --git a/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterFactoryTest.php b/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterFactoryTest.php index 502786f9f..280d44c1f 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterFactoryTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterFactoryTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporterFactory; use OpenTelemetry\SDK\Trace\SpanExporterInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporterFactory - */ +#[CoversClass(ConsoleSpanExporterFactory::class)] class ConsoleSpanExporterFactoryTest extends TestCase { public function test_create(): void diff --git a/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php b/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php index 046ec2af6..c317752c9 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php @@ -9,11 +9,12 @@ use OpenTelemetry\SDK\Trace\SpanDataInterface; use OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporter; use OpenTelemetry\SDK\Trace\SpanExporterInterface; +use PHPUnit\Framework\Attributes\CoversClass; /** - * @covers \OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporter * @psalm-suppress UndefinedInterfaceMethod */ +#[CoversClass(ConsoleSpanExporter::class)] class ConsoleSpanExporterTest extends AbstractExporterTestCase { public function createExporter(): ConsoleSpanExporter diff --git a/tests/Unit/SDK/Trace/SpanExporter/FriendlySpanConverterTest.php b/tests/Unit/SDK/Trace/SpanExporter/FriendlySpanConverterTest.php index 81086bf40..118ae66db 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/FriendlySpanConverterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/FriendlySpanConverterTest.php @@ -15,11 +15,10 @@ use OpenTelemetry\SDK\Trace\SpanDataInterface; use OpenTelemetry\SDK\Trace\SpanExporter\FriendlySpanConverter; use OpenTelemetry\SDK\Trace\StatusDataInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanExporter\FriendlySpanConverter - */ +#[CoversClass(FriendlySpanConverter::class)] class FriendlySpanConverterTest extends TestCase { private const TEST_DATA = [ diff --git a/tests/Unit/SDK/Trace/SpanExporter/InMemoryExporterTest.php b/tests/Unit/SDK/Trace/SpanExporter/InMemoryExporterTest.php index 1aba40b28..c3e669da9 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/InMemoryExporterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/InMemoryExporterTest.php @@ -9,16 +9,14 @@ use Mockery; use OpenTelemetry\SDK\Trace\SpanDataInterface; use OpenTelemetry\SDK\Trace\SpanExporter\InMemoryExporter; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanExporter\InMemoryExporter - */ +#[CoversClass(InMemoryExporter::class)] class InMemoryExporterTest extends TestCase { - /** - * @dataProvider provideSpans - */ + #[DataProvider('provideSpans')] public function test_export(iterable $spans): void { $instance = new InMemoryExporter(); diff --git a/tests/Unit/SDK/Trace/SpanExporter/InMemorySpanExporterFactoryTest.php b/tests/Unit/SDK/Trace/SpanExporter/InMemorySpanExporterFactoryTest.php index 82b0f768a..dec657b28 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/InMemorySpanExporterFactoryTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/InMemorySpanExporterFactoryTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\SDK\Trace\SpanExporter\InMemorySpanExporterFactory; use OpenTelemetry\SDK\Trace\SpanExporterInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanExporter\InMemorySpanExporterFactory - */ +#[CoversClass(InMemorySpanExporterFactory::class)] class InMemorySpanExporterFactoryTest extends TestCase { public function test_create(): void diff --git a/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php b/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php index 6642337d1..61cc1c121 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php @@ -7,12 +7,11 @@ use OpenTelemetry\SDK\Common\Future\CompletedFuture; use OpenTelemetry\SDK\Trace\SpanExporter\LoggerDecorator; use OpenTelemetry\SDK\Trace\SpanExporterInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LogLevel; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanExporter\LoggerDecorator - */ +#[CoversClass(LoggerDecorator::class)] class LoggerDecoratorTest extends AbstractLoggerAwareTestCase { /** diff --git a/tests/Unit/SDK/Trace/SpanExporter/LoggerExporterTest.php b/tests/Unit/SDK/Trace/SpanExporter/LoggerExporterTest.php index 1153fe22c..6b544d8f3 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/LoggerExporterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/LoggerExporterTest.php @@ -6,11 +6,10 @@ use Exception; use OpenTelemetry\SDK\Trace\SpanExporter\LoggerExporter; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanExporter\LoggerExporter - */ +#[CoversClass(\OpenTelemetry\SDK\Trace\SpanExporter\LoggerExporter::class)] class LoggerExporterTest extends TestCase { use LoggerAwareTestTrait; diff --git a/tests/Unit/SDK/Trace/SpanExporter/NullSpanConverterTest.php b/tests/Unit/SDK/Trace/SpanExporter/NullSpanConverterTest.php index b85bf04f5..11352d355 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/NullSpanConverterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/NullSpanConverterTest.php @@ -6,11 +6,10 @@ use OpenTelemetry\SDK\Trace\SpanDataInterface; use OpenTelemetry\SDK\Trace\SpanExporter\NullSpanConverter; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanExporter\NullSpanConverter - */ +#[CoversClass(NullSpanConverter::class)] class NullSpanConverterTest extends TestCase { public function test_convert(): void diff --git a/tests/Unit/SDK/Trace/SpanLimitsBuilderTest.php b/tests/Unit/SDK/Trace/SpanLimitsBuilderTest.php index 21eb9b02e..f3ab540e5 100644 --- a/tests/Unit/SDK/Trace/SpanLimitsBuilderTest.php +++ b/tests/Unit/SDK/Trace/SpanLimitsBuilderTest.php @@ -4,18 +4,18 @@ namespace OpenTelemetry\Tests\Unit\SDK\Trace; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use Exception; use OpenTelemetry\SDK\Common\Attribute\Attributes; use OpenTelemetry\SDK\Trace\SpanLimitsBuilder; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanLimitsBuilder - */ +#[CoversClass(SpanLimitsBuilder::class)] class SpanLimitsBuilderTest extends TestCase { - use EnvironmentVariables; + use TestState; public function test_span_limits_builder_uses_default_values(): void { @@ -25,9 +25,7 @@ public function test_span_limits_builder_uses_default_values(): void $this->assertEquals(Attributes::factory(128), $spanLimits->getAttributesFactory()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_limits_builder_uses_environment_variable(): void { $this->setEnvironmentVariable('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT', 111); @@ -37,9 +35,7 @@ public function test_span_limits_builder_uses_environment_variable(): void $this->assertEquals(Attributes::factory(111), $spanLimits->getAttributesFactory()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_limits_builder_uses_configured_value(): void { $this->setEnvironmentVariable('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT', 111); @@ -50,9 +46,7 @@ public function test_span_limits_builder_uses_configured_value(): void $this->assertEquals(Attributes::factory(222), $spanLimits->getAttributesFactory()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_span_limits_builder_throws_exception_on_invalid_value_from_environment(): void { $this->setEnvironmentVariable('OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT', 'fruit'); diff --git a/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorBuilderTest.php b/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorBuilderTest.php index 6a506b4c1..8b0baf532 100644 --- a/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorBuilderTest.php +++ b/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorBuilderTest.php @@ -8,11 +8,11 @@ use OpenTelemetry\SDK\Metrics\MeterProviderInterface; use OpenTelemetry\SDK\Trace\SpanExporterInterface; use OpenTelemetry\SDK\Trace\SpanProcessor\BatchSpanProcessor; +use OpenTelemetry\SDK\Trace\SpanProcessor\BatchSpanProcessorBuilder; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanProcessor\BatchSpanProcessorBuilder - */ +#[CoversClass(BatchSpanProcessorBuilder::class)] class BatchSpanProcessorBuilderTest extends TestCase { public function test_build(): void diff --git a/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorTest.php b/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorTest.php index 7e6190708..6fd6a804a 100644 --- a/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorTest.php +++ b/tests/Unit/SDK/Trace/SpanProcessor/BatchSpanProcessorTest.php @@ -31,12 +31,12 @@ use OpenTelemetry\SDK\Trace\SpanProcessor\BatchSpanProcessor; use OpenTelemetry\SDK\Trace\SpanProcessor\BatchSpanProcessorBuilder; use OpenTelemetry\SDK\Trace\SpanProcessorInterface; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LogLevel; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanProcessor\BatchSpanProcessor - */ +#[CoversClass(BatchSpanProcessor::class)] class BatchSpanProcessorTest extends MockeryTestCase { private TestClock $testClock; @@ -52,12 +52,6 @@ protected function setUp(): void Clock::setDefault($this->testClock); } - protected function tearDown(): void - { - Clock::reset(); - Logging::reset(); - } - public function test_export_batch_size_met(): void { $batchSize = 3; @@ -88,9 +82,7 @@ public function test_export_batch_size_met(): void } } - /** - * @dataProvider scheduledDelayProvider - */ + #[DataProvider('scheduledDelayProvider')] public function test_export_scheduled_delay(int $exportDelay, int $advanceByNano, bool $expectedFlush): void { $batchSize = 2; @@ -439,7 +431,7 @@ public function test_throwing_exporter_flush_rethrows_in_original_caller(): void { $processor = null; $exporter = $this->createMock(SpanExporterInterface::class); - $exporter->method('forceFlush')->willReturnCallback(function () use (&$processor) { + $exporter->method('forceFlush')->willReturnCallback(function () use (&$processor): never { /** @var SpanProcessorInterface $processor */ $span = $this->createSampledSpanMock(); $processor->onStart($span, Context::getCurrent()); @@ -461,9 +453,6 @@ public function test_throwing_exporter_flush_rethrows_in_original_caller(): void $processor->forceFlush(); } - /** - * @requires PHP >= 8.0 - */ public function test_self_diagnostics(): void { $clock = new TestClock(); diff --git a/tests/Unit/SDK/Trace/SpanProcessor/MultiSpanProcessorTest.php b/tests/Unit/SDK/Trace/SpanProcessor/MultiSpanProcessorTest.php index f2eff4c36..0139c03e7 100644 --- a/tests/Unit/SDK/Trace/SpanProcessor/MultiSpanProcessorTest.php +++ b/tests/Unit/SDK/Trace/SpanProcessor/MultiSpanProcessorTest.php @@ -9,12 +9,11 @@ use OpenTelemetry\SDK\Trace\ReadWriteSpanInterface; use OpenTelemetry\SDK\Trace\SpanProcessor\MultiSpanProcessor; use OpenTelemetry\SDK\Trace\SpanProcessorInterface; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanProcessor\MultiSpanProcessor - */ +#[CoversClass(MultiSpanProcessor::class)] class MultiSpanProcessorTest extends TestCase { private array $spanProcessors = []; @@ -142,11 +141,11 @@ private function createMultiSpanProcessor(): MultiSpanProcessor private function getSpanProcessors(): array { - return !empty($this->spanProcessors) - ? $this->spanProcessors - : $this->spanProcessors = [ + return $this->spanProcessors === [] + ? $this->spanProcessors = [ $this->createMock(SpanProcessorInterface::class), $this->createMock(SpanProcessorInterface::class), - ]; + ] + : $this->spanProcessors; } } diff --git a/tests/Unit/SDK/Trace/SpanProcessor/NoopSpanProcessorTest.php b/tests/Unit/SDK/Trace/SpanProcessor/NoopSpanProcessorTest.php index 5f2a681b6..c28c7ff8e 100644 --- a/tests/Unit/SDK/Trace/SpanProcessor/NoopSpanProcessorTest.php +++ b/tests/Unit/SDK/Trace/SpanProcessor/NoopSpanProcessorTest.php @@ -5,34 +5,24 @@ namespace OpenTelemetry\Tests\Unit\SDK\Trace\SpanProcessor; use OpenTelemetry\SDK\Trace\SpanProcessor\NoopSpanProcessor; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass OpenTelemetry\SDK\Trace\SpanProcessor\NoopSpanProcessor - */ +#[CoversClass(NoopSpanProcessor::class)] class NoopSpanProcessorTest extends TestCase { - /** - * @covers ::getInstance - */ public function test_get_instance(): void { $instance = NoopSpanProcessor::getInstance(); $this->assertSame($instance, NoopSpanProcessor::getInstance()); } - /** - * @covers ::forceFlush - */ public function test_force_flush(): void { $instance = NoopSpanProcessor::getInstance(); $this->assertTrue($instance->forceFlush()); } - /** - * @covers ::shutDown - */ public function test_shutdown(): void { $instance = NoopSpanProcessor::getInstance(); diff --git a/tests/Unit/SDK/Trace/SpanProcessor/SimpleSpanProcessorTest.php b/tests/Unit/SDK/Trace/SpanProcessor/SimpleSpanProcessorTest.php index 4442139f6..2f3a28f19 100644 --- a/tests/Unit/SDK/Trace/SpanProcessor/SimpleSpanProcessorTest.php +++ b/tests/Unit/SDK/Trace/SpanProcessor/SimpleSpanProcessorTest.php @@ -21,12 +21,11 @@ use OpenTelemetry\SDK\Trace\SpanExporterInterface; use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor; use OpenTelemetry\Tests\Unit\SDK\Util\SpanData; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LogLevel; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor - */ +#[CoversClass(SimpleSpanProcessor::class)] class SimpleSpanProcessorTest extends MockeryTestCase { private SimpleSpanProcessor $simpleSpanProcessor; @@ -64,11 +63,6 @@ protected function setUp(): void $this->simpleSpanProcessor = new SimpleSpanProcessor($this->spanExporter); } - public function tearDown(): void - { - Logging::reset(); - } - public function test_on_start(): void { $this->simpleSpanProcessor->onStart($this->readWriteSpan, Context::getRoot()); diff --git a/tests/Unit/SDK/Trace/SpanProcessorFactoryTest.php b/tests/Unit/SDK/Trace/SpanProcessorFactoryTest.php index c8f4ced5f..fe6b792b0 100644 --- a/tests/Unit/SDK/Trace/SpanProcessorFactoryTest.php +++ b/tests/Unit/SDK/Trace/SpanProcessorFactoryTest.php @@ -4,31 +4,26 @@ namespace OpenTelemetry\Tests\Unit\SDK\Trace; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use InvalidArgumentException; use OpenTelemetry\SDK\Trace\SpanExporterInterface; use OpenTelemetry\SDK\Trace\SpanProcessor\BatchSpanProcessor; use OpenTelemetry\SDK\Trace\SpanProcessor\NoopSpanProcessor; use OpenTelemetry\SDK\Trace\SpanProcessor\SimpleSpanProcessor; use OpenTelemetry\SDK\Trace\SpanProcessorFactory; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\SpanProcessorFactory - */ +#[CoversClass(SpanProcessorFactory::class)] class SpanProcessorFactoryTest extends TestCase { - use EnvironmentVariables; - - protected function tearDown(): void - { - $this->restoreEnvironmentVariables(); - } + use TestState; /** - * @dataProvider processorProvider * @psalm-suppress ArgumentTypeCoercion */ + #[DataProvider('processorProvider')] public function test_span_processor_factory_create_span_processor_from_environment(string $processorName, string $expected): void { $this->setEnvironmentVariable('OTEL_PHP_TRACES_PROCESSOR', $processorName); diff --git a/tests/Unit/SDK/Trace/SpanTest.php b/tests/Unit/SDK/Trace/SpanTest.php index 17beec2e3..077b9edee 100644 --- a/tests/Unit/SDK/Trace/SpanTest.php +++ b/tests/Unit/SDK/Trace/SpanTest.php @@ -38,13 +38,14 @@ use OpenTelemetry\SDK\Trace\SpanLimitsBuilder; use OpenTelemetry\SDK\Trace\SpanProcessorInterface; use OpenTelemetry\SDK\Trace\StatusData; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\MockObject\MockObject; use function range; use function str_repeat; -/** - * @covers \OpenTelemetry\SDK\Trace\Span - */ +#[CoversClass(Span::class)] class SpanTest extends MockeryTestCase { private const SPAN_NAME = 'test_span'; @@ -103,13 +104,6 @@ protected function setUp():void Logging::setLogWriter($this->logWriter); } - protected function tearDown(): void - { - Clock::reset(); - Logging::reset(); - // LoggerHolder::unset(); - } - // region API public function test_get_invalid_span(): void @@ -125,9 +119,7 @@ public function test_get_current_span_default(): void ); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_start_span(): void { $this->createTestSpan(API\SpanKind::KIND_INTERNAL); @@ -136,9 +128,7 @@ public function test_start_span(): void ->once(); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_end_span(): void { $span = $this->createTestSpan(API\SpanKind::KIND_CONSUMER); @@ -156,9 +146,7 @@ public function test_get_start_epoch_nanos(): void $this->assertSame(self::START_EPOCH, $span->getStartEpochNanos()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_get_current_span_set_span(): void { $span = Span::wrap(SpanContext::getInvalid()); @@ -217,12 +205,8 @@ public function test_in_process_context(): void } // endregion API - // region SDK - - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_nothing_changes_after_end(): void { $span = $this->createTestSpan(); @@ -254,10 +238,7 @@ public function test_end_twice(): void $this->assertTrue($span->hasEnded()); } - /** - * @group trace-compliance - * @covers \OpenTelemetry\SDK\Trace\Span::isRecording - */ + #[Group('trace-compliance')] public function test_to_span_data_active_span(): void { $span = $this->createTestSpan(); @@ -286,9 +267,7 @@ public function test_to_span_data_active_span(): void $this->assertFalse($span->isRecording()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_to_span_data_ended_span(): void { $span = $this->createTestSpan(); @@ -347,9 +326,7 @@ public function test_to_span_data_initial_attributes(): void $this->assertSame(0, $spanData->getAttributes()->getDroppedAttributesCount()); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_to_span_data_is_immutable(): void { $span = $this->createTestSpanWithAttributes(self::ATTRIBUTES); @@ -417,9 +394,7 @@ public function test_get_instrumentation_scope_info(): void $span->end(); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_update_span_name(): void { $span = $this->createTestRootSpan(); @@ -453,10 +428,7 @@ public function test_get_duration_ended_span(): void $this->assertSame($elapsedNanos, $span->getDuration()); } - /** - * @group trace-compliance - * @covers \OpenTelemetry\SDK\Trace\Span::setAttributes - */ + #[Group('trace-compliance')] public function test_set_attributes(): void { $span = $this->createTestRootSpan(); @@ -493,9 +465,7 @@ public function test_set_attributes_empty(): void $this->assertEmpty($span->toSpanData()->getAttributes()); } - /** - * @dataProvider nonHomogeneousArrayProvider - */ + #[DataProvider('nonHomogeneousArrayProvider')] public function test_set_attribute_drops_non_homogeneous_array(array $values): void { $this->logWriter->expects($this->once()) @@ -520,9 +490,7 @@ public static function nonHomogeneousArrayProvider(): array ]; } - /** - * @dataProvider homogeneousArrayProvider - */ + #[DataProvider('homogeneousArrayProvider')] public function test_set_attribute_with_homogeneous_array(array $values): void { $span = $this->createTestRootSpan(); @@ -542,10 +510,7 @@ public static function homogeneousArrayProvider(): array ]; } - /** - * @group trace-compliance - * @covers \OpenTelemetry\SDK\Trace\Span::addEvent - */ + #[Group('trace-compliance')] public function test_add_event(): void { $span = $this->createTestRootSpan(); @@ -600,9 +565,7 @@ public function test_add_event_attribute_length(): void $span->end(); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_record_exception(): void { $exception = new Exception('ERR'); @@ -688,9 +651,7 @@ public function test_attribute_length(): void $span->end(); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_dropping_attributes(): void { $maxNumberOfAttributes = 8; @@ -759,10 +720,7 @@ public function test_dropping_events(): void } // endregion SDK - - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_set_attributes_merges_attributes(): void { $span = $this->createTestRootSpan(); @@ -785,9 +743,7 @@ public function test_set_attributes_merges_attributes(): void $this->assertSame(['f', 'b'], $attributes->get('str_array')); } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_add_event_order_preserved(): void { $span = $this->createTestRootSpan(); @@ -805,12 +761,12 @@ public function test_add_event_order_preserved(): void } /** - * @dataProvider statusCodeProvider - * @group trace-compliance * @psalm-param StatusCode::STATUS_* $code * * When span status is set to Ok it SHOULD be considered final and any further attempts to change it SHOULD be ignored. */ + #[DataProvider('statusCodeProvider')] + #[Group('trace-compliance')] public function test_set_status_after_ok_is_ignored(string $code): void { $span = $this->createTestRootSpan(); @@ -830,9 +786,7 @@ public static function statusCodeProvider(): array ]; } - /** - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_can_set_status_to_ok_after_error(): void { $span = $this->createTestRootSpan(); diff --git a/tests/Unit/SDK/Trace/StatusDataTest.php b/tests/Unit/SDK/Trace/StatusDataTest.php index 98860938e..da3cdab1b 100644 --- a/tests/Unit/SDK/Trace/StatusDataTest.php +++ b/tests/Unit/SDK/Trace/StatusDataTest.php @@ -6,17 +6,18 @@ use OpenTelemetry\API\Trace\StatusCode; use OpenTelemetry\SDK\Trace\StatusData; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\StatusData - */ +#[CoversClass(StatusData::class)] class StatusDataTest extends TestCase { /** - * @dataProvider getStatuses * @psalm-param StatusCode::STATUS_* $code */ + #[DataProvider('getStatuses')] public function test_statuses(string $code): void { $status = StatusData::create($code, ''); @@ -38,10 +39,10 @@ public function test_statuses(string $code): void } /** - * @dataProvider getStatuses * @psalm-param StatusCode::STATUS_* $code - * @group trace-compliance */ + #[DataProvider('getStatuses')] + #[Group('trace-compliance')] public function test_statuses_description(string $code): void { $status = StatusData::create($code, 'ERR'); diff --git a/tests/Unit/SDK/Trace/TracerProviderFactoryTest.php b/tests/Unit/SDK/Trace/TracerProviderFactoryTest.php index 376a8fe80..46fd67581 100644 --- a/tests/Unit/SDK/Trace/TracerProviderFactoryTest.php +++ b/tests/Unit/SDK/Trace/TracerProviderFactoryTest.php @@ -4,7 +4,6 @@ namespace OpenTelemetry\Tests\Unit\SDK\Trace; -use AssertWell\PHPUnitGlobalState\EnvironmentVariables; use OpenTelemetry\API\Behavior\Internal\Logging; use OpenTelemetry\API\Behavior\Internal\LogWriter\LogWriterInterface; use OpenTelemetry\API\Trace\NoopTracerProvider; @@ -12,15 +11,15 @@ use OpenTelemetry\SDK\Trace\SamplerFactory; use OpenTelemetry\SDK\Trace\SpanProcessorFactory; use OpenTelemetry\SDK\Trace\TracerProviderFactory; +use OpenTelemetry\Tests\TestState; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\TracerProviderFactory - */ +#[CoversClass(TracerProviderFactory::class)] class TracerProviderFactoryTest extends TestCase { - use EnvironmentVariables; + use TestState; /** @var LogWriterInterface&MockObject $logWriter */ private LogWriterInterface $logWriter; @@ -31,12 +30,6 @@ public function setUp(): void Logging::setLogWriter($this->logWriter); } - public function tearDown(): void - { - Logging::reset(); - $this->restoreEnvironmentVariables(); - } - public function test_factory_creates_tracer(): void { $exporterFactory = $this->createMock(ExporterFactory::class); diff --git a/tests/Unit/SDK/Trace/TracerProviderTest.php b/tests/Unit/SDK/Trace/TracerProviderTest.php index f73116ccc..d83d4ccf0 100644 --- a/tests/Unit/SDK/Trace/TracerProviderTest.php +++ b/tests/Unit/SDK/Trace/TracerProviderTest.php @@ -7,17 +7,13 @@ use OpenTelemetry\API\Trace\NoopTracer; use OpenTelemetry\SDK\Trace\SamplerInterface; use OpenTelemetry\SDK\Trace\TracerProvider; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @coversDefaultClass \OpenTelemetry\SDK\Trace\TracerProvider - */ +#[CoversClass(TracerProvider::class)] class TracerProviderTest extends TestCase { - /** - * @covers ::getTracer - * @covers ::__construct - */ public function test_equal_for_same_name_without_version(): void { $provider = new TracerProvider(null); @@ -30,10 +26,6 @@ public function test_equal_for_same_name_without_version(): void $this->assertNotEquals($t1, $t3); } - /** - * @covers ::getTracer - * @covers ::__construct - */ public function test_equal_for_same_name_with_version(): void { $provider = new TracerProvider(null); @@ -46,11 +38,7 @@ public function test_equal_for_same_name_with_version(): void $this->assertNotEquals($t1, $t3); } - /** - * @covers ::getTracer - * @covers ::__construct - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_equal_for_same_name_with_schema_and_version(): void { $provider = new TracerProvider(null); @@ -63,10 +51,7 @@ public function test_equal_for_same_name_with_schema_and_version(): void $this->assertNotEquals($t1, $t3); } - /** - * @covers ::shutdown - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_shutdown(): void { $provider = new TracerProvider(null); @@ -76,10 +61,7 @@ public function test_shutdown(): void $this->assertTrue($provider->shutdown()); } - /** - * @covers ::forceFlush - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_force_flush(): void { $provider = new TracerProvider([]); @@ -89,9 +71,6 @@ public function test_force_flush(): void $this->assertTrue($provider->forceFlush()); } - /** - * @covers ::getSampler - */ public function test_get_sampler(): void { $sampler = $this->createMock(SamplerInterface::class); @@ -103,10 +82,7 @@ public function test_get_sampler(): void ); } - /** - * @covers ::getTracer - * @group trace-compliance - */ + #[Group('trace-compliance')] public function test_get_tracer_returns_noop_tracer_after_shutdown(): void { $provider = new TracerProvider([]); diff --git a/tests/Unit/SDK/Trace/TracerSharedStateTest.php b/tests/Unit/SDK/Trace/TracerSharedStateTest.php index 63b391d68..90eb45276 100644 --- a/tests/Unit/SDK/Trace/TracerSharedStateTest.php +++ b/tests/Unit/SDK/Trace/TracerSharedStateTest.php @@ -12,11 +12,10 @@ use OpenTelemetry\SDK\Trace\SpanProcessor\NoopSpanProcessor; use OpenTelemetry\SDK\Trace\SpanProcessorInterface; use OpenTelemetry\SDK\Trace\TracerSharedState; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\TracerSharedState - */ +#[CoversClass(TracerSharedState::class)] class TracerSharedStateTest extends TestCase { private IdGeneratorInterface $idGenerator; @@ -113,7 +112,7 @@ private function construct(array $spanProcessors = []): TracerSharedState $this->resourceInfo, $this->spanLimits, $this->sampler, - empty($spanProcessors) ? [new NoopSpanProcessor()] : $spanProcessors, + $spanProcessors === [] ? [new NoopSpanProcessor()] : $spanProcessors, ); } } diff --git a/tests/Unit/SDK/Trace/TracerTest.php b/tests/Unit/SDK/Trace/TracerTest.php index cb1fbf0ed..94341733e 100644 --- a/tests/Unit/SDK/Trace/TracerTest.php +++ b/tests/Unit/SDK/Trace/TracerTest.php @@ -8,11 +8,12 @@ use OpenTelemetry\SDK\Common\Instrumentation\InstrumentationScope; use OpenTelemetry\SDK\Trace\Tracer; use OpenTelemetry\SDK\Trace\TracerSharedState; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; -/** - * @covers \OpenTelemetry\SDK\Trace\Tracer - */ +#[CoversClass(Tracer::class)] class TracerTest extends TestCase { private Tracer $tracer; @@ -27,10 +28,10 @@ protected function setUp(): void } /** - * @dataProvider nameProvider * @param non-empty-string $name - * @group trace-compliance */ + #[DataProvider('nameProvider')] + #[Group('trace-compliance')] public function test_span_builder(string $name, string $expected): void { $spanBuilder = $this->tracer->spanBuilder($name); diff --git a/tests/Unit/SDK/Util/SpanData.php b/tests/Unit/SDK/Util/SpanData.php index fcba7b218..1c77f5531 100644 --- a/tests/Unit/SDK/Util/SpanData.php +++ b/tests/Unit/SDK/Util/SpanData.php @@ -32,7 +32,7 @@ class SpanData implements SDK\SpanDataInterface private array $links = []; private AttributesBuilderInterface $attributesBuilder; - private int $kind; + private int $kind = API\SpanKind::KIND_INTERNAL; private StatusData $status; private ResourceInfo $resource; private InstrumentationScope $instrumentationScope; @@ -47,7 +47,6 @@ class SpanData implements SDK\SpanDataInterface public function __construct() { $this->attributesBuilder = Attributes::factory()->builder(); - $this->kind = API\SpanKind::KIND_INTERNAL; $this->status = StatusData::unset(); $this->resource = ResourceInfoFactory::emptyResource(); $this->instrumentationScope = new InstrumentationScope('', null, null, Attributes::create([]));