Skip to content

Commit f9cb8d3

Browse files
authored
Merge pull request #486 from php/1.3.x
Merge up bug fixes for PHP version parsing and OS family to 1.3.6
2 parents f0efdfa + 1cf5c59 commit f9cb8d3

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-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: 21 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
@@ -85,13 +86,22 @@ public function testNonExecutablePhpBinaryIsRejected(): void
8586
PhpBinaryPath::fromPhpBinaryPath(__FILE__);
8687
}
8788

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

97+
#[RequiresOperatingSystemFamily('Linux')]
98+
public function testInvalidVersion(): void
99+
{
100+
$phpBinary = PhpBinaryPath::fromPhpBinaryPath(self::PHP_INVALID_VERSION);
101+
self::assertSame('5.6.40', $phpBinary->version());
102+
self::assertSame('5.6', $phpBinary->majorMinorVersion());
103+
}
104+
95105
public function testWarningsAndDeprecationsAreFiltered(): void
96106
{
97107
if (Platform::isWindows()) {
@@ -129,11 +139,17 @@ public static function phpConfigPathProvider(): array
129139

130140
$possiblePhpConfigPaths = array_filter(
131141
[
142+
['/usr/bin/php-config8.5', '8.5'],
143+
['/usr/bin/php-config8.4', '8.4'],
132144
['/usr/bin/php-config8.3', '8.3'],
133145
['/usr/bin/php-config8.2', '8.2'],
134146
['/usr/bin/php-config8.1', '8.1'],
135147
['/usr/bin/php-config8.0', '8.0'],
136148
['/usr/bin/php-config7.4', '7.4'],
149+
['/usr/bin/php-config7.3', '7.3'],
150+
['/usr/bin/php-config7.2', '7.2'],
151+
['/usr/bin/php-config7.1', '7.1'],
152+
['/usr/bin/php-config5.6', '5.6'],
137153
],
138154
static fn (array $phpConfigPath) => file_exists($phpConfigPath[0])
139155
&& is_executable($phpConfigPath[0]),
@@ -168,6 +184,11 @@ public function testFromPhpConfigExecutable(string $phpConfigPath, string $expec
168184
$phpBinary->majorMinorVersion(),
169185
);
170186

187+
self::assertStringStartsWith(
188+
$expectedMajorMinor . '.',
189+
$phpBinary->version(),
190+
);
191+
171192
self::assertSame($phpConfigPath, $phpBinary->phpConfigPath());
172193
}
173194

0 commit comments

Comments
 (0)