Skip to content

Commit

Permalink
Merge pull request #47 from asgrim/fix-php-binary-path-with-older-php…
Browse files Browse the repository at this point in the history
…-versions

Fix php binary path with older php versions
  • Loading branch information
asgrim authored Sep 24, 2024
2 parents 1e53f0f + b676558 commit b7d9efe
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Platform/TargetPhp/PhpBinaryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
51 changes: 51 additions & 0 deletions test/unit/Platform/TargetPhp/PhpBinaryPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -185,4 +189,51 @@ public function testExtensionPath(): void
$phpBinary->extensionPath(),
);
}

/**
* @return array<string, array{0: string}>
*
* @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());
}
}

0 comments on commit b7d9efe

Please sign in to comment.