From 34e6c2c628167bfd45be73c43137024dba8fc767 Mon Sep 17 00:00:00 2001 From: Chris Lightfoot-Wild Date: Mon, 20 Nov 2023 23:11:28 +0000 Subject: [PATCH] Mock Composer\InstalledVersions getRootPackage call for improved coverage. --- tests/Unit/SDK/SdkTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Unit/SDK/SdkTest.php b/tests/Unit/SDK/SdkTest.php index 85007ec22..27d3ecca6 100644 --- a/tests/Unit/SDK/SdkTest.php +++ b/tests/Unit/SDK/SdkTest.php @@ -5,6 +5,7 @@ namespace OpenTelemetry\Tests\Unit\SDK; use AssertWell\PHPUnitGlobalState\EnvironmentVariables; +use Composer\InstalledVersions; use OpenTelemetry\Context\Propagation\TextMapPropagatorInterface; use OpenTelemetry\SDK\Common\Configuration\Variables; use OpenTelemetry\SDK\Logs\LoggerProviderInterface; @@ -83,6 +84,14 @@ public function test_developer_mode_auto_detected(): void $this->assertTrue(Sdk::isDeveloperModeEnabled()); } + public function test_developer_mode_check_handles_exceptions(): void + { + $mock = \Mockery::mock('alias:' . InstalledVersions::class); + $mock->expects('getRootPackage')->andThrow(\Exception::class); + + $this->assertFalse(Sdk::isDeveloperModeEnabled()); + } + public function test_builder(): void { $this->assertInstanceOf(SdkBuilder::class, Sdk::builder());