Skip to content

Commit 71f8b75

Browse files
committed
446: Fix versions not parsing when PHP_VERSION is not semver-compat
Reverts commit 2962d92 Presumably this was changed for simplicity, but there was no test to ensure any PHP builds with non-semver-compatible version strings don't crash
1 parent 8f22ace commit 71f8b75

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

src/Platform/TargetPhp/PhpBinaryPath.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public function version(): string
299299
$phpVersion = self::cleanWarningAndDeprecationsFromOutput(Process::run([
300300
$this->phpBinaryPath,
301301
'-r',
302-
'echo PHP_VERSION;',
302+
'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION . "." . PHP_RELEASE_VERSION;',
303303
]));
304304
Assert::stringNotEmpty($phpVersion, 'Could not determine PHP version');
305305

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
3+
ARGS="$*"
4+
5+
case "$ARGS" in
6+
"-r echo \"PHP\";")
7+
echo "PHP";
8+
exit 0
9+
;;
10+
"-r echo PHP_VERSION;")
11+
echo "5.6.40-90+ubuntu24.04.1+deb.sury.org+1";
12+
exit 0
13+
;;
14+
"-r echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION . \".\" . PHP_RELEASE_VERSION;")
15+
echo "5.6.40";
16+
exit 0
17+
;;
18+
"-r echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;")
19+
echo "5.6";
20+
exit 0
21+
;;
22+
*)
23+
echo "unknown fake php command: $ARGS"
24+
exit 1
25+
esac
26+

test/integration/Command/InstallCommandTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public static function phpPathProvider(): array
5050
$possiblePhpConfigPaths = array_filter(
5151
[
5252
'/usr/bin/php-config',
53+
'/usr/bin/php-config8.5',
54+
'/usr/bin/php-config8.4',
5355
'/usr/bin/php-config8.3',
5456
'/usr/bin/php-config8.2',
5557
'/usr/bin/php-config8.1',

test/integration/Installing/UnixInstallTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ public static function phpPathProvider(): array
4747
$possiblePhpConfigPaths = array_filter(
4848
[
4949
'/usr/bin/php-config',
50+
'/usr/bin/php-config8.5',
5051
'/usr/bin/php-config8.4',
5152
'/usr/bin/php-config8.3',
5253
'/usr/bin/php-config8.2',
5354
'/usr/bin/php-config8.1',
5455
'/usr/bin/php-config8.0',
5556
'/usr/bin/php-config7.4',
57+
'/usr/bin/php-config7.3',
58+
'/usr/bin/php-config7.2',
5659
],
5760
static fn (string $phpConfigPath) => file_exists($phpConfigPath)
5861
&& is_executable($phpConfigPath),

test/unit/Platform/TargetPhp/PhpBinaryPathTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
final class PhpBinaryPathTest extends TestCase
5858
{
5959
private const FAKE_PHP_EXECUTABLE = __DIR__ . '/../../../assets/fake-php.sh';
60+
private const PHP_INVALID_VERSION = __DIR__ . '/../../../assets/fake-php-invalid-version.sh';
6061
private const VALID_PHP_WITH_WARNINGS = __DIR__ . '/../../../assets/valid-php-with-warnings.sh';
6162

6263
public function testNonExistentPhpBinaryIsRejected(): void
@@ -92,6 +93,13 @@ public function testInvalidPhpBinaryIsRejected(): void
9293
PhpBinaryPath::fromPhpBinaryPath(self::FAKE_PHP_EXECUTABLE);
9394
}
9495

96+
public function testInvalidVersion(): void
97+
{
98+
$phpBinary = PhpBinaryPath::fromPhpBinaryPath(self::PHP_INVALID_VERSION);
99+
self::assertSame('5.6.40', $phpBinary->version());
100+
self::assertSame('5.6', $phpBinary->majorMinorVersion());
101+
}
102+
95103
public function testWarningsAndDeprecationsAreFiltered(): void
96104
{
97105
if (Platform::isWindows()) {
@@ -129,11 +137,17 @@ public static function phpConfigPathProvider(): array
129137

130138
$possiblePhpConfigPaths = array_filter(
131139
[
140+
['/usr/bin/php-config8.5', '8.5'],
141+
['/usr/bin/php-config8.4', '8.4'],
132142
['/usr/bin/php-config8.3', '8.3'],
133143
['/usr/bin/php-config8.2', '8.2'],
134144
['/usr/bin/php-config8.1', '8.1'],
135145
['/usr/bin/php-config8.0', '8.0'],
136146
['/usr/bin/php-config7.4', '7.4'],
147+
['/usr/bin/php-config7.3', '7.3'],
148+
['/usr/bin/php-config7.2', '7.2'],
149+
['/usr/bin/php-config7.1', '7.1'],
150+
['/usr/bin/php-config5.6', '5.6'],
137151
],
138152
static fn (array $phpConfigPath) => file_exists($phpConfigPath[0])
139153
&& is_executable($phpConfigPath[0]),
@@ -168,6 +182,11 @@ public function testFromPhpConfigExecutable(string $phpConfigPath, string $expec
168182
$phpBinary->majorMinorVersion(),
169183
);
170184

185+
self::assertStringStartsWith(
186+
$expectedMajorMinor . '.',
187+
$phpBinary->version(),
188+
);
189+
171190
self::assertSame($phpConfigPath, $phpBinary->phpConfigPath());
172191
}
173192

0 commit comments

Comments
 (0)