mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-08 01:15:37 +08:00
Add simple unit test
This commit is contained in:
committed by
Jerry Ma
parent
8d348b9e14
commit
33798ff108
80
tests/SPC/util/LicenseDumperTest.php
Normal file
80
tests/SPC/util/LicenseDumperTest.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?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 = '../../var/license-dump';
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
public function testDumpWithMultipleLicenses(): void
|
||||
{
|
||||
Config::$lib = [
|
||||
'fake_lib' => [
|
||||
'source' => 'fake_lib',
|
||||
],
|
||||
];
|
||||
Config::$source = [
|
||||
'fake_lib' => [
|
||||
'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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user