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
2 changes: 1 addition & 1 deletion src/Platform/TargetPhp/PhpBinaryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public function version(): string
$phpVersion = self::cleanWarningAndDeprecationsFromOutput(Process::run([
$this->phpBinaryPath,
'-r',
'echo PHP_VERSION;',
'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION . "." . PHP_RELEASE_VERSION;',
]));
Assert::stringNotEmpty($phpVersion, 'Could not determine PHP version');

Expand Down
26 changes: 26 additions & 0 deletions test/assets/fake-php-invalid-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

ARGS="$*"

case "$ARGS" in
"-r echo \"PHP\";")
echo "PHP";
exit 0
;;
"-r echo PHP_VERSION;")
echo "5.6.40-90+ubuntu24.04.1+deb.sury.org+1";
exit 0
;;
"-r echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION . \".\" . PHP_RELEASE_VERSION;")
echo "5.6.40";
exit 0
;;
"-r echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;")
echo "5.6";
exit 0
;;
*)
echo "unknown fake php command: $ARGS"
exit 1
esac

2 changes: 2 additions & 0 deletions test/integration/Command/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public static function phpPathProvider(): array
$possiblePhpConfigPaths = array_filter(
[
'/usr/bin/php-config',
'/usr/bin/php-config8.5',
'/usr/bin/php-config8.4',
'/usr/bin/php-config8.3',
'/usr/bin/php-config8.2',
'/usr/bin/php-config8.1',
Expand Down
3 changes: 3 additions & 0 deletions test/integration/Installing/UnixInstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ public static function phpPathProvider(): array
$possiblePhpConfigPaths = array_filter(
[
'/usr/bin/php-config',
'/usr/bin/php-config8.5',
'/usr/bin/php-config8.4',
'/usr/bin/php-config8.3',
'/usr/bin/php-config8.2',
'/usr/bin/php-config8.1',
'/usr/bin/php-config8.0',
'/usr/bin/php-config7.4',
'/usr/bin/php-config7.3',
'/usr/bin/php-config7.2',
],
static fn (string $phpConfigPath) => file_exists($phpConfigPath)
&& is_executable($phpConfigPath),
Expand Down
21 changes: 21 additions & 0 deletions test/unit/Platform/TargetPhp/PhpBinaryPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
final class PhpBinaryPathTest extends TestCase
{
private const FAKE_PHP_EXECUTABLE = __DIR__ . '/../../../assets/fake-php.sh';
private const PHP_INVALID_VERSION = __DIR__ . '/../../../assets/fake-php-invalid-version.sh';
private const VALID_PHP_WITH_WARNINGS = __DIR__ . '/../../../assets/valid-php-with-warnings.sh';

public function testNonExistentPhpBinaryIsRejected(): void
Expand Down Expand Up @@ -85,13 +86,22 @@ public function testNonExecutablePhpBinaryIsRejected(): void
PhpBinaryPath::fromPhpBinaryPath(__FILE__);
}

#[RequiresOperatingSystemFamily('Linux')]
public function testInvalidPhpBinaryIsRejected(): void
{
$this->expectException(InvalidPhpBinaryPath::class);
$this->expectExceptionMessage('does not appear to be a PHP binary');
PhpBinaryPath::fromPhpBinaryPath(self::FAKE_PHP_EXECUTABLE);
}

#[RequiresOperatingSystemFamily('Linux')]
public function testInvalidVersion(): void
{
$phpBinary = PhpBinaryPath::fromPhpBinaryPath(self::PHP_INVALID_VERSION);
self::assertSame('5.6.40', $phpBinary->version());
self::assertSame('5.6', $phpBinary->majorMinorVersion());
}

public function testWarningsAndDeprecationsAreFiltered(): void
{
if (Platform::isWindows()) {
Expand Down Expand Up @@ -129,11 +139,17 @@ public static function phpConfigPathProvider(): array

$possiblePhpConfigPaths = array_filter(
[
['/usr/bin/php-config8.5', '8.5'],
['/usr/bin/php-config8.4', '8.4'],
['/usr/bin/php-config8.3', '8.3'],
['/usr/bin/php-config8.2', '8.2'],
['/usr/bin/php-config8.1', '8.1'],
['/usr/bin/php-config8.0', '8.0'],
['/usr/bin/php-config7.4', '7.4'],
['/usr/bin/php-config7.3', '7.3'],
['/usr/bin/php-config7.2', '7.2'],
['/usr/bin/php-config7.1', '7.1'],
['/usr/bin/php-config5.6', '5.6'],
],
static fn (array $phpConfigPath) => file_exists($phpConfigPath[0])
&& is_executable($phpConfigPath[0]),
Expand Down Expand Up @@ -168,6 +184,11 @@ public function testFromPhpConfigExecutable(string $phpConfigPath, string $expec
$phpBinary->majorMinorVersion(),
);

self::assertStringStartsWith(
$expectedMajorMinor . '.',
$phpBinary->version(),
);

self::assertSame($phpConfigPath, $phpBinary->phpConfigPath());
}

Expand Down