From 97ca0c0e796c13e0bb6c44c1744268dd423c3d77 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Mon, 14 Apr 2025 21:14:45 +0100 Subject: [PATCH] Ignore case sensitivity when checking if an extension is loaded --- src/Platform/TargetPhp/PhpBinaryPath.php | 2 +- .../Platform/TargetPhp/PhpBinaryPathTest.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Platform/TargetPhp/PhpBinaryPath.php b/src/Platform/TargetPhp/PhpBinaryPath.php index f75392a6..cb725f92 100644 --- a/src/Platform/TargetPhp/PhpBinaryPath.php +++ b/src/Platform/TargetPhp/PhpBinaryPath.php @@ -118,7 +118,7 @@ public function extensionPath(): string public function assertExtensionIsLoadedInRuntime(ExtensionName $extension, OutputInterface|null $output = null): void { - if (! in_array($extension->name(), array_keys($this->extensions()))) { + if (! in_array(strtolower($extension->name()), array_map('strtolower', array_keys($this->extensions())))) { throw Exception\ExtensionIsNotLoaded::fromExpectedExtension( $this, $extension, diff --git a/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php b/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php index 3ee8ea0c..b3c9a865 100644 --- a/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php +++ b/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php @@ -287,6 +287,24 @@ public function testAssertExtensionIsLoaded(): void ); } + public function testAssertDifferentCasedExtensionIsLoaded(): void + { + $php = PhpBinaryPath::fromCurrentProcess(); + $loadedExtensions = $php->extensions(); + + if (! count($loadedExtensions) || ! array_key_exists('Core', $loadedExtensions)) { + self::fail('Core extension is not loaded, this is quite unexpected...'); + } + + $output = new BufferedOutput(BufferedOutput::VERBOSITY_VERBOSE); + $php->assertExtensionIsLoadedInRuntime(ExtensionName::normaliseFromString('CORE'), $output); + + self::assertStringContainsString( + 'Successfully asserted that extension CORE is loaded in runtime.', + $output->fetch(), + ); + } + public function testAssertExtensionFailsWhenNotLoaded(): void { $php = PhpBinaryPath::fromCurrentProcess();