From 61b7a5e535899612b77c1acdd1e8834a3e5b2e0f Mon Sep 17 00:00:00 2001 From: Alessandro Chitolina Date: Wed, 22 Jun 2022 10:47:44 +0200 Subject: [PATCH] test http-client tracing enabled/disabled --- .github/workflows/tests.yaml | 2 +- src/Resources/config/schema/sentry-1.0.xsd | 5 +++++ .../Fixtures/php/http_client_tracing_enabled.php | 14 ++++++++++++++ .../Fixtures/xml/http_client_tracing_enabled.xml | 14 ++++++++++++++ .../Fixtures/yml/http_client_tracing_enabled.yml | 4 ++++ tests/DependencyInjection/SentryExtensionTest.php | 13 +++++++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/DependencyInjection/Fixtures/php/http_client_tracing_enabled.php create mode 100644 tests/DependencyInjection/Fixtures/xml/http_client_tracing_enabled.xml create mode 100644 tests/DependencyInjection/Fixtures/yml/http_client_tracing_enabled.yml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 14a17682..bd6cd95a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -128,7 +128,7 @@ jobs: run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Remove optional packages - run: composer remove doctrine/dbal doctrine/doctrine-bundle symfony/messenger symfony/twig-bundle symfony/cache --dev --no-update + run: composer remove doctrine/dbal doctrine/doctrine-bundle symfony/messenger symfony/twig-bundle symfony/cache symfony/http-client --dev --no-update - name: Install dependencies uses: ramsey/composer-install@v1 diff --git a/src/Resources/config/schema/sentry-1.0.xsd b/src/Resources/config/schema/sentry-1.0.xsd index 79a6aac4..9240c5c6 100644 --- a/src/Resources/config/schema/sentry-1.0.xsd +++ b/src/Resources/config/schema/sentry-1.0.xsd @@ -91,6 +91,7 @@ + @@ -117,4 +118,8 @@ + + + + diff --git a/tests/DependencyInjection/Fixtures/php/http_client_tracing_enabled.php b/tests/DependencyInjection/Fixtures/php/http_client_tracing_enabled.php new file mode 100644 index 00000000..639e2f9a --- /dev/null +++ b/tests/DependencyInjection/Fixtures/php/http_client_tracing_enabled.php @@ -0,0 +1,14 @@ +loadFromExtension('sentry', [ + 'tracing' => [ + 'http_client' => [ + 'enabled' => true, + ], + ], +]); diff --git a/tests/DependencyInjection/Fixtures/xml/http_client_tracing_enabled.xml b/tests/DependencyInjection/Fixtures/xml/http_client_tracing_enabled.xml new file mode 100644 index 00000000..cb0621ab --- /dev/null +++ b/tests/DependencyInjection/Fixtures/xml/http_client_tracing_enabled.xml @@ -0,0 +1,14 @@ + + + + + + + + + + diff --git a/tests/DependencyInjection/Fixtures/yml/http_client_tracing_enabled.yml b/tests/DependencyInjection/Fixtures/yml/http_client_tracing_enabled.yml new file mode 100644 index 00000000..50d56ede --- /dev/null +++ b/tests/DependencyInjection/Fixtures/yml/http_client_tracing_enabled.yml @@ -0,0 +1,4 @@ +sentry: + tracing: + http_client: + enabled: true diff --git a/tests/DependencyInjection/SentryExtensionTest.php b/tests/DependencyInjection/SentryExtensionTest.php index eaafea6d..e907e512 100644 --- a/tests/DependencyInjection/SentryExtensionTest.php +++ b/tests/DependencyInjection/SentryExtensionTest.php @@ -35,6 +35,7 @@ use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\ErrorHandler\Error\FatalError; +use Symfony\Component\HttpClient\HttpClient; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent; use Symfony\Component\Messenger\Event\WorkerMessageHandledEvent; @@ -380,6 +381,18 @@ public function testTwigTracingExtensionIsConfiguredWhenTwigTracingIsEnabled(): $this->assertTrue($container->hasDefinition(TwigTracingExtension::class)); } + public function testHttpClientTracingExtensionIsConfiguredWhenHttpClientTracingIsEnabled(): void + { + if (!class_exists(HttpClient::class)) { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Http client tracing support cannot be enabled because the symfony/http-client Composer package is not installed.'); + } + + $container = $this->createContainerFromFixture('http_client_tracing_enabled'); + + $this->assertTrue($container->getParameter('sentry.tracing.http_client.enabled')); + } + public function testTwigTracingExtensionIsRemovedWhenTwigTracingIsDisabled(): void { $container = $this->createContainerFromFixture('full');