ConfigTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. declare(strict_types=1);
  3. namespace SPC\Tests\store;
  4. use PHPUnit\Framework\TestCase;
  5. use SPC\exception\FileSystemException;
  6. use SPC\exception\WrongUsageException;
  7. use SPC\store\Config;
  8. use SPC\store\FileSystem;
  9. /**
  10. * @internal
  11. */
  12. class ConfigTest extends TestCase
  13. {
  14. /**
  15. * @throws FileSystemException
  16. */
  17. public static function setUpBeforeClass(): void
  18. {
  19. $testdir = WORKING_DIR . '/.configtest';
  20. FileSystem::createDir($testdir);
  21. FileSystem::writeFile($testdir . '/lib.json', file_get_contents(ROOT_DIR . '/config/lib.json'));
  22. FileSystem::writeFile($testdir . '/ext.json', file_get_contents(ROOT_DIR . '/config/ext.json'));
  23. FileSystem::writeFile($testdir . '/source.json', file_get_contents(ROOT_DIR . '/config/source.json'));
  24. FileSystem::loadConfigArray('lib', $testdir);
  25. FileSystem::loadConfigArray('ext', $testdir);
  26. FileSystem::loadConfigArray('source', $testdir);
  27. }
  28. /**
  29. * @throws FileSystemException
  30. */
  31. public static function tearDownAfterClass(): void
  32. {
  33. FileSystem::removeDir(WORKING_DIR . '/.configtest');
  34. }
  35. /**
  36. * @throws FileSystemException
  37. */
  38. public function testGetExts()
  39. {
  40. $this->assertTrue(is_assoc_array(Config::getExts()));
  41. }
  42. /**
  43. * @throws FileSystemException
  44. * @throws WrongUsageException
  45. */
  46. public function testGetLib()
  47. {
  48. $this->assertIsArray(Config::getLib('zlib'));
  49. match (PHP_OS_FAMILY) {
  50. 'FreeBSD', 'Darwin', 'Linux' => $this->assertStringEndsWith('.a', Config::getLib('zlib', 'static-libs', [])[0]),
  51. 'Windows' => $this->assertStringEndsWith('.lib', Config::getLib('zlib', 'static-libs', [])[0]),
  52. default => null,
  53. };
  54. }
  55. /**
  56. * @throws WrongUsageException
  57. * @throws FileSystemException
  58. */
  59. public function testGetExt()
  60. {
  61. $this->assertIsArray(Config::getExt('bcmath'));
  62. $this->assertEquals('builtin', Config::getExt('bcmath', 'type'));
  63. }
  64. /**
  65. * @throws FileSystemException
  66. */
  67. public function testGetSources()
  68. {
  69. $this->assertTrue(is_assoc_array(Config::getSources()));
  70. }
  71. /**
  72. * @throws FileSystemException
  73. */
  74. public function testGetSource()
  75. {
  76. $this->assertIsArray(Config::getSource('php-src'));
  77. }
  78. /**
  79. * @throws FileSystemException
  80. */
  81. public function testGetLibs()
  82. {
  83. $this->assertTrue(is_assoc_array(Config::getLibs()));
  84. }
  85. }