Skip to content

Commit

Permalink
upgrade to phpunit 10 (#1258)
Browse files Browse the repository at this point in the history
* upgrade to phpunit 10

* removing unintended commented code
  • Loading branch information
brettmc authored Mar 19, 2024
1 parent 639d8e2 commit a1489d3
Show file tree
Hide file tree
Showing 33 changed files with 146 additions and 121 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 20 additions & 28 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="true"
backupStaticAttributes="false"
bootstrap="./tests/bootstrap.php"
cacheResult="false"
colors="false"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
forceCoversAnnotation="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
Expand All @@ -22,34 +15,33 @@
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
verbose="true">

<coverage processUncoveredFiles="true">
<include>
<directory>src</directory>
</include>
<exclude>
<directory suffix=".php">src/SDK/Common/Dev/Compatibility/BC</directory>
</exclude>
</coverage>

cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="true">
<php>
<ini name="date.timezone" value="UTC" />
<ini name="display_errors" value="On" />
<ini name="display_startup_errors" value="On" />
<ini name="error_reporting" value="E_ALL" />
<ini name="assert.active" value="True" />
<ini name="assert.exception" value="True" />
<env name="OTEL_PHP_FIBERS_ENABLED" value="true" />
<ini name="date.timezone" value="UTC"/>
<ini name="display_errors" value="On"/>
<ini name="display_startup_errors" value="On"/>
<ini name="error_reporting" value="E_ALL"/>
<ini name="assert.active" value="True"/>
<ini name="assert.exception" value="True"/>
<env name="OTEL_PHP_FIBERS_ENABLED" value="true"/>
</php>

<testsuites>
<testsuite name="unit">
<directory>./tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/Integration</directory>
<directory phpVersion="8.1.0" suffix=".phpt">./tests/Integration/Context/Fiber</directory>
<directory suffix=".phpt">./tests/Integration/Context/Fiber</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
<exclude>
<directory suffix=".php">src/SDK/Common/Dev/Compatibility/BC</directory>
</exclude>
</source>
</phpunit>
3 changes: 3 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 => [
Expand Down
13 changes: 7 additions & 6 deletions src/SDK/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogRecordExporterFactoryInterface> $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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/SDK/Context/SpanContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/SDK/TracerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand Down
21 changes: 16 additions & 5 deletions tests/Unit/Context/DebugScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@

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;

/**
* @covers \OpenTelemetry\Context\DebugScope
*/
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
Expand Down Expand Up @@ -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();
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Contrib/Otlp/HttpEndpointResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Contrib/Zipkin/ZipkinExporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/Contrib/Zipkin/ZipkinSpanConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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'],
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Extension/Propagator/CloudTrace/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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'],
Expand All @@ -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'],
Expand All @@ -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],
Expand All @@ -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'],
Expand Down
Loading

0 comments on commit a1489d3

Please sign in to comment.