Skip to content

Commit 3feb4b8

Browse files
committed
When fetching PHP version, do not include the 'extra' information in the version
1 parent 2b90095 commit 3feb4b8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/TargetPhp/PhpBinaryPath.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Php\Pie\TargetPhp;
66

7+
use Composer\Semver\VersionParser;
78
use Symfony\Component\Process\PhpExecutableFinder;
89
use Symfony\Component\Process\Process;
910
use Webmozart\Assert\Assert;
@@ -20,11 +21,18 @@ private function __construct(readonly string $phpBinaryPath)
2021

2122
public function version(): string
2223
{
23-
$phpVersion = trim((new Process([$this->phpBinaryPath, '-r', 'echo phpversion();']))
24+
$phpVersion = trim((new Process([
25+
$this->phpBinaryPath,
26+
'-r',
27+
'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION . "." . PHP_RELEASE_VERSION;',
28+
]))
2429
->mustRun()
2530
->getOutput());
2631
Assert::stringNotEmpty($phpVersion, 'Could not determine PHP version');
2732

33+
// normalizing the version will throw an exception if it is not a valid version
34+
(new VersionParser())->normalize($phpVersion);
35+
2836
return $phpVersion;
2937
}
3038

test/unit/TargetPhp/PhpBinaryPathTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ final class PhpBinaryPathTest extends TestCase
1515
{
1616
public function testVersionFromCurrentProcess(): void
1717
{
18-
self::assertSame(PHP_VERSION, PhpBinaryPath::fromCurrentProcess()->version());
18+
self::assertSame(
19+
sprintf("%s.%s.%s", PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION),
20+
PhpBinaryPath::fromCurrentProcess()->version()
21+
);
1922
}
2023
}

0 commit comments

Comments
 (0)