1
0
mirror of https://github.com/php/pie.git synced 2026-03-23 23:12:17 +01:00

434: add more test cases for build tool checkers

This commit is contained in:
James Titcumb
2025-12-09 16:29:09 +00:00
parent b08066a759
commit e369a29cd7
2 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
namespace Php\PieUnitTest\SelfManage\BuildTools;
use Php\Pie\Platform\TargetPhp\PhpBinaryPath;
use Php\Pie\Platform\TargetPlatform;
use Php\Pie\SelfManage\BuildTools\BinaryBuildToolFinder;
use Php\Pie\SelfManage\BuildTools\PackageManager;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(BinaryBuildToolFinder::class)]
final class BinaryBuildToolFinderTest extends TestCase
{
public function testCheckFailsToFindTool(): void
{
self::assertFalse((new BinaryBuildToolFinder('this-should-not-be-anything-in-path', []))->check());
}
public function testCheckFindsTool(): void
{
self::assertTrue((new BinaryBuildToolFinder('echo', []))->check());
}
public function testPackageNameIsNullWhenNoPackageConfiguredForPackageManager(): void
{
self::assertNull(
(new BinaryBuildToolFinder('a', []))
->packageNameFor(
PackageManager::Test,
TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromCurrentProcess(), null),
),
);
}
public function testPackageNameIsNullWhenPackageConfiguredForPackageManagerIsNull(): void
{
self::assertNull(
(new BinaryBuildToolFinder('a', [PackageManager::Test->value => null]))
->packageNameFor(
PackageManager::Test,
TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromCurrentProcess(), null),
),
);
}
public function testPackageNameIsReturnedWhenPackageConfiguredForPackageManager(): void
{
self::assertSame(
'the-package',
(new BinaryBuildToolFinder('a', [PackageManager::Test->value => 'the-package']))
->packageNameFor(
PackageManager::Test,
TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromCurrentProcess(), null),
),
);
}
public function testPackageNameIsReturnedWithFormattingWhenPackageConfiguredForPackageManager(): void
{
$phpBinary = PhpBinaryPath::fromCurrentProcess();
self::assertSame(
'php' . $phpBinary->majorVersion() . $phpBinary->minorVersion() . '-dev',
(new BinaryBuildToolFinder('a', [PackageManager::Test->value => 'php{major}{minor}-dev']))
->packageNameFor(
PackageManager::Test,
TargetPlatform::fromPhpBinaryPath($phpBinary, null),
),
);
}
}

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace Php\PieUnitTest\SelfManage\BuildTools;
use Php\Pie\SelfManage\BuildTools\PackageManager;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(PackageManager::class)]
final class PackageManagerTest extends TestCase
{
public function testInstallCommand(): void
{
self::assertSame(
['echo', '"fake installing a, b"'],
PackageManager::Test->installCommand(['a', 'b']),
);
self::assertSame(
['apt-get', 'install', '-y', '--no-install-recommends', '--no-install-suggests', 'a', 'b'],
PackageManager::Apt->installCommand(['a', 'b']),
);
self::assertSame(
['apk', 'add', '--no-cache', 'a', 'b'],
PackageManager::Apk->installCommand(['a', 'b']),
);
}
}