Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelreyrol committed Feb 2, 2024
1 parent e757a25 commit d146333
Show file tree
Hide file tree
Showing 56 changed files with 198 additions and 257 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"open-telemetry/opentelemetry-propagation-server-timing": "^0.0.1",
"open-telemetry/opentelemetry-propagation-traceresponse": "^0.0.2",
"open-telemetry/sdk": "^1.0",
"open-telemetry/sem-conv": "^1.23",
"open-telemetry/sem-conv": "^1.24",
"open-telemetry/symfony-sdk-bundle": "^0.0.24",
"php-http/discovery": "^1.19",
"psr/http-factory": "^1.0",
Expand All @@ -47,15 +47,15 @@
"ext-mbstring": "*",
"ext-opentelemetry": "*",
"ext-xdebug": "*",
"doctrine/dbal": "^3.7",
"doctrine/dbal": "^3.8",
"doctrine/doctrine-bundle": "^2.11",
"doctrine/orm": "^2.17",
"ergebnis/composer-normalize": "^2.41",
"friendsofphp/php-cs-fixer": "^3.41",
"ergebnis/composer-normalize": "^2.42",
"friendsofphp/php-cs-fixer": "^3.49",
"guzzlehttp/promises": "^2.0",
"maglnet/composer-require-checker": "^4.8",
"matthiasnoback/symfony-config-test": "^5.1",
"matthiasnoback/symfony-dependency-injection-test": "^5.0",
"matthiasnoback/symfony-dependency-injection-test": "^5.1",
"nyholm/symfony-bundle-test": "^3.0",
"open-telemetry/exporter-otlp": "^1.0",
"open-telemetry/exporter-zipkin": "^1.0",
Expand All @@ -67,7 +67,7 @@
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpstan/phpstan-symfony": "^1.3",
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^10.5",
"pyrech/composer-changelogs": "^2.1",
"roave/security-advisories": "dev-master",
"symfony/cache": "^6.4 || ^7.0",
Expand Down
27 changes: 10 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheResultFile=".phpunit.cache/test-results"
executionOrder="depends,defects"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
convertDeprecationsToExceptions="true"
failOnRisky="true"
failOnWarning="false"
verbose="true">
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="false"
cacheDirectory=".phpunit.cache"
>

<php>
<ini name="error_reporting" value="-1"/>
Expand All @@ -24,14 +22,9 @@
</testsuite>
</testsuites>

<coverage cacheDirectory=".phpunit.cache/code-coverage"
processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
</source>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
$this->adapter = $adapter;
}

public function get(string $key, callable $callback, float $beta = null, array &$metadata = null): mixed
public function get(string $key, callable $callback, ?float $beta = null, ?array &$metadata = null): mixed

Check warning on line 25 in src/Instrumentation/Symfony/Cache/TagAwareTraceableCacheAdapter.php

View check run for this annotation

Codecov / codecov/patch

src/Instrumentation/Symfony/Cache/TagAwareTraceableCacheAdapter.php#L25

