From 6a1553cf194354998e79ed03d0048da8f20ae49e Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 24 Sep 2024 20:18:11 +0100 Subject: [PATCH 1/2] Added test for older versions of PHP being invoked in PhpBinaryPath --- .../Platform/TargetPhp/PhpBinaryPathTest.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php b/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php index c0d7802..a7c2f5a 100644 --- a/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php +++ b/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php @@ -10,11 +10,15 @@ use Php\Pie\Platform\TargetPhp\Exception\InvalidPhpBinaryPath; use Php\Pie\Platform\TargetPhp\PhpBinaryPath; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; +use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; use function array_combine; +use function array_filter; use function array_map; +use function array_unique; use function assert; use function defined; use function dirname; @@ -185,4 +189,51 @@ public function testExtensionPath(): void $phpBinary->extensionPath(), ); } + + /** + * @return array + * + * @psalm-suppress PossiblyUnusedMethod https://github.com/psalm/psalm-plugin-phpunit/issues/131 + */ + public function phpPathProvider(): array + { + $possiblePhpBinaries = array_filter( + array_unique([ + '/usr/bin/php', + (string) (new PhpExecutableFinder())->find(), + '/usr/bin/php8.4', + '/usr/bin/php8.3', + '/usr/bin/php8.2', + '/usr/bin/php8.1', + '/usr/bin/php8.0', + '/usr/bin/php7.4', + '/usr/bin/php7.3', + '/usr/bin/php7.2', + '/usr/bin/php7.1', + '/usr/bin/php7.0', + '/usr/bin/php5.6', + ]), + static fn (string $phpPath) => file_exists($phpPath) && is_executable($phpPath), + ); + + return array_combine( + $possiblePhpBinaries, + array_map(static fn (string $phpPath) => [$phpPath], $possiblePhpBinaries), + ); + } + + #[DataProvider('phpPathProvider')] + public function testDifferentVersionsOfPhp(string $phpPath): void + { + assert($phpPath !== ''); + $php = PhpBinaryPath::fromPhpBinaryPath($phpPath); + self::assertArrayHasKey('Core', $php->extensions()); + self::assertNotEmpty($php->extensionPath()); + self::assertInstanceOf(OperatingSystem::class, $php->operatingSystem()); + self::assertNotEmpty($php->version()); + self::assertNotEmpty($php->majorMinorVersion()); + self::assertInstanceOf(Architecture::class, $php->machineType()); + self::assertGreaterThan(0, $php->phpIntSize()); + self::assertNotEmpty($php->phpinfo()); + } } From b6765587f3c1bd886a9634bea3e27f64954c5f95 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 24 Sep 2024 20:18:29 +0100 Subject: [PATCH 2/2] Fix older versions of PHP being broken in PhpBinaryPath extensions() --- src/Platform/TargetPhp/PhpBinaryPath.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Platform/TargetPhp/PhpBinaryPath.php b/src/Platform/TargetPhp/PhpBinaryPath.php index ee8697d..d7da68b 100644 --- a/src/Platform/TargetPhp/PhpBinaryPath.php +++ b/src/Platform/TargetPhp/PhpBinaryPath.php @@ -119,7 +119,13 @@ static function ($extension) { }, $exts ); -echo implode("\n", array_map(fn($k, $v) => sprintf('%s:%s', $k, $v), $exts, $extVersions)); +echo implode("\n", array_map( + static function ($k, $v) { + return sprintf('%s:%s', $k, $v); + }, + $exts, + $extVersions +)); PHP, ])) ->mustRun()