From cd7d5314da3bd92580d4a1700df0f7e375c639be Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Wed, 21 Oct 2026 20:12:18 +0100 Subject: [PATCH 1/2] 780: handle --with-php-path and --with-php-config properly fallback --- src/Command/CommandHelper.php | 10 +++--- test/integration/Command/ShowCommandTest.php | 34 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/Command/CommandHelper.php b/src/Command/CommandHelper.php index 3d0f0254..d47c9525 100644 --- a/src/Command/CommandHelper.php +++ b/src/Command/CommandHelper.php @@ -197,8 +197,6 @@ public static function validateInput(InputInterface $input, Command $command): v public static function determineTargetPlatformFromInputs(InputInterface $input, IOInterface $io): TargetPlatform { - $phpBinaryPath = PhpBinaryPath::fromCurrentProcess(); - /** @var mixed $withPhpConfig */ $withPhpConfig = $input->getOption(self::OPTION_WITH_PHP_CONFIG); $specifiedWithPhpConfig = is_string($withPhpConfig) && $withPhpConfig !== ''; @@ -214,12 +212,12 @@ public static function determineTargetPlatformFromInputs(InputInterface $input, throw new InvalidArgumentException('The --with-php-path=/path/to/php cannot be used on non-Windows, use --with-php-config=/path/to/php-config instead.'); } - if ($specifiedWithPhpConfig) { - $phpBinaryPath = PhpBinaryPath::fromPhpConfigExecutable($withPhpConfig); - } - if ($specifiedWithPhpPath) { $phpBinaryPath = PhpBinaryPath::fromPhpBinaryPath($withPhpPath); + } elseif ($specifiedWithPhpConfig) { + $phpBinaryPath = PhpBinaryPath::fromPhpConfigExecutable($withPhpConfig); + } else { + $phpBinaryPath = PhpBinaryPath::fromCurrentProcess(); } $makeParallelJobs = null; /** `null` means {@see TargetPlatform} will try to auto-detect */ diff --git a/test/integration/Command/ShowCommandTest.php b/test/integration/Command/ShowCommandTest.php index c097b402..d039a388 100644 --- a/test/integration/Command/ShowCommandTest.php +++ b/test/integration/Command/ShowCommandTest.php @@ -4,6 +4,7 @@ namespace Php\PieIntegrationTest\Command; +use Composer\Util\Platform; use InvalidArgumentException; use Php\Pie\Command\InstallCommand; use Php\Pie\Command\ShowCommand; @@ -17,9 +18,14 @@ use Webmozart\Assert\Assert; use function get_loaded_extensions; +use function getenv; use function phpversion; +use function Safe\putenv; use function str_contains; +use function sys_get_temp_dir; +use const DIRECTORY_SEPARATOR; +use const PHP_BINARY; use const PHP_VERSION_ID; #[CoversClass(ShowCommand::class)] @@ -50,6 +56,34 @@ public function testExecute(): void } } + public function testExecuteWithExplicitTargetPhpWhenRunningPhpCannotBeFound(): void + { + if (Platform::isWindows()) { + $targetPhpOption = ['--with-php-path' => PHP_BINARY]; + } else { + try { + $phpConfig = Process::run(['which', 'php-config']); + Assert::stringNotEmpty($phpConfig); + } catch (ProcessFailedException | InvalidArgumentException) { + self::markTestSkipped('This test can only run on systems with php-config'); + } + + $targetPhpOption = ['--with-php-config' => $phpConfig]; + } + + $originalPhpBinaryEnv = getenv('PHP_BINARY'); + putenv('PHP_BINARY=' . sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php-that-does-not-exist'); + + try { + $this->commandTester->execute($targetPhpOption); + } finally { + putenv($originalPhpBinaryEnv === false ? 'PHP_BINARY' : 'PHP_BINARY=' . $originalPhpBinaryEnv); + } + + $this->commandTester->assertCommandIsSuccessful(); + self::assertStringContainsString('Target PHP installation:', $this->commandTester->getDisplay()); + } + public function testExecuteWithAvailableConstrainedUpdates(): void { if (PHP_VERSION_ID >= 80500) { From 70a13dcec17e28b0fb171818e90f3fdcc010cd28 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Wed, 21 Oct 2026 20:19:06 +0100 Subject: [PATCH 2/2] 780: backport ea76188 to fix isRunningStaticPhp() check --- src/Platform.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Platform.php b/src/Platform.php index e2a3f778..31a73604 100644 --- a/src/Platform.php +++ b/src/Platform.php @@ -22,6 +22,7 @@ use const DIRECTORY_SEPARATOR; use const PHP_BUILD_PROVIDER; +use const PHP_SAPI; use const STDIN; /** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */ @@ -135,6 +136,6 @@ public static function getPieJsonFilename(TargetPlatform $targetPlatform): strin public static function isRunningStaticPhp(): bool { - return defined('PHP_BUILD_PROVIDER') && str_contains(PHP_BUILD_PROVIDER, 'static-php-cli'); + return PHP_SAPI === 'micro' || (defined('PHP_BUILD_PROVIDER') && str_contains(PHP_BUILD_PROVIDER, 'static-php-cli')); } }