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
10 changes: 4 additions & 6 deletions src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 !== '';
Expand All @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion src/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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'));
}
}
34 changes: 34 additions & 0 deletions test/integration/Command/ShowCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Php\PieIntegrationTest\Command;

use Composer\Util\Platform;
use InvalidArgumentException;
use Php\Pie\Command\InstallCommand;
use Php\Pie\Command\ShowCommand;
Expand All @@ -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)]
Expand Down Expand Up @@ -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) {
Expand Down
Loading