Skip to content

Commit

Permalink
When fetching PHP version, do not include the 'extra' information in …
Browse files Browse the repository at this point in the history
…the version
  • Loading branch information
asgrim committed Apr 1, 2024
1 parent 2b90095 commit 3feb4b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/TargetPhp/PhpBinaryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Php\Pie\TargetPhp;

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

public function version(): string
{
$phpVersion = trim((new Process([$this->phpBinaryPath, '-r', 'echo phpversion();']))
$phpVersion = trim((new Process([
$this->phpBinaryPath,
'-r',
'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION . "." . PHP_RELEASE_VERSION;',
]))
->mustRun()
->getOutput());
Assert::stringNotEmpty($phpVersion, 'Could not determine PHP version');

// normalizing the version will throw an exception if it is not a valid version
(new VersionParser())->normalize($phpVersion);

return $phpVersion;
}

Expand Down
5 changes: 4 additions & 1 deletion test/unit/TargetPhp/PhpBinaryPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ final class PhpBinaryPathTest extends TestCase
{
public function testVersionFromCurrentProcess(): void
{
self::assertSame(PHP_VERSION, PhpBinaryPath::fromCurrentProcess()->version());
self::assertSame(
sprintf("%s.%s.%s", PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION),

Check failure on line 19 in test/unit/TargetPhp/PhpBinaryPathTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Function sprintf() should not be referenced via a fallback global name, but via a use statement.

Check failure on line 19 in test/unit/TargetPhp/PhpBinaryPathTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

String "%s.%s.%s" does not require double quotes; use single quotes instead

Check failure on line 19 in test/unit/TargetPhp/PhpBinaryPathTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Constant PHP_MAJOR_VERSION should not be referenced via a fallback global name, but via a use statement.

Check failure on line 19 in test/unit/TargetPhp/PhpBinaryPathTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Constant PHP_MINOR_VERSION should not be referenced via a fallback global name, but via a use statement.

Check failure on line 19 in test/unit/TargetPhp/PhpBinaryPathTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Constant PHP_RELEASE_VERSION should not be referenced via a fallback global name, but via a use statement.
PhpBinaryPath::fromCurrentProcess()->version()

Check failure on line 20 in test/unit/TargetPhp/PhpBinaryPathTest.php

View workflow job for this annotation

GitHub Actions / ci / QA Checks (PHPCodeSniffer [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-ac...

Multi-line function calls must have a trailing comma after the last parameter.
);
}
}

0 comments on commit 3feb4b8

Please sign in to comment.