diff --git a/src/Platform/TargetPhp/PhpBinaryPath.php b/src/Platform/TargetPhp/PhpBinaryPath.php index 8163b253..dcd5ee9b 100644 --- a/src/Platform/TargetPhp/PhpBinaryPath.php +++ b/src/Platform/TargetPhp/PhpBinaryPath.php @@ -29,6 +29,7 @@ use function in_array; use function is_dir; use function is_executable; +use function mkdir; use function preg_match; use function sprintf; use function strtolower; @@ -105,6 +106,11 @@ public function extensionPath(): string return $extensionPath; } + // if the path is absolute, try to create it + if (mkdir($extensionPath, 0777, true) && file_exists($extensionPath) && is_dir($extensionPath)) { + return $extensionPath; + } + // `extension_dir` may be a relative URL on Windows, so resolve it according to the location of PHP $phpPath = dirname($this->phpBinaryPath); $attemptExtensionPath = $phpPath . DIRECTORY_SEPARATOR . $extensionPath; diff --git a/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php b/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php index 89be56e7..6b8d8c92 100644 --- a/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php +++ b/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php @@ -37,6 +37,8 @@ use function phpversion; use function sprintf; use function strtolower; +use function sys_get_temp_dir; +use function uniqid; use const DIRECTORY_SEPARATOR; use const PHP_INT_SIZE; @@ -237,6 +239,21 @@ public function testExtensionPath(): void ); } + public function testExtensionPathIsImplicitlyCreated(): void + { + $phpBinary = $this->createPartialMock(PhpBinaryPath::class, ['phpinfo']); + + $configuredExtensionPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('PIE_non_existent_extension_path', true); + self::assertDirectoryDoesNotExist($configuredExtensionPath); + + $phpBinary->expects(self::once()) + ->method('phpinfo') + ->willReturn(sprintf('extension_dir => %s => %s', $configuredExtensionPath, $configuredExtensionPath)); + + self::assertSame($configuredExtensionPath, $phpBinary->extensionPath()); + self::assertDirectoryExists($configuredExtensionPath); + } + /** @return array */ public static function phpPathProvider(): array {