static-php-cli/tests/SPC/util/LicenseDumperTest.php

92 lines
2.2 KiB
PHP
Raw Normal View History

2023-09-05 12:28:12 +02:00
<?php
declare(strict_types=1);
namespace SPC\Tests\util;
use PHPUnit\Framework\TestCase;
use SPC\store\Config;
use SPC\util\LicenseDumper;
/**
* @internal
*/
final class LicenseDumperTest extends TestCase
{
2024-01-29 09:42:08 +08:00
private const DIRECTORY = __DIR__ . '/../../var/license-dump';
public static function tearDownAfterClass(): void
{
@rmdir(self::DIRECTORY);
@rmdir(dirname(self::DIRECTORY));
}
2023-09-05 12:28:12 +02:00
protected function setUp(): void
{
@rmdir(self::DIRECTORY);
}
protected function tearDown(): void
{
array_map('unlink', glob(self::DIRECTORY . '/*.txt'));
}
public function testDumpWithSingleLicense(): void
{
Config::$lib = [
'fake_lib' => [
'source' => 'fake_lib',
],
];
Config::$source = [
'fake_lib' => [
'license' => [
'type' => 'text',
'text' => 'license',
],
],
];
$dumper = new LicenseDumper();
$dumper->addLibs(['fake_lib']);
$dumper->dump(self::DIRECTORY);
$this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt');
2023-09-05 12:28:12 +02:00
}
public function testDumpWithMultipleLicenses(): void
{
Config::$lib = [
'fake_lib' => [
'source' => 'fake_lib',
],
];
Config::$source = [
'fake_lib' => [
'license' => [
[
'type' => 'text',
'text' => 'license',
],
[
'type' => 'text',
'text' => 'license',
],
2023-09-05 20:05:09 +02:00
[
'type' => 'text',
'text' => 'license',
],
2023-09-05 12:28:12 +02:00
],
],
];
$dumper = new LicenseDumper();
$dumper->addLibs(['fake_lib']);
$dumper->dump(self::DIRECTORY);
$this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_0.txt');
$this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_1.txt');
$this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_2.txt');
2023-09-05 12:28:12 +02:00
}
}