LicenseDumperTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 = '../../var/license-dump';
  13. protected function setUp(): void
  14. {
  15. @rmdir(self::DIRECTORY);
  16. }
  17. protected function tearDown(): void
  18. {
  19. array_map('unlink', glob(self::DIRECTORY . '/*.txt'));
  20. }
  21. public function testDumpWithSingleLicense(): void
  22. {
  23. Config::$lib = [
  24. 'fake_lib' => [
  25. 'source' => 'fake_lib',
  26. ],
  27. ];
  28. Config::$source = [
  29. 'fake_lib' => [
  30. 'license' => [
  31. 'type' => 'text',
  32. 'text' => 'license',
  33. 'suffix' => 'zend',
  34. ],
  35. ],
  36. ];
  37. $dumper = new LicenseDumper();
  38. $dumper->addLibs(['fake_lib']);
  39. $dumper->dump(self::DIRECTORY);
  40. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_zend.txt');
  41. }
  42. public function testDumpWithMultipleLicenses(): void
  43. {
  44. Config::$lib = [
  45. 'fake_lib' => [
  46. 'source' => 'fake_lib',
  47. ],
  48. ];
  49. Config::$source = [
  50. 'fake_lib' => [
  51. 'license' => [
  52. [
  53. 'type' => 'text',
  54. 'text' => 'license',
  55. ],
  56. [
  57. 'type' => 'text',
  58. 'text' => 'license',
  59. ],
  60. [
  61. 'type' => 'text',
  62. 'text' => 'license',
  63. 'suffix' => 'zend',
  64. ],
  65. ],
  66. ],
  67. ];
  68. $dumper = new LicenseDumper();
  69. $dumper->addLibs(['fake_lib']);
  70. $dumper->dump(self::DIRECTORY);
  71. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt');
  72. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_1.txt');
  73. $this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_zend.txt');
  74. }
  75. }