mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
111 lines
2.8 KiB
PHP
111 lines
2.8 KiB
PHP
<?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
|
|
{
|
|
private const DIRECTORY = __DIR__ . '/../../var/license-dump';
|
|
|
|
public static function tearDownAfterClass(): void
|
|
{
|
|
@rmdir(self::DIRECTORY);
|
|
@rmdir(dirname(self::DIRECTORY));
|
|
}
|
|
|
|
protected function setUp(): void
|
|
{
|
|
@rmdir(self::DIRECTORY);
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
array_map('unlink', glob(self::DIRECTORY . '/*.txt'));
|
|
}
|
|
|
|
public function testDumpWithSingleLicense(): void
|
|
{
|
|
$bak = [
|
|
'source' => Config::$source,
|
|
'lib' => Config::$lib,
|
|
];
|
|
Config::$lib = [
|
|
'lib-base' => ['type' => 'root'],
|
|
'php' => ['type' => 'root'],
|
|
'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');
|
|
// restore
|
|
Config::$source = $bak['source'];
|
|
Config::$lib = $bak['lib'];
|
|
}
|
|
|
|
public function testDumpWithMultipleLicenses(): void
|
|
{
|
|
$bak = [
|
|
'source' => Config::$source,
|
|
'lib' => Config::$lib,
|
|
];
|
|
Config::$lib = [
|
|
'lib-base' => ['type' => 'root'],
|
|
'php' => ['type' => 'root'],
|
|
'fake_lib' => [
|
|
'source' => 'fake_lib',
|
|
],
|
|
];
|
|
Config::$source = [
|
|
'fake_lib' => [
|
|
'license' => [
|
|
[
|
|
'type' => 'text',
|
|
'text' => 'license',
|
|
],
|
|
[
|
|
'type' => 'text',
|
|
'text' => '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');
|
|
$this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_1.txt');
|
|
$this->assertFileExists(self::DIRECTORY . '/lib_fake_lib_2.txt');
|
|
|
|
// restore
|
|
Config::$source = $bak['source'];
|
|
Config::$lib = $bak['lib'];
|
|
}
|
|
}
|