From d09af9088ac7ee1918c0a7a2bf69aaacbbf50978 Mon Sep 17 00:00:00 2001 From: Stefano Arlandini Date: Mon, 22 Feb 2021 22:32:24 +0100 Subject: [PATCH] Ensure that the bundle works even without the symfony/twig-bundle package installed --- .github/workflows/tests.yaml | 2 +- tests/Tracing/Twig/TwigTracingExtensionTest.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index d8fa8d6a..beebc3ee 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -104,7 +104,7 @@ jobs: restore-keys: ${{ runner.os }}-${{ matrix.php }}-composer-${{ matrix.dependencies }}- - name: Remove optional packages - run: composer remove doctrine/dbal doctrine/doctrine-bundle symfony/messenger --dev --no-update + run: composer remove doctrine/dbal doctrine/doctrine-bundle symfony/messenger symfony/twig-bundle --dev --no-update - name: Install highest dependencies run: composer update --no-progress --no-interaction --prefer-dist diff --git a/tests/Tracing/Twig/TwigTracingExtensionTest.php b/tests/Tracing/Twig/TwigTracingExtensionTest.php index 32d65bae..ba2f8c76 100644 --- a/tests/Tracing/Twig/TwigTracingExtensionTest.php +++ b/tests/Tracing/Twig/TwigTracingExtensionTest.php @@ -10,7 +10,7 @@ use Sentry\State\HubInterface; use Sentry\Tracing\Transaction; use Sentry\Tracing\TransactionContext; -use Twig\Profiler\Profile; +use Symfony\Bundle\TwigBundle\TwigBundle; final class TwigTracingExtensionTest extends TestCase { @@ -24,6 +24,13 @@ final class TwigTracingExtensionTest extends TestCase */ private $listener; + public static function setUpBeforeClass(): void + { + if (!self::isTwigBundlePackageInstalled()) { + self::markTestSkipped('This test requires the "symfony/twig-bundle" Composer package to be installed.'); + } + } + protected function setUp(): void { $this->hub = $this->createMock(HubInterface::class); @@ -113,4 +120,9 @@ public function testLeaveDoesNothingIfSpanDoesNotExistsForProfile(): void $this->listener->leave(new Profile('main', Profile::TEMPLATE)); } + + private static function isTwigBundlePackageInstalled(): bool + { + return class_exists(TwigBundle::class); + } }