diff --git a/composer.json b/composer.json index 79ee954d8..3865f61c3 100644 --- a/composer.json +++ b/composer.json @@ -91,11 +91,11 @@ "phpdocumentor/reflection-docblock": "^5.3", "phpmetrics/phpmetrics": "^2.8", "phpspec/prophecy": "^1.17.0", - "phpspec/prophecy-phpunit": "2.0.1", + "phpspec/prophecy-phpunit": "^2", "phpstan/phpstan": "^1.10.13", "phpstan/phpstan-mockery": "^1.1", "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.6", + "phpunit/phpunit": "^10", "psalm/plugin-mockery": "^1", "psalm/plugin-phpunit": "^0.18.4", "psalm/psalm": "^5", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fb770309b..9dca719cc 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,11 @@ - - - - - src - - - src/SDK/Common/Dev/Compatibility/BC - - - + cacheDirectory=".phpunit.cache" + backupStaticProperties="false" + requireCoverageMetadata="true"> - - - - - - - + + + + + + + - ./tests/Unit ./tests/Integration - ./tests/Integration/Context/Fiber + ./tests/Integration/Context/Fiber + + + src + + + src/SDK/Common/Dev/Compatibility/BC + + diff --git a/rector.php b/rector.php index 96ea2a92e..bb15476cb 100644 --- a/rector.php +++ b/rector.php @@ -9,6 +9,7 @@ use Rector\Config\RectorConfig; use Rector\Php81\Rector\ClassMethod\NewInInitializerRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; +use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; use Rector\ValueObject\PhpVersion; use Rector\Set\ValueObject\SetList; @@ -18,11 +19,13 @@ $rectorConfig->paths([ __DIR__ . '/src', + __DIR__ . '/tests', ]); $rectorConfig->sets([ SetList::PHP_81, SetList::CODE_QUALITY, + PHPUnitSetList::PHPUNIT_100, ]); $rectorConfig->skip([ CallableThisArrayToAnonymousFunctionRector::class => [ diff --git a/src/SDK/Registry.php b/src/SDK/Registry.php index d04b700ad..32ffe1522 100644 --- a/src/SDK/Registry.php +++ b/src/SDK/Registry.php @@ -89,22 +89,23 @@ public static function registerMetricExporterFactory(string $exporter, MetricExp self::$metricExporterFactories[$exporter] = $factory; } - public static function registerLogRecordExporterFactory(string $exporter, $factory, bool $clobber = false): void + /** + * @param LogRecordExporterFactoryInterface|class-string $factory + * @throws TypeError + */ + public static function registerLogRecordExporterFactory(string $exporter, LogRecordExporterFactoryInterface|string $factory, bool $clobber = false): void { if (!$clobber && array_key_exists($exporter, self::$logRecordExporterFactories)) { return; } if (!is_subclass_of($factory, LogRecordExporterFactoryInterface::class)) { - trigger_error( + throw new TypeError( sprintf( 'Cannot register LogRecord exporter factory: %s must exist and implement %s', is_string($factory) ? $factory : $factory::class, LogRecordExporterFactoryInterface::class - ), - E_USER_WARNING + ) ); - - return; } self::$logRecordExporterFactories[$exporter] = $factory; } diff --git a/tests/Integration/SDK/Context/SpanContextTest.php b/tests/Integration/SDK/Context/SpanContextTest.php index 6edf0f284..85493d47a 100644 --- a/tests/Integration/SDK/Context/SpanContextTest.php +++ b/tests/Integration/SDK/Context/SpanContextTest.php @@ -26,7 +26,7 @@ public function test_invalid_span(string $traceId, string $spanId): void $this->assertSame(SpanContextValidator::INVALID_SPAN, $spanContext->getSpanId()); } - public function invalidSpanData(): array + public static function invalidSpanData(): array { return [ // Too long TraceID diff --git a/tests/Integration/SDK/TracerTest.php b/tests/Integration/SDK/TracerTest.php index 4512885cc..e0596e13c 100644 --- a/tests/Integration/SDK/TracerTest.php +++ b/tests/Integration/SDK/TracerTest.php @@ -10,6 +10,7 @@ use OpenTelemetry\API\Trace\SpanContext; use OpenTelemetry\API\Trace\TraceState; use OpenTelemetry\Context\Context; +use OpenTelemetry\SDK\Common\Attribute\AttributesInterface; use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Trace\Sampler\AlwaysOffSampler; use OpenTelemetry\SDK\Trace\SamplerInterface; @@ -131,6 +132,7 @@ public function test_general_identity_attributes_are_dropped_by_default(): void $tracerProvider->shutdown(); + /** @var AttributesInterface $attributes */ $attributes = $exporter->getSpans()[0]->getAttributes(); $this->assertCount(0, $attributes); $this->assertSame(3, $attributes->getDroppedAttributesCount()); @@ -153,6 +155,7 @@ public function test_general_identity_attributes_are_retained_if_enabled(): void $tracerProvider->shutdown(); + /** @var AttributesInterface $attributes */ $attributes = $exporter->getSpans()[0]->getAttributes(); $this->assertCount(3, $attributes); $this->assertSame(0, $attributes->getDroppedAttributesCount()); diff --git a/tests/Unit/Context/DebugScopeTest.php b/tests/Unit/Context/DebugScopeTest.php index 2ffe6a1e3..90082a741 100644 --- a/tests/Unit/Context/DebugScopeTest.php +++ b/tests/Unit/Context/DebugScopeTest.php @@ -4,10 +4,10 @@ namespace OpenTelemetry\Tests\Unit\Context; +use Exception; use function ini_set; use OpenTelemetry\Context\Context; use OpenTelemetry\Context\DebugScope; -use PHPUnit\Framework\Exception as PHPUnitFrameworkException; use PHPUnit\Framework\TestCase; /** @@ -15,6 +15,17 @@ */ final class DebugScopeTest extends TestCase { + public function setUp(): void + { + set_error_handler(static function (int $errno, string $errstr): never { + throw new Exception($errstr, $errno); + }, E_USER_NOTICE); + } + + public function tearDown(): void + { + restore_error_handler(); + } /** * @covers \OpenTelemetry\Context\Context::activate @@ -70,7 +81,7 @@ public function test_detached_scope_detach(): void $scope1->detach(); - $this->expectException(PHPUnitFrameworkException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('already detached'); $scope1->detach(); } @@ -81,7 +92,7 @@ public function test_order_mismatch_scope_detach(): void $scope2 = Context::getCurrent()->activate(); try { - $this->expectException(PHPUnitFrameworkException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('another scope'); $scope1->detach(); } finally { @@ -97,7 +108,7 @@ public function test_inactive_scope_detach(): void Context::storage()->switch(1); try { - $this->expectException(PHPUnitFrameworkException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('different execution context'); $scope1->detach(); } finally { @@ -109,7 +120,7 @@ public function test_inactive_scope_detach(): void public function test_missing_scope_detach(): void { try { - $this->expectException(PHPUnitFrameworkException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('missing call'); Context::getCurrent()->activate(); } finally { diff --git a/tests/Unit/Context/Propagation/ArrayAccessGetterSetterTest.php b/tests/Unit/Context/Propagation/ArrayAccessGetterSetterTest.php index f37422db5..19af53a85 100644 --- a/tests/Unit/Context/Propagation/ArrayAccessGetterSetterTest.php +++ b/tests/Unit/Context/Propagation/ArrayAccessGetterSetterTest.php @@ -94,6 +94,9 @@ public function test_set_map_array_access(): void $this->assertSame('bravo', $value); } + /** + * @psalm-suppress InvalidArgument,UndefinedInterfaceMethod,PossiblyInvalidArrayAccess + */ public function test_set_map_array_access_case(): void { $carrier = new ArrayObject(['A' => 'alpha']); diff --git a/tests/Unit/Contrib/Otlp/HttpEndpointResolverTest.php b/tests/Unit/Contrib/Otlp/HttpEndpointResolverTest.php index c85d048ac..108160b38 100644 --- a/tests/Unit/Contrib/Otlp/HttpEndpointResolverTest.php +++ b/tests/Unit/Contrib/Otlp/HttpEndpointResolverTest.php @@ -76,7 +76,7 @@ public function test_normalize_throws_exception_on_invalid_url(string $signal): ->resolve('/\/', $signal); } - public function provideEndpoints(): Generator + public static function provideEndpoints(): Generator { foreach (self::DEFAULT_PATHS as $signal => $path) { $baseEndpoint = 'http://collector'; @@ -113,14 +113,14 @@ public function test_references_are_correct(array $values, array $reference): vo ); } - public function provideSignals(): Generator + public static function provideSignals(): Generator { foreach (self::SIGNALS as $signal) { yield [$signal]; } } - public function provideSchemes(): Generator + public static function provideSchemes(): Generator { foreach (self::VALID_SCHEMES as $scheme) { yield [$scheme]; diff --git a/tests/Unit/Contrib/Zipkin/ZipkinExporterTest.php b/tests/Unit/Contrib/Zipkin/ZipkinExporterTest.php index 018d8220a..7c990226d 100644 --- a/tests/Unit/Contrib/Zipkin/ZipkinExporterTest.php +++ b/tests/Unit/Contrib/Zipkin/ZipkinExporterTest.php @@ -7,12 +7,12 @@ use OpenTelemetry\Contrib\Zipkin\Exporter; use OpenTelemetry\SDK\Common\Export\TransportInterface; -use OpenTelemetry\Tests\Unit\SDK\Trace\SpanExporter\AbstractExporterTest; +use OpenTelemetry\Tests\Unit\SDK\Trace\SpanExporter\AbstractExporterTestCase; /** * @covers \OpenTelemetry\Contrib\Zipkin\Exporter */ -class ZipkinExporterTest extends AbstractExporterTest +class ZipkinExporterTest extends AbstractExporterTestCase { /** * @psalm-suppress PossiblyInvalidArgument diff --git a/tests/Unit/Contrib/Zipkin/ZipkinSpanConverterTest.php b/tests/Unit/Contrib/Zipkin/ZipkinSpanConverterTest.php index 60217441d..cbf33217d 100644 --- a/tests/Unit/Contrib/Zipkin/ZipkinSpanConverterTest.php +++ b/tests/Unit/Contrib/Zipkin/ZipkinSpanConverterTest.php @@ -202,6 +202,9 @@ public function test_should_use_otel_ipv_6_correctly_for_zipkin_remote_endpoint( $this->assertSame('00000000000000000000000000000001', bin2hex($row['remoteEndpoint']['ipv6'])); //Couldn't figure out how to do a direct assertion against binary data } + /** + * @psalm-suppress UndefinedInterfaceMethod,PossiblyInvalidArrayAccess + */ public function test_tags_are_coerced_correctly_to_strings(): void { $listOfStrings = ['string-1', 'string-2']; diff --git a/tests/Unit/Extension/Propagator/CloudTrace/CloudTraceFormatterTest.php b/tests/Unit/Extension/Propagator/CloudTrace/CloudTraceFormatterTest.php index 7e7f13467..2b4e2aad9 100644 --- a/tests/Unit/Extension/Propagator/CloudTrace/CloudTraceFormatterTest.php +++ b/tests/Unit/Extension/Propagator/CloudTrace/CloudTraceFormatterTest.php @@ -27,7 +27,7 @@ public function test_deserialize(string $header, string $traceId, string $spanId $this->assertEquals($result->getTraceFlags(), $sample, "Given deserialize($header), traceFlags != $sample (result={$result->getTraceFlags()}"); } - public function for_test_deserialize() : array + public static function for_test_deserialize() : array { return [ ['00000000000000000000000000000001/1;o=0', '00000000000000000000000000000001', '0000000000000001', 0], @@ -44,7 +44,7 @@ public function test_serialize(SpanContextInterface $span, string $header) : voi $this->assertEquals($result, $header, "Given serialize(header), result != $header (result=$result"); } - public function for_test_serialize() : array + public static function for_test_serialize() : array { return [ [SpanContext::createFromRemoteParent('00000000000000000000000000000001', '0000000000000001', TraceFlags::DEFAULT), '00000000000000000000000000000001/1;o=0'], diff --git a/tests/Unit/Extension/Propagator/CloudTrace/UtilsTest.php b/tests/Unit/Extension/Propagator/CloudTrace/UtilsTest.php index 5cb093e6a..cf27a4c3c 100644 --- a/tests/Unit/Extension/Propagator/CloudTrace/UtilsTest.php +++ b/tests/Unit/Extension/Propagator/CloudTrace/UtilsTest.php @@ -21,7 +21,7 @@ public function test_left_zero_pad(string $pad, int $howMuch, string $equalsTo) $this->assertEquals(Utils::leftZeroPad($pad, $howMuch), $equalsTo, "Given leftZeroPad($pad, $howMuch) != $equalsTo"); } - public function for_test_left_zero_pad() : array + public static function for_test_left_zero_pad() : array { return [ ['a', 3, '00a'], @@ -39,7 +39,7 @@ public function test_dec_to_hex(string $decNum, string $equalsTo) : void $this->assertEquals(Utils::decToHex($decNum), $equalsTo, "Given decToHex($decNum) != $equalsTo"); } - public function for_test_dec_to_hex() : array + public static function for_test_dec_to_hex() : array { return [ ['10', 'a'], @@ -58,7 +58,7 @@ public function test_hex_to_dec(string $hexNum, string $equalsTo) : void $this->assertEquals(Utils::hexToDec($hexNum), $equalsTo, "Given hexToDec($hexNum) != $equalsTo"); } - public function for_test_hex_to_dec() : array + public static function for_test_hex_to_dec() : array { return [ ['a', '10'], @@ -84,7 +84,7 @@ public function test_is_big_num($num, bool $equalsTo) : void $this->assertEquals(Utils::isBigNum($num), $equalsTo, "Given isBigNum($num) != $equalsTo"); } - public function for_test_is_big_num() : array + public static function for_test_is_big_num() : array { return [ [-100.5, false], @@ -108,7 +108,7 @@ public function test_base_convert(string $num, int $fromBase, int $toBase, strin $this->assertEquals($result, $equalsTo, "Given baseConvert($num, $fromBase, $toBase) != $equalsTo (result=$result)"); } - public function for_test_base_convert() : array + public static function for_test_base_convert() : array { return [ ['b', 16, 10, '11'], diff --git a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/DependencyResolverTest.php b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/DependencyResolverTest.php index 4b1f10e94..a041b8579 100644 --- a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/DependencyResolverTest.php +++ b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/DependencyResolverTest.php @@ -6,6 +6,7 @@ use Generator; use Http\Client\HttpAsyncClient; +use Mockery; use OpenTelemetry\SDK\Common\Adapter\HttpDiscovery\DependencyResolver; use OpenTelemetry\SDK\Common\Http\HttpPlug\Client\ResolverInterface as HttpPlugClientResolverInterface; use OpenTelemetry\SDK\Common\Http\Psr\Client\ResolverInterface as PsrClientResolverInterface; @@ -60,18 +61,18 @@ public function test_resolve(string $method, object $dependency, array $argument ); } - public function provideDependencies(): Generator + public static function provideDependencies(): Generator { $arguments = []; $dependencies = []; foreach (self::DEPENDENCIES as $resolverInterface => $interfaces) { - $resolver = $this->createMock($resolverInterface); + $resolver = Mockery::mock($resolverInterface); foreach ($interfaces as $interface) { - $method = $this->resolveMethodName($interface, self::METHOD_NAME_REPLACEMENTS[$resolverInterface]); - $dependency = $this->createMock($interface); - $resolver->method($method)->willReturn($dependency); + $method = self::resolveMethodName($interface, self::METHOD_NAME_REPLACEMENTS[$resolverInterface]); + $dependency = Mockery::mock($interface); + $resolver->allows([$method => $dependency]); $dependencies[$method] = $dependency; } @@ -86,7 +87,7 @@ public function provideDependencies(): Generator /** * @psalm-param class-string $interface */ - private function resolveMethodName(string $interface, array $replacements = []): string + private static function resolveMethodName(string $interface, array $replacements = []): string { $interface = (new ReflectionClass($interface))->getShortName(); diff --git a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php index e5dee1269..bdec83602 100644 --- a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php +++ b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php @@ -5,8 +5,9 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Adapter\HttpDiscovery; use Generator; -use Http\Discovery\HttpClientDiscovery; +use Http\Discovery\Psr18ClientDiscovery; use Http\Discovery\Strategy\MockClientStrategy; +use Mockery; use OpenTelemetry\SDK\Common\Adapter\HttpDiscovery\MessageFactoryResolver; use PHPUnit\Framework\TestCase; use Psr\Http\Message\RequestFactoryInterface; @@ -33,7 +34,7 @@ class MessageFactoryResolverTest extends TestCase public function setUp(): void { - HttpClientDiscovery::prependStrategy(MockClientStrategy::class); + Psr18ClientDiscovery::prependStrategy(MockClientStrategy::class); } /** @@ -49,12 +50,12 @@ public function test_resolve(string $method, object $dependency, array $argument ); } - public function provideDependencies(): Generator + public static function provideDependencies(): Generator { $dependencies = []; foreach (self::DEPENDENCIES as $interface) { - $dependencies[$this->resolveMethodName($interface)] = $this->createMock($interface); + $dependencies[self::resolveMethodName($interface)] = Mockery::mock($interface); } foreach ($dependencies as $method => $dependency) { @@ -65,7 +66,7 @@ public function provideDependencies(): Generator /** * @psalm-param class-string $interface */ - private function resolveMethodName(string $interface): string + private static function resolveMethodName(string $interface): string { return sprintf( 'resolve%s', diff --git a/tests/Unit/SDK/Common/Configuration/ConfigurationTest.php b/tests/Unit/SDK/Common/Configuration/ConfigurationTest.php index 25a19a933..994186782 100644 --- a/tests/Unit/SDK/Common/Configuration/ConfigurationTest.php +++ b/tests/Unit/SDK/Common/Configuration/ConfigurationTest.php @@ -123,7 +123,7 @@ public function test_integer_failure(): void Configuration::getInt('OTEL_FOO', 99); } - public function environment_variables_integer_uses_default_if_env_var_not_defined() + public function environment_variables_integer_uses_default_if_env_var_not_defined(): void { $this->assertSame(20, Configuration::getInt('OTEL_FOO', 20)); } @@ -166,7 +166,7 @@ public function test_bool_uses_default_when_empty_value(?string $input): void $this->assertTrue($value); } - public function emptyProvider() + public static function emptyProvider(): array { return [ 'no value' => [null], @@ -177,13 +177,13 @@ public function emptyProvider() /** * @dataProvider booleanProvider */ - public function test_bool_get(string $input, bool $default, bool $expected) + public function test_bool_get(string $input, bool $default, bool $expected): void { $this->setEnvironmentVariable('OTEL_BOOL', $input); $this->assertSame($expected, Configuration::getBoolean('OTEL_BOOL', $default)); } - public function booleanProvider() + public static function booleanProvider(): array { return [ 'false' => ['false', true, false], @@ -193,25 +193,25 @@ public function booleanProvider() ]; } - public function test_list_get() + public function test_list_get(): void { $this->setEnvironmentVariable('OTEL_LIST', 'a,b,c'); $this->assertSame(['a', 'b', 'c'], Configuration::getList('OTEL_LIST')); } - public function test_map_get() + public function test_map_get(): void { $this->setEnvironmentVariable('OTEL_MAP', 'a=b,c=d'); $this->assertSame(['a'=>'b', 'c'=>'d'], Configuration::getMap('OTEL_MAP')); } - public function test_enum_get() + public function test_enum_get(): void { $this->setEnvironmentVariable('OTEL_ENUM', 'foo'); $this->assertSame('foo', Configuration::getEnum('OTEL_ENUM')); } - public function test_ratio_get() + public function test_ratio_get(): void { $this->setEnvironmentVariable('OTEL_RATIO', '0.5'); $this->assertSame(0.5, Configuration::getRatio('OTEL_RATIO')); @@ -220,7 +220,7 @@ public function test_ratio_get() /** * @dataProvider userEnvValueProvider */ - public function test_return_user_env_vars(string $methodName, string $variable, string $value, $result) + public function test_return_user_env_vars(string $methodName, string $variable, string $value, $result): void { $this->setEnvironmentVariable($variable, $value); @@ -233,7 +233,7 @@ public function test_return_user_env_vars(string $methodName, string $variable, /** * @dataProvider userValueProvider */ - public function test_return_user_default_value(string $methodName, string $variable, $defaultValue, $result) + public function test_return_user_default_value(string $methodName, string $variable, $defaultValue, $result): void { $this->assertSame( $result, @@ -244,7 +244,7 @@ public function test_return_user_default_value(string $methodName, string $varia /** * @dataProvider libraryDefaultValueProvider */ - public function test_return_library_default_value(string $methodName, string $variable, $result) + public function test_return_library_default_value(string $methodName, string $variable, $result): void { $this->assertSame( $result, @@ -255,7 +255,7 @@ public function test_return_library_default_value(string $methodName, string $va /** * @dataProvider nonEmptyMethodNameProvider */ - public function test_no_value_throws_exception(string $methodName) + public function test_no_value_throws_exception(string $methodName): void { $this->expectException(UnexpectedValueException::class); @@ -265,7 +265,7 @@ public function test_no_value_throws_exception(string $methodName) /** * @dataProvider invalidTypeProvider */ - public function test_invalid_type_throws_exception(string $methodName, string $variable) + public function test_invalid_type_throws_exception(string $methodName, string $variable): void { $this->expectException(UnexpectedValueException::class); @@ -275,14 +275,14 @@ public function test_invalid_type_throws_exception(string $methodName, string $v /** * @dataProvider noDefaultProvider */ - public function test_null_result_throws_exception(string $methodName, string $variable) + public function test_null_result_throws_exception(string $methodName, string $variable): void { $this->expectException(UnexpectedValueException::class); call_user_func([Configuration::class, $methodName], $variable); } - public function userValueProvider(): Generator + public static function userValueProvider(): Generator { foreach (self::USER_VALUES as $varType => $values) { [$default, $result] = $values; @@ -296,7 +296,7 @@ public function userValueProvider(): Generator } } - public function userEnvValueProvider(): Generator + public static function userEnvValueProvider(): Generator { foreach (self::USER_ENV_VALUES as $varType => $values) { [$default, $result] = $values; @@ -310,7 +310,7 @@ public function userEnvValueProvider(): Generator } } - public function libraryDefaultValueProvider(): Generator + public static function libraryDefaultValueProvider(): Generator { foreach (self::LIBRARY_DEFAULTS as $varType => $values) { [$variable, $result] = $values; @@ -323,7 +323,7 @@ public function libraryDefaultValueProvider(): Generator } } - public function nonEmptyMethodNameProvider(): Generator + public static function nonEmptyMethodNameProvider(): Generator { foreach (self::METHOD_NAMES as $varType => $names) { if (in_array($varType, self::ALLOW_EMPTY)) { @@ -334,7 +334,7 @@ public function nonEmptyMethodNameProvider(): Generator } } - public function invalidTypeProvider(): Generator + public static function invalidTypeProvider(): Generator { foreach (self::METHOD_NAMES as $varType => $names) { if ($varType === VariableTypes::MIXED) { @@ -352,7 +352,7 @@ public function invalidTypeProvider(): Generator } } - public function noDefaultProvider(): Generator + public static function noDefaultProvider(): Generator { foreach (self::NO_DEFAULTS as $varType => $values) { if (in_array($varType, self::ALLOW_EMPTY)) { @@ -380,7 +380,7 @@ public function test_get_known_values(string $varName, array $varValue): void ); } - public function knownValuesProvider(): array + public static function knownValuesProvider(): array { return self::KNOWN_VALUES; } @@ -411,7 +411,7 @@ public function test_get_type(string $varName, string $type): void ); } - public function typeProvider(): array + public static function typeProvider(): array { return [ 'bool' => ['OTEL_EXPORTER_OTLP_INSECURE', VariableTypes::BOOL], @@ -448,7 +448,7 @@ public function test_get_default_value(string $varName, $varValue): void ); } - public function defaultValueProvider(): array + public static function defaultValueProvider(): array { return self::DEFAULT_VALUES; } @@ -463,7 +463,7 @@ public function test_get_non_string_value(string $method, $value): void $this->assertSame($value, call_user_func([Configuration::class, $method], 'OTEL_FOO')); } - public function nonStringProvider(): array + public static function nonStringProvider(): array { return [ ['getFloat', 3.14159], diff --git a/tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php b/tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php index ed4782110..97fde7e44 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php +++ b/tests/Unit/SDK/Common/Configuration/Parser/BooleanParserTest.php @@ -71,7 +71,7 @@ public function test_disallowed_boolean_type_values_throw_exception(string $valu BooleanParser::parse($value); } - public function disallowedBooleanProvider(): array + public static function disallowedBooleanProvider(): array { return self::DISALLOWED_BOOLEAN_VALUES; } @@ -86,17 +86,17 @@ public function test_non_boolean_values_throw_exception(string $value): void BooleanParser::parse($value); } - public function truthyValueProvider(): array + public static function truthyValueProvider(): array { return self::TRUTHY_VALUES; } - public function falsyValueProvider(): array + public static function falsyValueProvider(): array { return self::FALSY_VALUES; } - public function nonBooleanValueProvider(): array + public static function nonBooleanValueProvider(): array { return self::NON_BOOLEAN_VALUES; } diff --git a/tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php b/tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php index 79bb0f059..17eb7a834 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php +++ b/tests/Unit/SDK/Common/Configuration/Parser/ListParserTest.php @@ -45,7 +45,7 @@ public function test_comma_separated_list_returns_array(string $value, array $ex ); } - public function listValueProvider(): array + public static function listValueProvider(): array { return self::LIST_VALUES; } diff --git a/tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php b/tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php index 0690c02bc..85f8f941f 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php +++ b/tests/Unit/SDK/Common/Configuration/Parser/MapParserTest.php @@ -61,12 +61,12 @@ public function test_invalid_values_throw_exception(string $value): void \OpenTelemetry\SDK\Common\Configuration\Parser\MapParser::parse($value); } - public function mapValueProvider(): array + public static function mapValueProvider(): array { return self::MAP_VALUES; } - public function invalidValueProvider(): array + public static function invalidValueProvider(): array { return self::INVALID_VALUES; } diff --git a/tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php b/tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php index 35dee3c04..36300225b 100644 --- a/tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php +++ b/tests/Unit/SDK/Common/Configuration/Parser/RatioParserTest.php @@ -60,17 +60,17 @@ public function test_out_of_range_values_throw_exception(string $value): void RatioParser::parse($value); } - public function ratioValueProvider(): array + public static function ratioValueProvider(): array { return self::RATIO_VALUES; } - public function nonNumericValueProvider(): array + public static function nonNumericValueProvider(): array { return self::NON_NUMERIC_VALUES; } - public function outOfRangeValueProvider(): array + public static function outOfRangeValueProvider(): array { return self::OUT_OF_RANGE_VALUES; } diff --git a/tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php b/tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php index 70bbe1c92..74d8d5c0f 100644 --- a/tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php +++ b/tests/Unit/SDK/Common/Configuration/Resolver/CompositeResolverTest.php @@ -82,7 +82,7 @@ public function test_resolve_uses_library_default_when_empty(?string $value): vo $this->assertSame(Defaults::OTEL_EXPORTER_OTLP_PROTOCOL, $this->resolver->resolve(Variables::OTEL_EXPORTER_OTLP_PROTOCOL, $value)); } - public function emptyProvider(): array + public static function emptyProvider(): array { return [ [''], diff --git a/tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php b/tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php index 3be3a939a..280c21476 100644 --- a/tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php +++ b/tests/Unit/SDK/Common/Configuration/Resolver/EnvironmentResolverTest.php @@ -102,7 +102,7 @@ public function test_retrieve_value_with_injected_value(): void ); } - public function rawValueProvider(): array + public static function rawValueProvider(): array { return self::RAW_VALUES; } diff --git a/tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php b/tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php index ae45fe233..33b7489fc 100644 --- a/tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php +++ b/tests/Unit/SDK/Common/Configuration/Resolver/PhpIniResolverTest.php @@ -44,7 +44,7 @@ public function test_has_variable($value, bool $expected): void $this->assertSame($expected, $this->resolver->hasVariable('OTEL_FOO')); } - public function hasVariableProvider(): array + public static function hasVariableProvider(): array { return [ 'string' => ['foo', true], diff --git a/tests/Unit/SDK/Common/Dev/Compatibility/UtilTest.php b/tests/Unit/SDK/Common/Dev/Compatibility/UtilTest.php index 90dc7abc1..6243868a3 100644 --- a/tests/Unit/SDK/Common/Dev/Compatibility/UtilTest.php +++ b/tests/Unit/SDK/Common/Dev/Compatibility/UtilTest.php @@ -4,9 +4,9 @@ namespace OpenTelemetry\Tests\Unit\SDK\Common\Dev\Compatibility; +use Exception; use Generator; use OpenTelemetry\SDK\Common\Dev\Compatibility\Util; -use PHPUnit\Framework\Exception as PHPUnitFrameworkException; use PHPUnit\Framework\TestCase; /** @@ -14,9 +14,17 @@ */ class UtilTest extends TestCase { + public function setUp(): void + { + set_error_handler(static function (int $errno, string $errstr): never { + throw new Exception($errstr, $errno); + }, E_USER_WARNING|E_USER_NOTICE|E_USER_ERROR|E_USER_DEPRECATED); + } + public function tearDown(): void { Util::setErrorLevel(); + restore_error_handler(); } /** @@ -46,7 +54,7 @@ public function test_trigger_class_deprecation_notice(int $level): void { Util::setErrorLevel($level); - $this->expectException(PHPUnitFrameworkException::class); + $this->expectException(Exception::class); Util::triggerClassDeprecationNotice(Util::class, self::class); } @@ -58,7 +66,7 @@ public function test_trigger_method_deprecation_notice_without_class(int $level) { Util::setErrorLevel($level); - $this->expectException(PHPUnitFrameworkException::class); + $this->expectException(Exception::class); Util::triggerMethodDeprecationNotice(Util::class, __METHOD__); } @@ -70,7 +78,7 @@ public function test_trigger_method_deprecation_notice_with_class(int $level): v { Util::setErrorLevel($level); - $this->expectException(PHPUnitFrameworkException::class); + $this->expectException(Exception::class); Util::triggerMethodDeprecationNotice(Util::class, 'foo', self::class); } diff --git a/tests/Unit/SDK/FactoryRegistryTest.php b/tests/Unit/SDK/FactoryRegistryTest.php index c42d9cf45..698f98a97 100644 --- a/tests/Unit/SDK/FactoryRegistryTest.php +++ b/tests/Unit/SDK/FactoryRegistryTest.php @@ -10,7 +10,6 @@ use OpenTelemetry\SDK\Metrics\MetricExporterFactoryInterface; use OpenTelemetry\SDK\Registry; use OpenTelemetry\SDK\Trace\SpanExporter\SpanExporterFactoryInterface; -use PHPUnit\Framework\Exception as PHPUnitFrameworkException; use PHPUnit\Framework\TestCase; use TypeError; @@ -149,7 +148,7 @@ public function test_register_invalid_metric_exporter_factory($factory): void */ public function test_register_invalid_log_record_exporter_factory($factory): void { - $this->expectException(PHPUnitFrameworkException::class); + $this->expectException(TypeError::class); Registry::registerLogRecordExporterFactory('foo', $factory, true); } diff --git a/tests/Unit/SDK/Metrics/Stream/MetricStreamTest.php b/tests/Unit/SDK/Metrics/Stream/MetricStreamTest.php index 651bc77de..08b4839ba 100644 --- a/tests/Unit/SDK/Metrics/Stream/MetricStreamTest.php +++ b/tests/Unit/SDK/Metrics/Stream/MetricStreamTest.php @@ -19,7 +19,6 @@ use OpenTelemetry\SDK\Metrics\Stream\MetricAggregator; use OpenTelemetry\SDK\Metrics\Stream\SynchronousMetricStream; use const PHP_INT_SIZE; -use PHPUnit\Framework\Exception as PHPUnitFrameworkException; use PHPUnit\Framework\TestCase; /** @@ -296,9 +295,8 @@ public function test_synchronous_reader_limit_exceeded_triggers_warning(): void $s->register(Temporality::DELTA); } - $this->expectException(PHPUnitFrameworkException::class); - $this->expectExceptionMessageMatches('/^GMP extension required to register over \d++ readers$/'); - $s->register(Temporality::DELTA); + $r = $s->register(Temporality::DELTA); + $this->assertSame(PHP_INT_SIZE << 3, $r); } public function test_synchronous_reader_limit_exceeded_returns_noop_reader(): void diff --git a/tests/Unit/SDK/Trace/SamplingResultTest.php b/tests/Unit/SDK/Trace/SamplingResultTest.php index 944d3d58e..7cb86814a 100644 --- a/tests/Unit/SDK/Trace/SamplingResultTest.php +++ b/tests/Unit/SDK/Trace/SamplingResultTest.php @@ -4,6 +4,7 @@ namespace OpenTelemetry\Tests\Unit\SDK\Trace; +use Mockery; use OpenTelemetry\API\Trace\TraceStateInterface; use OpenTelemetry\SDK\Trace\SamplingResult; use PHPUnit\Framework\TestCase; @@ -27,12 +28,12 @@ public function test_attributes_and_links_getters($attributes, $traceState): voi /** * Provide different sets of data to test SamplingResult constructor and getters */ - public function provideAttributesAndLinks(): array + public static function provideAttributesAndLinks(): array { return [ [ ['foo' => 'bar'], - $this->createMock(TraceStateInterface::class), + Mockery::mock(TraceStateInterface::class), ], [ [], diff --git a/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTest.php b/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTestCase.php similarity index 97% rename from tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTest.php rename to tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTestCase.php index 8a07146c2..ecc89bcb8 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/AbstractExporterTestCase.php @@ -18,7 +18,7 @@ /** * @psalm-suppress UndefinedInterfaceMethod */ -abstract class AbstractExporterTest extends MockeryTestCase +abstract class AbstractExporterTestCase extends MockeryTestCase { protected TransportInterface $transport; protected FutureInterface $future; diff --git a/tests/Unit/SDK/Trace/SpanExporter/AbstractLoggerAwareTest.php b/tests/Unit/SDK/Trace/SpanExporter/AbstractLoggerAwareTestCase.php similarity index 72% rename from tests/Unit/SDK/Trace/SpanExporter/AbstractLoggerAwareTest.php rename to tests/Unit/SDK/Trace/SpanExporter/AbstractLoggerAwareTestCase.php index d09fb1c86..2f046ac90 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/AbstractLoggerAwareTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/AbstractLoggerAwareTestCase.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; -abstract class AbstractLoggerAwareTest extends TestCase +abstract class AbstractLoggerAwareTestCase extends TestCase { use LoggerAwareTestTrait; } diff --git a/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php b/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php index bbf507287..046ec2af6 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/ConsoleSpanExporterTest.php @@ -14,7 +14,7 @@ * @covers \OpenTelemetry\SDK\Trace\SpanExporter\ConsoleSpanExporter * @psalm-suppress UndefinedInterfaceMethod */ -class ConsoleSpanExporterTest extends AbstractExporterTest +class ConsoleSpanExporterTest extends AbstractExporterTestCase { public function createExporter(): ConsoleSpanExporter { diff --git a/tests/Unit/SDK/Trace/SpanExporter/InMemoryExporterTest.php b/tests/Unit/SDK/Trace/SpanExporter/InMemoryExporterTest.php index daa3f64e3..1aba40b28 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/InMemoryExporterTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/InMemoryExporterTest.php @@ -6,6 +6,7 @@ use ArrayObject; use Generator; +use Mockery; use OpenTelemetry\SDK\Trace\SpanDataInterface; use OpenTelemetry\SDK\Trace\SpanExporter\InMemoryExporter; use PHPUnit\Framework\TestCase; @@ -50,12 +51,12 @@ public function test_get_spans(): void ); } - public function provideSpans(): Generator + public static function provideSpans(): Generator { $spans = []; for ($x = 0; $x < 3; $x++) { - $spans[] = $this->createMock(SpanDataInterface::class); + $spans[] = Mockery::mock(SpanDataInterface::class); yield $x => [$spans]; } diff --git a/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php b/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php index ad4ba3f05..6642337d1 100644 --- a/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php +++ b/tests/Unit/SDK/Trace/SpanExporter/LoggerDecoratorTest.php @@ -13,7 +13,7 @@ /** * @covers \OpenTelemetry\SDK\Trace\SpanExporter\LoggerDecorator */ -class LoggerDecoratorTest extends AbstractLoggerAwareTest +class LoggerDecoratorTest extends AbstractLoggerAwareTestCase { /** * @var SpanExporterInterface|null diff --git a/tests/Unit/SDK/Trace/StatusDataTest.php b/tests/Unit/SDK/Trace/StatusDataTest.php index 0f05e35e7..98860938e 100644 --- a/tests/Unit/SDK/Trace/StatusDataTest.php +++ b/tests/Unit/SDK/Trace/StatusDataTest.php @@ -65,7 +65,7 @@ public function test_statuses_description(string $code): void $this->assertSame($code, $status->getCode()); } - public function getStatuses(): array + public static function getStatuses(): array { return [ [StatusCode::STATUS_ERROR],