v7.0.0-beta.1 release

This commit is contained in:
HeuJung committed 2026-04-01 10:30:52 +09:00
commit 6595fd0eb5
3967 files changed
+1875383

No files matched your search

@@ -0,0 +1,174 @@
<?php
namespace Tests\Unit\Extension\Helpers;
use App\Extension\Helpers\GithubHelper;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class GithubHelperTest extends TestCase
{
// ──────────────────────────────────────────
// parseUrl
// ──────────────────────────────────────────
#[Test]
public function parseUrl_유효한_github_url에서_owner와_repo를_추출합니다(): void
{
[$owner, $repo] = GithubHelper::parseUrl('https://github.com/owner/repo');
$this->assertSame('owner', $owner);
$this->assertSame('repo', $repo);
}
#[Test]
public function parseUrl_git_접미사_포함_url을_처리합니다(): void
{
[$owner, $repo] = GithubHelper::parseUrl('https://github.com/owner/repo.git');
$this->assertSame('owner', $owner);
$this->assertSame('repo', $repo);
}
#[Test]
public function parseUrl_끝에_슬래시가_있는_url을_처리합니다(): void
{
[$owner, $repo] = GithubHelper::parseUrl('https://github.com/owner/repo/');
$this->assertSame('owner', $owner);
$this->assertSame('repo', $repo);
}
#[Test]
public function parseUrl_잘못된_url이면_RuntimeException을_던집니다(): void
{
$this->expectException(\RuntimeException::class);
GithubHelper::parseUrl('https://example.com/foo');
}
#[Test]
public function parseUrl_빈_문자열이면_RuntimeException을_던집니다(): void
{
$this->expectException(\RuntimeException::class);
GithubHelper::parseUrl('');
}
#[Test]
public function parseUrl_경로가_부족한_url이면_RuntimeException을_던집니다(): void
{
$this->expectException(\RuntimeException::class);
GithubHelper::parseUrl('https://github.com/owner');
}
// ──────────────────────────────────────────
// buildHeaders
// ──────────────────────────────────────────
#[Test]
public function buildHeaders_토큰_없이_기본_헤더만_반환합니다(): void
{
$headers = GithubHelper::buildHeaders();
$this->assertCount(2, $headers);
$this->assertSame('User-Agent: G7', $headers[0]);
$this->assertSame('Accept: application/vnd.github.v3+json', $headers[1]);
}
#[Test]
public function buildHeaders_빈_문자열_토큰이면_Authorization을_포함하지_않습니다(): void
{
$headers = GithubHelper::buildHeaders('');
$this->assertCount(2, $headers);
foreach ($headers as $header) {
$this->assertStringNotContainsString('Authorization', $header);
}
}
#[Test]
public function buildHeaders_토큰이_있으면_Authorization_Bearer를_포함합니다(): void
{
$headers = GithubHelper::buildHeaders('ghp_test_token');
$this->assertCount(3, $headers);
$this->assertSame('Authorization: Bearer ghp_test_token', $headers[2]);
}
// ──────────────────────────────────────────
// extractStatusCode
// ──────────────────────────────────────────
#[Test]
public function extractStatusCode_200_응답을_추출합니다(): void
{
$statusCode = GithubHelper::extractStatusCode(['HTTP/1.1 200 OK']);
$this->assertSame(200, $statusCode);
}
#[Test]
public function extractStatusCode_404_응답을_추출합니다(): void
{
$statusCode = GithubHelper::extractStatusCode(['HTTP/1.1 404 Not Found']);
$this->assertSame(404, $statusCode);
}
#[Test]
public function extractStatusCode_빈_헤더에서_0을_반환합니다(): void
{
$statusCode = GithubHelper::extractStatusCode([]);
$this->assertSame(0, $statusCode);
}
#[Test]
public function extractStatusCode_리다이렉트_시_마지막_상태코드를_반환합니다(): void
{
$statusCode = GithubHelper::extractStatusCode([
'HTTP/1.1 301 Moved Permanently',
'Location: https://example.com',
'HTTP/1.1 200 OK',
]);
$this->assertSame(200, $statusCode);
}
#[Test]
public function extractStatusCode_302_후_200_리다이렉트_체인을_처리합니다(): void
{
$statusCode = GithubHelper::extractStatusCode([
'HTTP/1.1 302 Found',
'HTTP/1.1 302 Found',
'HTTP/1.1 200 OK',
]);
$this->assertSame(200, $statusCode);
}
// ──────────────────────────────────────────
// parseUrl 경계 케이스
// ──────────────────────────────────────────
#[Test]
public function parseUrl_대시와_언더스코어가_포함된_저장소명을_처리합니다(): void
{
[$owner, $repo] = GithubHelper::parseUrl('https://github.com/my-org/my_repo-name');
$this->assertSame('my-org', $owner);
$this->assertSame('my_repo-name', $repo);
}
#[Test]
public function parseUrl_ssh_스타일_url은_실패합니다(): void
{
// SSH URL도 정규식에서 매칭 가능
[$owner, $repo] = GithubHelper::parseUrl('git@github.com:owner/repo.git');
$this->assertSame('owner', $owner);
$this->assertSame('repo', $repo);
}
}
@@ -0,0 +1,287 @@
<?php
namespace Tests\Unit\Extension\Helpers;
use App\Extension\Helpers\ZipInstallHelper;
use Illuminate\Support\Facades\File;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class ZipInstallHelperTest extends TestCase
{
private string $tempDir;
protected function setUp(): void
{
parent::setUp();
$this->tempDir = storage_path('app/temp/test-zip-helper-'.uniqid());
File::ensureDirectoryExists($this->tempDir);
}
protected function tearDown(): void
{
if (File::isDirectory($this->tempDir)) {
File::deleteDirectory($this->tempDir);
}
parent::tearDown();
}
// ──────────────────────────────────────────
// extractZip
// ──────────────────────────────────────────
#[Test]
public function extractZip_유효한_zip_파일을_추출합니다(): void
{
$zipPath = $this->createTestZip(['module.json' => '{"identifier":"test-module"}']);
$extractPath = $this->tempDir.'/extracted';
ZipInstallHelper::extractZip($zipPath, $extractPath);
$this->assertTrue(File::exists($extractPath.'/module.json'));
}
#[Test]
public function extractZip_존재하지_않는_파일이면_RuntimeException을_던집니다(): void
{
$this->expectException(\RuntimeException::class);
ZipInstallHelper::extractZip('/nonexistent/path.zip', $this->tempDir.'/extracted');
}
#[Test]
public function extractZip_손상된_zip이면_RuntimeException을_던집니다(): void
{
$fakePath = $this->tempDir.'/corrupted.zip';
File::put($fakePath, 'this is not a valid zip file');
$this->expectException(\RuntimeException::class);
ZipInstallHelper::extractZip($fakePath, $this->tempDir.'/extracted');
}
// ──────────────────────────────────────────
// findManifest
// ──────────────────────────────────────────
#[Test]
public function findManifest_루트에_있는_manifest를_찾습니다(): void
{
File::put($this->tempDir.'/module.json', '{}');
$result = ZipInstallHelper::findManifest($this->tempDir, 'module.json');
$this->assertNotNull($result);
$this->assertStringEndsWith('module.json', $result);
}
#[Test]
public function findManifest_1단계_하위_디렉토리에서_manifest를_찾습니다(): void
{
$subDir = $this->tempDir.'/owner-repo-abc123';
File::ensureDirectoryExists($subDir);
File::put($subDir.'/module.json', '{}');
$result = ZipInstallHelper::findManifest($this->tempDir, 'module.json');
$this->assertNotNull($result);
$this->assertStringContainsString('owner-repo-abc123', $result);
}
#[Test]
public function findManifest_manifest가_없으면_null을_반환합니다(): void
{
$result = ZipInstallHelper::findManifest($this->tempDir, 'module.json');
$this->assertNull($result);
}
#[Test]
public function findManifest_2단계_이상_하위에서는_찾지_않습니다(): void
{
$deepDir = $this->tempDir.'/level1/level2';
File::ensureDirectoryExists($deepDir);
File::put($deepDir.'/module.json', '{}');
$result = ZipInstallHelper::findManifest($this->tempDir, 'module.json');
$this->assertNull($result);
}
// ──────────────────────────────────────────
// findAndValidateManifest
// ──────────────────────────────────────────
#[Test]
public function findAndValidateManifest_유효한_모듈_manifest를_검증합니다(): void
{
File::put($this->tempDir.'/module.json', json_encode([
'identifier' => 'test-module',
'name' => 'Test Module',
]));
$result = ZipInstallHelper::findAndValidateManifest($this->tempDir, 'module.json', 'modules');
$this->assertSame('test-module', $result['identifier']);
$this->assertArrayHasKey('config', $result);
$this->assertArrayHasKey('sourcePath', $result);
$this->assertSame('Test Module', $result['config']['name']);
}
#[Test]
public function findAndValidateManifest_유효한_플러그인_manifest를_검증합니다(): void
{
File::put($this->tempDir.'/plugin.json', json_encode([
'identifier' => 'test-plugin',
'name' => 'Test Plugin',
]));
$result = ZipInstallHelper::findAndValidateManifest($this->tempDir, 'plugin.json', 'plugins');
$this->assertSame('test-plugin', $result['identifier']);
}
#[Test]
public function findAndValidateManifest_유효한_템플릿_manifest를_검증합니다(): void
{
File::put($this->tempDir.'/template.json', json_encode([
'identifier' => 'test-template',
'name' => 'Test Template',
]));
$result = ZipInstallHelper::findAndValidateManifest($this->tempDir, 'template.json', 'templates');
$this->assertSame('test-template', $result['identifier']);
}
#[Test]
public function findAndValidateManifest_manifest가_없으면_RuntimeException을_던집니다(): void
{
$this->expectException(\RuntimeException::class);
ZipInstallHelper::findAndValidateManifest($this->tempDir, 'module.json', 'modules');
}
#[Test]
public function findAndValidateManifest_identifier가_누락되면_RuntimeException을_던집니다(): void
{
File::put($this->tempDir.'/module.json', json_encode([
'name' => 'No Identifier Module',
]));
$this->expectException(\RuntimeException::class);
ZipInstallHelper::findAndValidateManifest($this->tempDir, 'module.json', 'modules');
}
#[Test]
public function findAndValidateManifest_잘못된_json이면_RuntimeException을_던집니다(): void
{
File::put($this->tempDir.'/module.json', 'this is not valid json {{{');
$this->expectException(\RuntimeException::class);
ZipInstallHelper::findAndValidateManifest($this->tempDir, 'module.json', 'modules');
}
#[Test]
public function findAndValidateManifest_github_아카이브_구조를_처리합니다(): void
{
// GitHub ZIP은 owner-repo-hash/ 형태로 추출됨
$subDir = $this->tempDir.'/owner-repo-abc123';
File::ensureDirectoryExists($subDir);
File::put($subDir.'/module.json', json_encode([
'identifier' => 'github-module',
]));
$result = ZipInstallHelper::findAndValidateManifest($this->tempDir, 'module.json', 'modules');
$this->assertSame('github-module', $result['identifier']);
$this->assertSame(realpath($subDir), realpath($result['sourcePath']));
}
// ──────────────────────────────────────────
// extractAndValidate
// ──────────────────────────────────────────
#[Test]
public function extractAndValidate_zip_추출_후_manifest를_검증합니다(): void
{
$zipPath = $this->createTestZip(['module.json' => json_encode([
'identifier' => 'zip-module',
'name' => 'ZIP Module',
])]);
$extractPath = $this->tempDir.'/extract';
$result = ZipInstallHelper::extractAndValidate($zipPath, $extractPath, 'module.json', 'modules');
$this->assertSame('zip-module', $result['identifier']);
$this->assertSame('ZIP Module', $result['config']['name']);
}
// ──────────────────────────────────────────
// moveToPending
// ──────────────────────────────────────────
#[Test]
public function moveToPending_소스를_pending_디렉토리로_이동합니다(): void
{
// 소스 준비
$sourcePath = $this->tempDir.'/source';
File::ensureDirectoryExists($sourcePath);
File::put($sourcePath.'/module.json', '{"identifier":"test"}');
$pendingBase = $this->tempDir.'/pending';
$result = ZipInstallHelper::moveToPending($sourcePath, $pendingBase, 'test-module');
$this->assertSame($pendingBase.'/test-module', $result);
$this->assertTrue(File::exists($result.'/module.json'));
$this->assertFalse(File::isDirectory($sourcePath));
}
#[Test]
public function moveToPending_이미_존재하는_대상을_덮어씁니다(): void
{
// 소스 준비
$sourcePath = $this->tempDir.'/source';
File::ensureDirectoryExists($sourcePath);
File::put($sourcePath.'/new_file.txt', 'new content');
// 기존 pending 대상 준비
$pendingBase = $this->tempDir.'/pending';
$existingTarget = $pendingBase.'/test-module';
File::ensureDirectoryExists($existingTarget);
File::put($existingTarget.'/old_file.txt', 'old content');
$result = ZipInstallHelper::moveToPending($sourcePath, $pendingBase, 'test-module');
$this->assertTrue(File::exists($result.'/new_file.txt'));
$this->assertFalse(File::exists($result.'/old_file.txt'));
}
// ──────────────────────────────────────────
// 헬퍼 메서드
// ──────────────────────────────────────────
/**
* 테스트용 ZIP 파일을 생성합니다.
*
* @param array<string, string> $files 파일명 => 내용 매핑
* @return string 생성된 ZIP 파일 경로
*/
private function createTestZip(array $files): string
{
$zipPath = $this->tempDir.'/test.zip';
$zip = new \ZipArchive;
$zip->open($zipPath, \ZipArchive::CREATE);
foreach ($files as $name => $content) {
$zip->addFromString($name, $content);
}
$zip->close();
return $zipPath;
}
}