LicenseDumperTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. 'suffix' => 'zend',
  39. ],
  40. ],
  41. ];
  42. $dumper = new LicenseDumper();
  43. $dumper->addLibs(['fake_lib']);
  44. $dumper->dump(self::DIRECTORY);
  45. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_zend.txt');
  46. }
  47. public function testDumpWithMultipleLicenses(): void
  48. {
  49. Config::$lib = [
  50. 'fake_lib' => [
  51. 'source' => 'fake_lib',
  52. ],
  53. ];
  54. Config::$source = [
  55. 'fake_lib' => [
  56. 'license' => [
  57. [
  58. 'type' => 'text',
  59. 'text' => 'license',
  60. ],
  61. [
  62. 'type' => 'text',
  63. 'text' => 'license',
  64. ],
  65. [
  66. 'type' => 'text',
  67. 'text' => 'license',
  68. 'suffix' => 'zend',
  69. ],
  70. ],
  71. ],
  72. ];
  73. $dumper = new LicenseDumper();
  74. $dumper->addLibs(['fake_lib']);
  75. $dumper->dump(self::DIRECTORY);
  76. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt');
  77. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_1.txt');
  78. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_zend.txt');
  79. }
  80. }