SystemUtilTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. declare(strict_types=1);
  3. namespace SPC\Tests\builder\linux;
  4. use PHPUnit\Framework\TestCase;
  5. use SPC\builder\linux\SystemUtil;
  6. /**
  7. * @internal
  8. */
  9. class SystemUtilTest extends TestCase
  10. {
  11. public static function setUpBeforeClass(): void
  12. {
  13. if (PHP_OS_FAMILY !== 'Linux') {
  14. self::markTestIncomplete('This test is only for Linux');
  15. }
  16. }
  17. public function testIsMuslDistAndGetOSRelease()
  18. {
  19. $release = SystemUtil::getOSRelease();
  20. // we cannot ensure what is the current distro, just test the key exists
  21. $this->assertArrayHasKey('dist', $release);
  22. $this->assertArrayHasKey('ver', $release);
  23. $this->assertTrue($release['dist'] === 'alpine' && SystemUtil::isMuslDist() || $release['dist'] !== 'alpine' && !SystemUtil::isMuslDist());
  24. }
  25. public function testFindStaticLib()
  26. {
  27. $this->assertIsArray(SystemUtil::findStaticLib('ld-linux-x86-64.so.2'));
  28. }
  29. public function testGetCpuCount()
  30. {
  31. $this->assertIsInt(SystemUtil::getCpuCount());
  32. }
  33. public function testFindHeader()
  34. {
  35. $this->assertIsArray(SystemUtil::findHeader('elf.h'));
  36. }
  37. public function testGetCrossCompilePrefix()
  38. {
  39. $this->assertIsString(SystemUtil::getCrossCompilePrefix('gcc', 'x86_64'));
  40. }
  41. public function testGetCCType()
  42. {
  43. $this->assertEquals('gcc', SystemUtil::getCCType('xjfoiewjfoewof-gcc'));
  44. }
  45. public function testGetSupportedDistros()
  46. {
  47. $this->assertIsArray(SystemUtil::getSupportedDistros());
  48. }
  49. public function testFindHeaders()
  50. {
  51. $this->assertIsArray(SystemUtil::findHeaders(['elf.h']));
  52. }
  53. public function testFindStaticLibs()
  54. {
  55. $this->assertIsArray(SystemUtil::findStaticLibs(['ld-linux-x86-64.so.2']));
  56. }
  57. }