v7.0.0-beta.2 release

This commit is contained in:
HeuJung committed 2026-04-20 20:37:49 +09:00
1 parent 6595fd0eb5
commit fa8eba7a0d
1165 files changed
+107118 -762127

No files matched your search

@@ -0,0 +1,133 @@
<?php
namespace Tests\Feature\Upgrade;
use App\Services\CoreUpdateService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\File;
use Tests\TestCase;
/**
* Test-2: `CoreUpdateService::reloadCoreConfigAndResync()` 가
*
* 1. config/core.php 를 디스크에서 다시 require 하고
* 2. config repository 의 'core' 네임스페이스를 갱신하며
* 3. syncCoreRolesAndPermissions / syncCoreMenus 를 재호출하여 DB 에 반영
*
* 하는지 실증한다. 경로 B (spawn) 실패 시 in-process fallback 으로 사용되는 핵심 로직.
*
* 파일 IO 경로는 config_path('core.php') 를 일시적으로 백업/복원하는 방식으로 검증한다.
* tearDown 에서 원본을 반드시 복원하므로 테스트 실패 시에도 데이터 손상은 없다.
*/
class CoreConfigReloadTest extends TestCase
{
use RefreshDatabase;
private string $coreConfigPath;
private string $backupPath;
private bool $backupCreated = false;
protected function setUp(): void
{
parent::setUp();
$this->coreConfigPath = config_path('core.php');
$this->backupPath = $this->coreConfigPath.'.test-backup-'.uniqid();
}
protected function tearDown(): void
{
// 테스트 실패 시에도 원본 복원 보장
if ($this->backupCreated && File::exists($this->backupPath)) {
File::copy($this->backupPath, $this->coreConfigPath);
File::delete($this->backupPath);
// 메모리 config 도 원본으로 재주입
config(['core' => require $this->coreConfigPath]);
}
parent::tearDown();
}
public function test_reloadCoreConfigAndResync_runs_without_error_on_current_config(): void
{
$service = app(CoreUpdateService::class);
// 현재 config/core.php 기반으로 재동기화 수행 — 예외 없이 완료해야 한다
$service->reloadCoreConfigAndResync();
// 코어 최상위 권한(module) 이 DB 에 존재해야 한다
$coreIdentifier = config('core.permissions.module.identifier', 'core');
$this->assertDatabaseHas('permissions', ['identifier' => $coreIdentifier]);
}
public function test_reloadCoreConfigAndResync_picks_up_disk_changes(): void
{
if (! File::exists($this->coreConfigPath)) {
$this->markTestSkipped('config/core.php 미존재');
}
// 1. 원본 백업
File::copy($this->coreConfigPath, $this->backupPath);
$this->backupCreated = true;
// 2. 디스크의 config/core.php 에 새 권한 1건 추가 (category/permission 둘 다 신규)
$original = require $this->coreConfigPath;
$modified = $original;
$modified['permissions']['categories'][] = [
'identifier' => 'core.test_reload_disk',
'name' => ['ko' => '테스트 재로드', 'en' => 'Test Reload'],
'description' => ['ko' => 'Test reload disk sync', 'en' => 'Test reload disk sync'],
'order' => 9999,
'permissions' => [
[
'identifier' => 'core.test_reload_disk.read',
'type' => 'admin',
'name' => ['ko' => '테스트 재로드 조회', 'en' => 'View Test Reload'],
'description' => ['ko' => 'Can view', 'en' => 'Can view'],
'order' => 1,
],
],
];
File::put($this->coreConfigPath, '<?php return '.var_export($modified, true).';');
// 3. 메모리 config 는 아직 구 값 (Laravel 부팅 시점 기준)
$memoryNames = collect(config('core.permissions.categories', []))
->pluck('identifier')
->all();
$this->assertNotContains(
'core.test_reload_disk',
$memoryNames,
'메모리 config 에는 아직 신규 권한이 없어야 한다 (디스크만 변경됨)'
);
// 4. reloadCoreConfigAndResync 호출 → 디스크 재읽기 + sync
$service = app(CoreUpdateService::class);
$service->reloadCoreConfigAndResync();
// 5. DB 에 신규 권한이 반영되어야 한다
$this->assertDatabaseHas('permissions', [
'identifier' => 'core.test_reload_disk.read',
]);
}
public function test_reloadCoreConfigAndResync_skips_gracefully_if_file_missing(): void
{
if (! File::exists($this->coreConfigPath)) {
$this->markTestSkipped('config/core.php 미존재');
}
// 원본 백업 후 일시 삭제
File::copy($this->coreConfigPath, $this->backupPath);
$this->backupCreated = true;
File::delete($this->coreConfigPath);
try {
$service = app(CoreUpdateService::class);
$service->reloadCoreConfigAndResync();
$this->assertTrue(true, 'config 파일 미존재 시 예외 없이 정상 반환해야 한다');
} finally {
// 즉시 복원 (tearDown 이전에도)
File::copy($this->backupPath, $this->coreConfigPath);
}
}
}
@@ -0,0 +1,147 @@
<?php
namespace Tests\Feature\Upgrade;
use Illuminate\Support\Facades\File;
use Tests\TestCase;
/**
* Test-1: 경로 B — `core:execute-upgrade-steps` 가 별도 PHP 프로세스로 실행될 때
* 최신 파일 기준으로 클래스를 로드함을 실증한다.
*
* 시나리오:
* 1. 임시 Service 클래스(`app/Services/TestUpgradeSpawnMarkerService.php`) 작성 —
* 프로세스 메모리 캐시와 무관한 마커 파일을 생성하는 정적 메서드 보유
* 2. 임시 upgrade 파일(`upgrades/Upgrade_0_0_1_test_spawn.php`) 작성 — run() 이
* 신규 Service 의 정적 메서드 호출
* 3. `proc_open` 으로 `php artisan core:execute-upgrade-steps --from=0.0.0 --to=0.0.1 --force`
* 실행 → 새 PHP 프로세스가 방금 작성한 파일들을 autoload 로 읽어 실행
* 4. 마커 파일 존재로 정상 호출 검증
* 5. tearDown: 임시 파일 3종(Service, Upgrade, 마커) 삭제
*
* 본 테스트가 통과하면 경로 B 구조(별도 프로세스 spawn → 최신 클래스 로드)가
* 실제로 작동함을 보장한다.
*/
class CoreUpgradeStepSpawnTest extends TestCase
{
private string $tmpServicePath;
private string $tmpUpgradePath;
private string $markerPath;
protected function setUp(): void
{
parent::setUp();
$this->tmpServicePath = base_path('app/Services/TestUpgradeSpawnMarkerService.php');
$this->tmpUpgradePath = base_path('upgrades/Upgrade_0_0_1_test_spawn.php');
$this->markerPath = storage_path('app/test-upgrade-spawn-marker-'.uniqid().'.txt');
}
protected function tearDown(): void
{
foreach ([$this->tmpServicePath, $this->tmpUpgradePath, $this->markerPath] as $p) {
if (File::exists($p)) {
File::delete($p);
}
}
parent::tearDown();
}
public function test_spawned_process_loads_fresh_classes(): void
{
if (! function_exists('proc_open')) {
$this->markTestSkipped('proc_open 미지원 환경');
}
$markerPath = addslashes($this->markerPath);
$serviceCode = <<<PHP
<?php
namespace App\\Services;
class TestUpgradeSpawnMarkerService
{
public static function writeMarker(): void
{
file_put_contents('{$markerPath}', 'spawned:'.getmypid());
}
}
PHP;
$upgradeCode = <<<'PHP'
<?php
namespace App\Upgrades;
use App\Contracts\Extension\UpgradeStepInterface;
use App\Extension\UpgradeContext;
class Upgrade_0_0_1_test_spawn implements UpgradeStepInterface
{
public function version(): string
{
return '0.0.1';
}
public function description(): string
{
return 'Test spawn marker';
}
public function run(UpgradeContext $context): void
{
\App\Services\TestUpgradeSpawnMarkerService::writeMarker();
}
}
PHP;
File::put($this->tmpServicePath, $serviceCode);
File::put($this->tmpUpgradePath, $upgradeCode);
$this->assertFileDoesNotExist($this->markerPath, '사전: 마커 파일이 없어야 한다');
$phpBinary = PHP_BINARY;
$artisan = base_path('artisan');
$commandLine = implode(' ', array_map('escapeshellarg', [
$phpBinary,
$artisan,
'core:execute-upgrade-steps',
'--from=0.0.0',
'--to=0.0.1',
'--force',
'--env=testing',
])).' 2>&1';
$descriptors = [
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];
$process = proc_open($commandLine, $descriptors, $pipes, base_path());
$this->assertIsResource($process, 'proc_open 으로 별도 프로세스 실행 성공해야 한다');
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
$exitCode = proc_close($process);
$this->assertSame(
0,
$exitCode,
"spawn 프로세스가 exit 0 으로 종료되어야 한다. output:\n{$stdout}"
);
$this->assertFileExists(
$this->markerPath,
'별도 프로세스가 최신 Service 를 autoload 로 로드하여 마커를 작성해야 한다'
);
$marker = File::get($this->markerPath);
$this->assertStringStartsWith('spawned:', $marker, '마커 내용이 예상 형식이어야 한다');
}
}
@@ -0,0 +1,132 @@
<?php
namespace Tests\Feature\Upgrade;
use App\Extension\UpgradeContext;
use App\Upgrades\Upgrade_7_0_0_beta_2;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\File;
use ReflectionMethod;
use Tests\TestCase;
/**
* Test-3: 경로 C — `Upgrade_7_0_0_beta_2::resyncCorePermissionsAndMenus()` 가
*
* 1. config/core.php 를 디스크에서 다시 require 하고
* 2. config repository 의 'core' 네임스페이스를 갱신하며
* 3. `CoreUpdateService::syncCoreRolesAndPermissions` / `syncCoreMenus` 를 재호출
*
* 하는지 실증한다. beta.1 → beta.2 특수 경로(Path C)의 단발성 로컬 로직 검증.
*
* 본 메서드는 beta.1 메모리에서 실행되는 전제로 작성되었으므로 **기존 클래스(CoreUpdateService)
* 의 기존 메서드만** 호출한다. 새로 도입된 `reloadCoreConfigAndResync` 호출 금지 (beta.1 메모리에는
* 존재하지 않음 — Fatal 유발). 본 테스트는 이 계약을 검증하기보다 "동일한 효과를 로컬 로직으로
* 달성하는지" 를 확인한다.
*/
class Upgrade700Beta2ResyncTest extends TestCase
{
use RefreshDatabase;
private string $coreConfigPath;
private string $backupPath;
private bool $backupCreated = false;
protected function setUp(): void
{
parent::setUp();
$this->coreConfigPath = config_path('core.php');
$this->backupPath = $this->coreConfigPath.'.test-backup-'.uniqid();
// upgrade 파일은 composer PSR-4 autoload 대상이 아니며 runUpgradeSteps()가
// 실행 시점에 require_once 로 수동 로드한다. 테스트에서도 동일하게 수동 로드.
require_once base_path('upgrades/Upgrade_7_0_0_beta_2.php');
}
protected function tearDown(): void
{
if ($this->backupCreated && File::exists($this->backupPath)) {
File::copy($this->backupPath, $this->coreConfigPath);
File::delete($this->backupPath);
config(['core' => require $this->coreConfigPath]);
}
parent::tearDown();
}
/**
* private resyncCorePermissionsAndMenus 를 Reflection 으로 호출합니다.
*/
private function invokeResync(Upgrade_7_0_0_beta_2 $upgrade, UpgradeContext $context): void
{
$ref = new ReflectionMethod($upgrade, 'resyncCorePermissionsAndMenus');
$ref->setAccessible(true);
$ref->invoke($upgrade, $context);
}
public function test_resyncCorePermissionsAndMenus_reads_disk_and_upserts_new_permissions(): void
{
if (! File::exists($this->coreConfigPath)) {
$this->markTestSkipped('config/core.php 미존재');
}
File::copy($this->coreConfigPath, $this->backupPath);
$this->backupCreated = true;
// 디스크에 신규 카테고리 + 권한 추가 (beta.2 신규 권한 시뮬레이션)
$original = require $this->coreConfigPath;
$modified = $original;
$modified['permissions']['categories'][] = [
'identifier' => 'core.test_beta2_path_c',
'name' => ['ko' => '경로 C 테스트', 'en' => 'Path C Test'],
'description' => ['ko' => 'Path C test category', 'en' => 'Path C test category'],
'order' => 9998,
'permissions' => [
[
'identifier' => 'core.test_beta2_path_c.read',
'type' => 'admin',
'name' => ['ko' => '경로 C 조회', 'en' => 'View Path C'],
'description' => ['ko' => 'Can view', 'en' => 'Can view'],
'order' => 1,
],
],
];
File::put($this->coreConfigPath, '<?php return '.var_export($modified, true).';');
// 메모리 config 에는 아직 신규 권한 없음
$memoryNames = collect(config('core.permissions.categories', []))
->pluck('identifier')
->all();
$this->assertNotContains('core.test_beta2_path_c', $memoryNames);
// Reflection 으로 private resyncCorePermissionsAndMenus 호출
$upgrade = new Upgrade_7_0_0_beta_2;
$context = new UpgradeContext('7.0.0-beta.1', '7.0.0-beta.2', '7.0.0-beta.2');
$this->invokeResync($upgrade, $context);
// 디스크 재로드가 성공하여 신규 권한이 DB 에 upsert 되어야 한다
$this->assertDatabaseHas('permissions', [
'identifier' => 'core.test_beta2_path_c.read',
]);
}
public function test_resyncCorePermissionsAndMenus_skips_gracefully_if_config_missing(): void
{
if (! File::exists($this->coreConfigPath)) {
$this->markTestSkipped('config/core.php 미존재');
}
File::copy($this->coreConfigPath, $this->backupPath);
$this->backupCreated = true;
File::delete($this->coreConfigPath);
try {
$upgrade = new Upgrade_7_0_0_beta_2;
$context = new UpgradeContext('7.0.0-beta.1', '7.0.0-beta.2', '7.0.0-beta.2');
$this->invokeResync($upgrade, $context);
$this->assertTrue(true, 'config 파일 미존재 시 예외 없이 로그 경고 후 정상 반환');
} finally {
File::copy($this->backupPath, $this->coreConfigPath);
}
}
}