v7.0.0-beta.2 release

This commit is contained in:
HeuJung
2026-04-20 20:37:49 +09:00
parent 6595fd0eb5
commit fa8eba7a0d
1165 changed files with 107118 additions and 762127 deletions
+13 -88
View File
@@ -7,7 +7,6 @@ use App\Extension\ModuleManager;
use App\Extension\PluginManager;
use App\Models\Module;
use App\Models\Plugin;
use App\Services\CacheService;
use Illuminate\Support\Facades\Cache;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
@@ -15,16 +14,22 @@ use Tests\TestCase;
/**
* 모듈/플러그인 상태 캐시 통합 테스트
*
* 빈 배열 캐싱 금지 기능이 모듈/플러그인 활성 목록 조회에
* 올바르게 적용되는지 검증합니다.
* 새 CacheInterface 기반 캐시 키(`g7:core:ext.modules.active_identifiers` 등)와
* Trait 의 캐시 무효화 동작을 검증합니다.
*
* 참고: 이전의 "빈 배열 캐시 금지" 정책은 새 시스템에서 폐기되었습니다.
* 대신 모듈 설치/활성화 훅에서 invalidateModuleStatusCache() 로 확실히 무효화합니다.
*/
class ModuleCacheTest extends TestCase
{
private const MODULE_ACTIVE_KEY = 'g7:core:ext.modules.active_identifiers';
private const PLUGIN_ACTIVE_KEY = 'g7:core:ext.plugins.active_identifiers';
protected function setUp(): void
{
parent::setUp();
// 캐시 초기화
Cache::flush();
ModuleManager::invalidateModuleStatusCache();
PluginManager::invalidatePluginStatusCache();
@@ -36,62 +41,23 @@ class ModuleCacheTest extends TestCase
parent::tearDown();
}
/**
* 활성 모듈이 없을 때 빈 배열이 캐시되지 않아야 합니다.
*/
#[Test]
public function it_does_not_cache_empty_active_modules(): void
{
// 기존 상태 백업
$originalStatuses = Module::pluck('status', 'id')->toArray();
try {
// 모든 모듈 비활성화
Module::query()->update(['status' => ExtensionStatus::Inactive->value]);
// 캐시 무효화
ModuleManager::invalidateModuleStatusCache();
// 첫 번째 조회
$result1 = ModuleManager::getActiveModuleIdentifiers();
$this->assertEquals([], $result1);
// 캐시에 저장되지 않았는지 확인
$cacheKey = CacheService::key('modules', 'active_identifiers');
$this->assertNull(Cache::get($cacheKey), '빈 배열이 캐시에 저장되면 안됩니다');
// 두 번째 조회도 동일하게 빈 배열 반환
$result2 = ModuleManager::getActiveModuleIdentifiers();
$this->assertEquals([], $result2);
} finally {
// 원래 상태 복원
foreach ($originalStatuses as $id => $status) {
Module::where('id', $id)->update(['status' => $status]);
}
}
}
/**
* 활성 모듈이 있을 때 정상적으로 캐시되어야 합니다.
*/
#[Test]
public function it_caches_non_empty_active_modules(): void
{
// 최소 1개 활성 모듈 확인
$activeModule = Module::where('status', ExtensionStatus::Active->value)->first();
if (! $activeModule) {
$this->markTestSkipped('활성 모듈이 없습니다.');
}
// 캐시 무효화 후 조회
ModuleManager::invalidateModuleStatusCache();
$result = ModuleManager::getActiveModuleIdentifiers();
$this->assertNotEmpty($result, '활성 모듈 목록이 비어있으면 안됩니다');
// 캐시에 저장되었는지 확인
$cacheKey = CacheService::key('modules', 'active_identifiers');
$cached = Cache::get($cacheKey);
$cached = Cache::get(self::MODULE_ACTIVE_KEY);
$this->assertNotNull($cached, '활성 모듈 목록이 캐시되어야 합니다');
$this->assertEquals($result, $cached);
}
@@ -102,54 +68,17 @@ class ModuleCacheTest extends TestCase
#[Test]
public function it_invalidates_cache_on_status_change(): void
{
// 초기 조회 (캐시 생성)
$initialResult = ModuleManager::getActiveModuleIdentifiers();
if (empty($initialResult)) {
$this->markTestSkipped('활성 모듈이 없습니다.');
}
$cacheKey = CacheService::key('modules', 'active_identifiers');
$this->assertNotNull(Cache::get(self::MODULE_ACTIVE_KEY), '초기 캐시가 생성되어야 합니다');
// 캐시 확인
$this->assertNotNull(Cache::get($cacheKey), '초기 캐시가 생성되어야 합니다');
// 캐시 무효화
ModuleManager::invalidateModuleStatusCache();
// 캐시 삭제 확인
$this->assertNull(Cache::get($cacheKey), '캐시가 무효화되어야 합니다');
}
/**
* 활성 플러그인이 없을 때 빈 배열이 캐시되지 않아야 합니다.
*/
#[Test]
public function it_does_not_cache_empty_active_plugins(): void
{
// 기존 상태 백업
$originalStatuses = Plugin::pluck('status', 'id')->toArray();
try {
// 모든 플러그인 비활성화
Plugin::query()->update(['status' => ExtensionStatus::Inactive->value]);
// 캐시 무효화
PluginManager::invalidatePluginStatusCache();
// 조회
$result = PluginManager::getActivePluginIdentifiers();
$this->assertEquals([], $result);
// 캐시에 저장되지 않았는지 확인
$cacheKey = CacheService::key('plugins', 'active_identifiers');
$this->assertNull(Cache::get($cacheKey), '빈 배열이 캐시에 저장되면 안됩니다');
} finally {
// 원래 상태 복원
foreach ($originalStatuses as $id => $status) {
Plugin::where('id', $id)->update(['status' => $status]);
}
}
$this->assertNull(Cache::get(self::MODULE_ACTIVE_KEY), '캐시가 무효화되어야 합니다');
}
/**
@@ -158,21 +87,17 @@ class ModuleCacheTest extends TestCase
#[Test]
public function it_caches_non_empty_active_plugins(): void
{
// 최소 1개 활성 플러그인 확인
$activePlugin = Plugin::where('status', ExtensionStatus::Active->value)->first();
if (! $activePlugin) {
$this->markTestSkipped('활성 플러그인이 없습니다.');
}
// 캐시 무효화 후 조회
PluginManager::invalidatePluginStatusCache();
$result = PluginManager::getActivePluginIdentifiers();
$this->assertNotEmpty($result, '활성 플러그인 목록이 비어있으면 안됩니다');
// 캐시에 저장되었는지 확인
$cacheKey = CacheService::key('plugins', 'active_identifiers');
$cached = Cache::get($cacheKey);
$cached = Cache::get(self::PLUGIN_ACTIVE_KEY);
$this->assertNotNull($cached, '활성 플러그인 목록이 캐시되어야 합니다');
$this->assertEquals($result, $cached);
}