LicenseDumperTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. declare(strict_types=1);
  3. namespace SPC\Tests\util;
  4. use PHPUnit\Framework\TestCase;
  5. use SPC\store\Config;
  6. use SPC\util\LicenseDumper;
  7. /**
  8. * @internal
  9. */
  10. final class LicenseDumperTest extends TestCase
  11. {
  12. private const DIRECTORY = __DIR__ . '/../../var/license-dump';
  13. public static function tearDownAfterClass(): void
  14. {
  15. @rmdir(self::DIRECTORY);
  16. @rmdir(dirname(self::DIRECTORY));
  17. }
  18. protected function setUp(): void
  19. {
  20. @rmdir(self::DIRECTORY);
  21. }
  22. protected function tearDown(): void
  23. {
  24. array_map('unlink', glob(self::DIRECTORY . '/*.txt'));
  25. }
  26. public function testDumpWithSingleLicense(): void
  27. {
  28. Config::$lib = [
  29. 'fake_lib' => [
  30. 'source' => 'fake_lib',
  31. ],
  32. ];
  33. Config::$source = [
  34. 'fake_lib' => [
  35. 'license' => [
  36. 'type' => 'text',
  37. 'text' => 'license',
  38. ],
  39. ],
  40. ];
  41. $dumper = new LicenseDumper();
  42. $dumper->addLibs(['fake_lib']);
  43. $dumper->dump(self::DIRECTORY);
  44. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt');
  45. }
  46. public function testDumpWithMultipleLicenses(): void
  47. {
  48. Config::$lib = [
  49. 'fake_lib' => [
  50. 'source' => 'fake_lib',
  51. ],
  52. ];
  53. Config::$source = [
  54. 'fake_lib' => [
  55. 'license' => [
  56. [
  57. 'type' => 'text',
  58. 'text' => 'license',
  59. ],
  60. [
  61. 'type' => 'text',
  62. 'text' => 'license',
  63. ],
  64. [
  65. 'type' => 'text',
  66. 'text' => 'license',
  67. ],
  68. ],
  69. ],
  70. ];
  71. $dumper = new LicenseDumper();
  72. $dumper->addLibs(['fake_lib']);
  73. $dumper->dump(self::DIRECTORY);
  74. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt');
  75. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_1.txt');
  76. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_2.txt');
  77. }
  78. }