Added line #L25 was not covered by tests
{
return $this->tracer->traceFunction(
'cache.get',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
$this->adapter = $adapter;
}

public function get(string $key, callable $callback, float $beta = null, array &$metadata = null): mixed
public function get(string $key, callable $callback, ?float $beta = null, ?array &$metadata = null): mixed

Check warning on line 24 in src/Instrumentation/Symfony/Cache/TraceableCacheAdapter.php

View check run for this annotation

Codecov / codecov/patch

src/Instrumentation/Symfony/Cache/TraceableCacheAdapter.php#L24

Added line #L24 was not covered by tests
{
return $this->tracer->traceFunction(
'cache.get',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function request(string $method, string $url, array $options = []): Respo
}
}

public function stream(iterable|ResponseInterface $responses, float $timeout = null): ResponseStreamInterface
public function stream(iterable|ResponseInterface $responses, ?float $timeout = null): ResponseStreamInterface

Check warning on line 64 in src/Instrumentation/Symfony/HttpClient/TraceableHttpClient.php

View check run for this annotation

Codecov / codecov/patch

src/Instrumentation/Symfony/HttpClient/TraceableHttpClient.php#L64

Added line #L64 was not covered by tests
{
$scope = Context::storage()->scope();
if (null === $scope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function cancel(): void
$this->endSpan();
}

public function getInfo(string $type = null): mixed
public function getInfo(?string $type = null): mixed

Check warning on line 81 in src/Instrumentation/Symfony/HttpClient/TraceableResponse.php

View check run for this annotation

Codecov / codecov/patch

src/Instrumentation/Symfony/HttpClient/TraceableResponse.php#L81

Added line #L81 was not covered by tests
{
return $this->response->getInfo($type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Instrumentation/Symfony/Mailer/TraceableMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
) {
}

public function send(RawMessage $message, Envelope $envelope = null): void
public function send(RawMessage $message, ?Envelope $envelope = null): void

Check warning on line 25 in src/Instrumentation/Symfony/Mailer/TraceableMailer.php

View check run for this annotation

Codecov / codecov/patch

src/Instrumentation/Symfony/Mailer/TraceableMailer.php#L25

Added line #L25 was not covered by tests
{
$scope = Context::storage()->scope();
if (null === $scope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __toString()
return (string) $this->transport;
}

public function send(RawMessage $message, Envelope $envelope = null): ?SentMessage
public function send(RawMessage $message, ?Envelope $envelope = null): ?SentMessage

Check warning on line 32 in src/Instrumentation/Symfony/Mailer/TraceableMailerTransport.php

View check run for this annotation

Codecov / codecov/patch

src/Instrumentation/Symfony/Mailer/TraceableMailerTransport.php#L32

Added line #L32 was not covered by tests
{
$scope = Context::storage()->scope();
if (null === $scope) {
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Exporter/ExporterDsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function getPath(): ?string
return $this->uri->path()->isEmpty() ? null : $this->uri->path()->toString();
}

public function getPort(int $default = null): ?int
public function getPort(?int $default = null): ?int
{
return $this->uri->port() ?? $default;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Exporter/OtlpExporterEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class OtlpExporterEndpoint implements ExporterEndpointInterface

private function __construct(
private readonly ExporterDsn $dsn,
UriFactoryInterface $uriFactory = null,
?UriFactoryInterface $uriFactory = null,
) {
if ('otlp' !== $this->dsn->getExporter()) {
throw new \RuntimeException('Provided DSN exporter is not compatible with this endpoint.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ interface LogProcessorFactoryInterface
*/
public static function createProcessor(
array $processors = [],
LogRecordExporterInterface $exporter = null,
?LogRecordExporterInterface $exporter = null,
): LogRecordProcessorInterface;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class MultiLogProcessorFactory extends AbstractLogProcessorFactory
{
public static function createProcessor(
array $processors = [],
LogRecordExporterInterface $exporter = null,
?LogRecordExporterInterface $exporter = null,
): LogRecordProcessorInterface {
if (0 >= count($processors)) {
throw new \InvalidArgumentException('Processors should not be empty');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class NoopLogProcessorFactory extends AbstractLogProcessorFactory
{
public static function createProcessor(
array $processors = [],
LogRecordExporterInterface $exporter = null,
?LogRecordExporterInterface $exporter = null,
): LogRecordProcessorInterface {
return new NoopLogRecordProcessor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class SimpleLogProcessorFactory extends AbstractLogProcessorFactory
{
public static function createProcessor(
array $processors = [],
LogRecordExporterInterface $exporter = null,
?LogRecordExporterInterface $exporter = null,
): LogRecordProcessorInterface {
if (null === $exporter) {
throw new \InvalidArgumentException('Exporter is null');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class NoopMeterProviderFactory extends AbstractMeterProviderFactory
{
public static function createProvider(MetricExporterInterface $exporter = null, ExemplarFilterInterface $filter = null): MeterProviderInterface
public static function createProvider(?MetricExporterInterface $exporter = null, ?ExemplarFilterInterface $filter = null): MeterProviderInterface
{
return new NoopMeterProvider();
}
Expand Down
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Trace/SamplerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final class SamplerFactory
{
public static function create(string $name, float $probability = null): SamplerInterface
public static function create(string $name, ?float $probability = null): SamplerInterface
{
$sampler = TraceSamplerEnum::tryFrom($name);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class MultiSpanProcessorFactory extends AbstractSpanProcessorFactory
{
public static function createProcessor(
array $processors = [],
SpanExporterInterface $exporter = null
?SpanExporterInterface $exporter = null
): SpanProcessorInterface {
if (0 >= count($processors)) {
throw new \InvalidArgumentException('Processors should not be empty');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class NoopSpanProcessorFactory extends AbstractSpanProcessorFactory
{
public static function createProcessor(
array $processors = [],
SpanExporterInterface $exporter = null
?SpanExporterInterface $exporter = null
): SpanProcessorInterface {
return new NoopSpanProcessor();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class SimpleSpanProcessorFactory extends AbstractSpanProcessorFactory
{
public static function createProcessor(
array $processors = [],
SpanExporterInterface $exporter = null
?SpanExporterInterface $exporter = null
): SpanProcessorInterface {
if (null === $exporter) {
throw new \InvalidArgumentException('Exporter is null');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ interface SpanProcessorFactoryInterface
*/
public static function createProcessor(
array $processors = [],
SpanExporterInterface $exporter = null
?SpanExporterInterface $exporter = null
): SpanProcessorInterface;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final readonly class DefaultTracerProviderFactory implements TracerProviderFactoryInterface
{
public static function createProvider(SamplerInterface $sampler = null, array $processors = []): TracerProviderInterface
public static function createProvider(?SamplerInterface $sampler = null, array $processors = []): TracerProviderInterface
{
if (0 >= count($processors)) {
throw new \InvalidArgumentException('Processors should not be empty');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class NoopTracerProviderFactory implements TracerProviderFactoryInterface
{
public static function createProvider(SamplerInterface $sampler = null, array $processors = []): TracerProviderInterface
public static function createProvider(?SamplerInterface $sampler = null, array $processors = []): TracerProviderInterface
{
return new NoopTracerProvider();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ interface TracerProviderFactoryInterface
/**
* @param SpanProcessorInterface[] $processors
*/
public static function createProvider(SamplerInterface $sampler = null, array $processors = []): TracerProviderInterface;
public static function createProvider(?SamplerInterface $sampler = null, array $processors = []): TracerProviderInterface;
}
2 changes: 1 addition & 1 deletion src/OpenTelemetry/Trace/ZipkinExporterEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class ZipkinExporterEndpoint implements ExporterEndpointInterface

private function __construct(
private readonly ExporterDsn $dsn,
UriFactoryInterface $uriFactory = null,
?UriFactoryInterface $uriFactory = null,
) {
if (TraceExporterEnum::Zipkin !== TraceExporterEnum::fromDsn($this->dsn)) {
throw new \InvalidArgumentException('Unsupported DSN exporter for this endpoint.');
Expand Down
11 changes: 5 additions & 6 deletions tests/Unit/Command/DummyCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace FriendsOfOpenTelemetry\OpenTelemetryBundle\Tests\Unit\Command;

use FriendsOfOpenTelemetry\OpenTelemetryBundle\Tests\Application\Command\DummyCommand;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;

/**
* @coversDefaultClass \FriendsOfOpenTelemetry\OpenTelemetryBundle\Tests\Application\Command\DummyCommand
*/
#[CoversClass(DummyCommand::class)]
final class DummyCommandTest extends TestCase
{
public function testSuccessful(): void
Expand Down Expand Up @@ -49,7 +49,7 @@ public function testThrow(): void
/**
* @return array<int, array{0: int, 1: array<string, mixed>}>
*/
public function exitCodeProvider(): array
public static function exitCodeProvider(): array
{
return [
[42, ['--exit-code' => 42]],
Expand All @@ -58,10 +58,9 @@ public function exitCodeProvider(): array
}

/**
* @dataProvider exitCodeProvider
*
* @param array<string, mixed> $args
*/
#[DataProvider('exitCodeProvider')]
public function testExitCode(int $exitCode, array $args): void
{
$commandTester = new CommandTester(new DummyCommand());
Expand Down
12 changes: 5 additions & 7 deletions tests/Unit/EventSubscriber/ConsoleEventSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
use OpenTelemetry\Context\ContextStorageScopeInterface;
use OpenTelemetry\SDK\Trace\StatusData;
use OpenTelemetry\SDK\Trace\TracerProvider;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;

/**
* @coversDefaultClass \FriendsOfOpenTelemetry\OpenTelemetryBundle\Instrumentation\Symfony\Console\TraceableConsoleEventSubscriber
*/
#[CoversClass(TraceableConsoleEventSubscriber::class)]
final class ConsoleEventSubscriberTest extends TestCase
{
private readonly TracerInterface $tracer;
Expand All @@ -43,16 +43,14 @@ protected function tearDown(): void
/**
* @return array<int, array{0: ConsoleCommandEvent}>
*/
public function consoleCommandEventDataProvider(): array
public static function consoleCommandEventDataProvider(): array
{
return [
[new ConsoleCommandEvent(new DummyCommand(), new ArrayInput([]), new NullOutput())],
];
}

/**
* @dataProvider consoleCommandEventDataProvider
*/
#[DataProvider('consoleCommandEventDataProvider')]
public function testHandleCommandEvent(ConsoleCommandEvent $event): void
{
$subscriber = new TraceableConsoleEventSubscriber($this->tracer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

use FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Exporter\ConsoleExporterEndpoint;
use FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Exporter\ExporterDsn;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
* @coversDefaultClass \FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Exporter\ConsoleExporterEndpoint
*/
#[CoversClass(ConsoleExporterEndpoint::class)]
class ConsoleExporterEndpointTest extends TestCase
{
/**
* @dataProvider dsnProvider
*/
#[DataProvider('dsnProvider')]
public function testFromDsn(string $dsn, string $endpoint): void
{
self::assertSame($endpoint, (string) ConsoleExporterEndpoint::fromDsn(ExporterDsn::fromString($dsn)));
Expand All @@ -22,7 +20,7 @@ public function testFromDsn(string $dsn, string $endpoint): void
/**
* @return \Generator<int, array{0: string, 1: string}>
*/
public function dsnProvider(): \Generator
public static function dsnProvider(): \Generator
{
yield [
'stream+console://default',
Expand Down

0 comments on commit d146333

Please sign in to comment.