Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Platform/TargetPhp/PhpBinaryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions test/unit/Platform/TargetPhp/PhpBinaryPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string, array{0: string}> */
public static function phpPathProvider(): array
{
Expand Down