From e369a29cd7c4fdda2c794c32ee84b33fdffae1e7 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Tue, 9 Dec 2025 16:29:09 +0000 Subject: [PATCH] 434: add more test cases for build tool checkers --- .../BuildTools/BinaryBuildToolFinderTest.php | 74 +++++++++++++++++++ .../BuildTools/PackageManagerTest.php | 29 ++++++++ 2 files changed, 103 insertions(+) create mode 100644 test/unit/SelfManage/BuildTools/BinaryBuildToolFinderTest.php create mode 100644 test/unit/SelfManage/BuildTools/PackageManagerTest.php diff --git a/test/unit/SelfManage/BuildTools/BinaryBuildToolFinderTest.php b/test/unit/SelfManage/BuildTools/BinaryBuildToolFinderTest.php new file mode 100644 index 0000000..ac7c27d --- /dev/null +++ b/test/unit/SelfManage/BuildTools/BinaryBuildToolFinderTest.php @@ -0,0 +1,74 @@ +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), + ), + ); + } +} diff --git a/test/unit/SelfManage/BuildTools/PackageManagerTest.php b/test/unit/SelfManage/BuildTools/PackageManagerTest.php new file mode 100644 index 0000000..53a4092 --- /dev/null +++ b/test/unit/SelfManage/BuildTools/PackageManagerTest.php @@ -0,0 +1,29 @@ +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']), + ); + } +}