From 7bbd0081752a6c66eaf2cece38a4f61f30979d69 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Unit/SDK/SdkTest.php b/tests/Unit/SDK/SdkTest.php index 85007ec22..85b389b57 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,18 @@ public function test_developer_mode_auto_detected(): void $this->assertTrue(Sdk::isDeveloperModeEnabled()); } + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + 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());