chore(payment): NHN KCP와 NICE 결제 플러그인 개발 브랜치 분리
정식 develop에서는 기본 번들 정책에 따라 제거된 결제 플러그인을 별도 개발 브랜치에서 계속 유지보수할 수 있도록 복원한다.
This commit is contained in:
1 parent
49b21e788c
commit
657f546efc
651 files changed
+49118
-20476
No files matched your search
@@ -1,350 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Extension;
|
||||
|
||||
use App\Extension\Helpers\CoreBackupHelper;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* CoreBackupHelper::computeApplyList() 단위 테스트 (공개 #64)
|
||||
*
|
||||
* `core:update` 기본(증분) 모드의 3-way 판정을 검증합니다:
|
||||
* - base == theirs (코어 미변경) → 적용 목록 제외 (사용자 상태 보존)
|
||||
* - base 없음 (신규) → added 로 목록 포함
|
||||
* - size 다름 / md5 다름 (변경) → changed 로 목록 포함
|
||||
* - symlink / excludes / protected → 목록 제외
|
||||
*/
|
||||
class CoreBackupHelperApplyListTest extends TestCase
|
||||
{
|
||||
private string $basePath; // 백업 스냅샷 (base = 구버전 원본)
|
||||
|
||||
private string $theirsPath; // _pending (theirs = 신 버전)
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$root = storage_path('app/test_apply_list_'.uniqid());
|
||||
$this->basePath = $root.DIRECTORY_SEPARATOR.'base';
|
||||
$this->theirsPath = $root.DIRECTORY_SEPARATOR.'theirs';
|
||||
|
||||
File::ensureDirectoryExists($this->basePath);
|
||||
File::ensureDirectoryExists($this->theirsPath);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$root = dirname($this->basePath);
|
||||
if (File::isDirectory($root)) {
|
||||
File::deleteDirectory($root);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* base == theirs 인 파일은 적용 목록에서 제외됩니다 (코어 미변경 → 보존).
|
||||
*/
|
||||
public function test_unchanged_file_is_excluded_from_apply_list(): void
|
||||
{
|
||||
$this->writeBoth('app/Same.php', '<?php // identical', '<?php // identical');
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
['app'],
|
||||
[],
|
||||
[],
|
||||
);
|
||||
|
||||
$this->assertNotContains('app/Same.php', $result['apply']);
|
||||
$this->assertSame(0, $result['added_count']);
|
||||
$this->assertSame(0, $result['changed_count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* base 에 없고 theirs 에만 있는 파일은 added 로 포함됩니다 (신규).
|
||||
*/
|
||||
public function test_new_file_is_added_to_apply_list(): void
|
||||
{
|
||||
File::ensureDirectoryExists($this->theirsPath.DIRECTORY_SEPARATOR.'app');
|
||||
File::put($this->theirsPath.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'New.php', '<?php // new');
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
['app'],
|
||||
[],
|
||||
[],
|
||||
);
|
||||
|
||||
$this->assertContains('app/New.php', $result['apply']);
|
||||
$this->assertSame(1, $result['added_count']);
|
||||
$this->assertSame(0, $result['changed_count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* size 가 다른 파일은 md5 계산 없이 changed 로 포함됩니다.
|
||||
*/
|
||||
public function test_size_differing_file_is_changed(): void
|
||||
{
|
||||
$this->writeBoth('app/Grown.php', '<?php // small', '<?php // this content is clearly longer than base');
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
['app'],
|
||||
[],
|
||||
[],
|
||||
);
|
||||
|
||||
$this->assertContains('app/Grown.php', $result['apply']);
|
||||
$this->assertSame(1, $result['changed_count']);
|
||||
$this->assertSame(0, $result['added_count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* size 는 같지만 내용(md5)이 다른 파일은 changed 로 포함됩니다.
|
||||
*/
|
||||
public function test_same_size_different_content_file_is_changed(): void
|
||||
{
|
||||
// 동일 길이(12), 내용만 다름
|
||||
$this->writeBoth('app/Edited.php', 'AAAAAAAAAAAA', 'BBBBBBBBBBBB');
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
['app'],
|
||||
[],
|
||||
[],
|
||||
);
|
||||
|
||||
$this->assertContains('app/Edited.php', $result['apply']);
|
||||
$this->assertSame(1, $result['changed_count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* excludes 패턴에 매칭되는 파일은 목록에서 제외됩니다.
|
||||
*/
|
||||
public function test_excluded_file_is_not_in_apply_list(): void
|
||||
{
|
||||
// theirs 에만 존재하지만 node_modules 하위 → 제외
|
||||
File::ensureDirectoryExists($this->theirsPath.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'node_modules');
|
||||
File::put($this->theirsPath.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'node_modules'.DIRECTORY_SEPARATOR.'x.js', 'x');
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
['app'],
|
||||
[],
|
||||
['node_modules'],
|
||||
);
|
||||
|
||||
$this->assertSame([], $result['apply']);
|
||||
}
|
||||
|
||||
/**
|
||||
* protected_paths 하위 항목은 목록에서 제외됩니다.
|
||||
*/
|
||||
public function test_protected_path_file_is_not_in_apply_list(): void
|
||||
{
|
||||
File::ensureDirectoryExists($this->theirsPath.DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'app');
|
||||
File::put($this->theirsPath.DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'runtime.txt', 'data');
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
['storage'],
|
||||
['storage'],
|
||||
[],
|
||||
);
|
||||
|
||||
$this->assertSame([], $result['apply']);
|
||||
}
|
||||
|
||||
/**
|
||||
* targets 에 명시된 `{domain}/_bundled` 경로는 상위 protected(`{domain}`)보다
|
||||
* 우선하여 apply 목록에 포함됩니다 (공개 #64 / 내부 #452 회귀).
|
||||
*
|
||||
* 배경: `config/app.php` 의 update.targets 에는 `modules/_bundled`,
|
||||
* `plugins/_bundled`, `templates/_bundled`, `lang-packs/_bundled` 가 있고,
|
||||
* protected_paths 에는 부모 `modules`, `plugins`, `templates`, `lang-packs` 가
|
||||
* 있다. protected 는 자동 발견 폴백이 활성 서브디렉토리(`modules/sirsoft-*`)를
|
||||
* 통째로 삭제하는 회귀(#347)를 막기 위한 것인데, 정상 증분 흐름의 apply 산출에서
|
||||
* `{domain}/_bundled/...` 파일이 `{domain}/` 접두사에 걸려 통째로 제외되면
|
||||
* 코어 업데이트 시 번들 확장의 새 파일(composer.json·vendor-bundle.*)이
|
||||
* 반영되지 않는다. targets 에 더 구체적으로 명시된 경로는 상위 protected 를
|
||||
* 오버라이드해야 한다. 4종 확장(모듈/플러그인/템플릿/언어팩) 전수 검증.
|
||||
*
|
||||
* @dataProvider bundledDomainProvider
|
||||
*/
|
||||
public function test_bundled_target_overrides_parent_protected_path(string $domain): void
|
||||
{
|
||||
$bundledTarget = "{$domain}/_bundled";
|
||||
|
||||
// theirs 에만 존재하는 신규 번들 파일 (added)
|
||||
$newRel = "{$bundledTarget}/vendor-ext/composer.json";
|
||||
$newAbs = $this->theirsPath.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $newRel);
|
||||
File::ensureDirectoryExists(dirname($newAbs));
|
||||
File::put($newAbs, '{"version":"1.0.1"}');
|
||||
|
||||
// base·theirs 양쪽에 있지만 내용이 다른 번들 파일 (changed)
|
||||
$this->writeBoth(
|
||||
"{$bundledTarget}/vendor-ext/vendor-bundle.json",
|
||||
'{"composer_json_sha256":"old"}',
|
||||
'{"composer_json_sha256":"new-value-differs"}',
|
||||
);
|
||||
|
||||
// 활성 서브디렉토리(=targets 밖, protected 로 보존되어야 함)
|
||||
$activeRel = "{$domain}/vendor-ext-active";
|
||||
File::ensureDirectoryExists($this->theirsPath.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $activeRel));
|
||||
File::put(
|
||||
$this->theirsPath.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, "{$activeRel}/active.php"),
|
||||
'active',
|
||||
);
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
[$bundledTarget], // targets: _bundled 만 명시
|
||||
[$domain, 'storage', 'vendor'], // protected: 부모 도메인 포함 (실제 config 반영)
|
||||
['node_modules', '.git'],
|
||||
);
|
||||
|
||||
// _bundled 하위 신규/변경 파일은 apply 목록에 포함되어야 한다
|
||||
$this->assertContains("{$bundledTarget}/vendor-ext/composer.json", $result['apply']);
|
||||
$this->assertContains("{$bundledTarget}/vendor-ext/vendor-bundle.json", $result['apply']);
|
||||
$this->assertSame(1, $result['added_count']);
|
||||
$this->assertSame(1, $result['changed_count']);
|
||||
|
||||
// 활성 서브디렉토리(targets 밖)는 순회 대상이 아니므로 목록에 없어야 한다
|
||||
$this->assertNotContains("{$activeRel}/active.php", $result['apply']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 4종 번들 확장 도메인 (config/app.php 의 targets/protected_paths 실제 조합).
|
||||
*
|
||||
* @return array<string, array{string}>
|
||||
*/
|
||||
public static function bundledDomainProvider(): array
|
||||
{
|
||||
return [
|
||||
'modules' => ['modules'],
|
||||
'plugins' => ['plugins'],
|
||||
'templates' => ['templates'],
|
||||
'lang-packs' => ['lang-packs'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* target 과 protected 가 정확히 동일한 경로면 여전히 제외됩니다 (기존 방어 유지).
|
||||
*
|
||||
* `_bundled` 오버라이드는 "targets 가 protected 보다 더 구체적(하위)일 때"만
|
||||
* 적용된다. target == protected (예: storage) 는 제외가 정상.
|
||||
*/
|
||||
public function test_target_equal_to_protected_is_still_excluded(): void
|
||||
{
|
||||
File::ensureDirectoryExists($this->theirsPath.DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'app');
|
||||
File::put($this->theirsPath.DIRECTORY_SEPARATOR.'storage'.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'runtime.txt', 'data');
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
['storage'],
|
||||
['storage'],
|
||||
[],
|
||||
);
|
||||
|
||||
$this->assertSame([], $result['apply']);
|
||||
}
|
||||
|
||||
/**
|
||||
* added 와 changed 가 섞여 있을 때 apply 목록이 정렬되어 둘 다 포함합니다.
|
||||
*/
|
||||
public function test_apply_list_merges_added_and_changed_sorted(): void
|
||||
{
|
||||
$this->writeBoth('app/Zeta.php', 'old', 'new-different'); // changed
|
||||
File::put($this->theirsPath.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'Alpha.php', 'brand-new'); // added
|
||||
$this->writeBoth('app/Keep.php', 'same', 'same'); // unchanged → 제외
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
['app'],
|
||||
[],
|
||||
[],
|
||||
);
|
||||
|
||||
$this->assertSame(['app/Alpha.php', 'app/Zeta.php'], $result['apply']);
|
||||
$this->assertSame(1, $result['added_count']);
|
||||
$this->assertSame(1, $result['changed_count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 단일 파일 target 도 3-way 판정을 받습니다 (변경 시 changed).
|
||||
*/
|
||||
public function test_single_file_target_is_classified(): void
|
||||
{
|
||||
File::put($this->basePath.DIRECTORY_SEPARATOR.'artisan', 'v1');
|
||||
File::put($this->theirsPath.DIRECTORY_SEPARATOR.'artisan', 'v2-changed');
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
['artisan'],
|
||||
[],
|
||||
[],
|
||||
);
|
||||
|
||||
$this->assertContains('artisan', $result['apply']);
|
||||
$this->assertSame(1, $result['changed_count']);
|
||||
}
|
||||
|
||||
/**
|
||||
* theirs 의 symlink 는 적용 목록에서 제외되고 has_symlink 플래그가 켜집니다.
|
||||
* (링크 자체는 copyDirectory 의 별도 링크 처리 경로가 담당 — 목록 산출 대상 아님)
|
||||
*/
|
||||
public function test_symlink_is_excluded_and_flagged(): void
|
||||
{
|
||||
// theirs/app/real.php + theirs/app/link.php(→ real.php) 구성
|
||||
File::ensureDirectoryExists($this->theirsPath.DIRECTORY_SEPARATOR.'app');
|
||||
$realTarget = $this->theirsPath.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'real.php';
|
||||
File::put($realTarget, '<?php // real');
|
||||
|
||||
$linkPath = $this->theirsPath.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'link.php';
|
||||
if (! @symlink($realTarget, $linkPath) || ! is_link($linkPath)) {
|
||||
// Windows SeCreateSymbolicLink 권한 부족 등 — 링크 생성 불가 환경은 skip
|
||||
$this->markTestSkipped('symlink 생성 불가 환경 (권한 부족)');
|
||||
}
|
||||
|
||||
$result = CoreBackupHelper::computeApplyList(
|
||||
$this->basePath,
|
||||
$this->theirsPath,
|
||||
['app'],
|
||||
[],
|
||||
[],
|
||||
);
|
||||
|
||||
// real.php 는 added 로 포함되지만 link.php 는 목록에서 제외
|
||||
$this->assertContains('app/real.php', $result['apply']);
|
||||
$this->assertNotContains('app/link.php', $result['apply']);
|
||||
$this->assertTrue($result['has_symlink'], 'symlink 발견 시 has_symlink 플래그가 켜져야 한다');
|
||||
}
|
||||
|
||||
/**
|
||||
* base·theirs 양쪽에 동일 파일을 씁니다.
|
||||
*/
|
||||
private function writeBoth(string $relative, string $baseContent, string $theirsContent): void
|
||||
{
|
||||
$rel = str_replace('/', DIRECTORY_SEPARATOR, $relative);
|
||||
|
||||
$baseFile = $this->basePath.DIRECTORY_SEPARATOR.$rel;
|
||||
File::ensureDirectoryExists(dirname($baseFile));
|
||||
File::put($baseFile, $baseContent);
|
||||
|
||||
$theirsFile = $this->theirsPath.DIRECTORY_SEPARATOR.$rel;
|
||||
File::ensureDirectoryExists(dirname($theirsFile));
|
||||
File::put($theirsFile, $theirsContent);
|
||||
}
|
||||
}
|
||||
@@ -1,268 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Extension;
|
||||
|
||||
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
||||
use App\Contracts\Repositories\PluginRepositoryInterface;
|
||||
use App\Extension\ExtensionManager;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 확장 소스 classmap(B2) 생성 무결성 테스트.
|
||||
*
|
||||
* 서빙 API 부팅 비용 최적화: 확장 소스 클래스를 classmap 에 편입하여 findFile 의
|
||||
* 파일시스템 스캔(PSR-4 폴백 stat)을 제거한다. 안전 게이트:
|
||||
* - FQCN 추출 정확성 (namespace + class/interface/trait/enum)
|
||||
* - 소스 클래스만 대상 (서드파티 vendor 미포함 — 격리 불변조건 보존)
|
||||
* - 매핑 경로 유효성
|
||||
*
|
||||
* @see ExtensionManager::buildSourceClassmap()
|
||||
*/
|
||||
class ExtensionSourceClassmapTest extends TestCase
|
||||
{
|
||||
private string $fixtureDir;
|
||||
|
||||
private ExposedExtensionManager $manager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->manager = new ExposedExtensionManager(
|
||||
app(ModuleRepositoryInterface::class),
|
||||
app(PluginRepositoryInterface::class),
|
||||
);
|
||||
|
||||
// base_path 하위 임시 픽스처 (buildSourceClassmap 이 base_path 상대경로를 산출하므로)
|
||||
$this->fixtureDir = base_path('storage/framework/testing/classmap_fx_'.uniqid());
|
||||
File::ensureDirectoryExists($this->fixtureDir.'/src');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if (File::isDirectory($this->fixtureDir)) {
|
||||
File::deleteDirectory($this->fixtureDir);
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
private function relative(string $absolute): string
|
||||
{
|
||||
return str_replace('\\', '/', substr($absolute, strlen(base_path()) + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects extracts_fqcn_for_class_declaration, extracts_fqcn_for_interface_declaration, extracts_fqcn_for_trait_declaration, extracts_fqcn_for_enum_declaration
|
||||
*/
|
||||
public function test_extracts_fqcn_for_class_interface_trait_enum(): void
|
||||
{
|
||||
$cases = [
|
||||
'FooClass.php' => "<?php\nnamespace Vendor\\Ext\\Sub;\nclass FooClass {}\n",
|
||||
'BarInterface.php' => "<?php\nnamespace Vendor\\Ext;\ninterface BarInterface {}\n",
|
||||
'BazTrait.php' => "<?php\nnamespace Vendor\\Ext;\ntrait BazTrait {}\n",
|
||||
'QuxEnum.php' => "<?php\nnamespace Vendor\\Ext;\nenum QuxEnum: string { case A = 'a'; }\n",
|
||||
];
|
||||
|
||||
foreach ($cases as $file => $code) {
|
||||
File::put($this->fixtureDir.'/src/'.$file, $code);
|
||||
}
|
||||
|
||||
$psr4 = ['Vendor\\Ext\\' => $this->relative($this->fixtureDir.'/src')];
|
||||
$classmap = $this->manager->exposedBuildSourceClassmap($psr4);
|
||||
|
||||
$this->assertArrayHasKey('Vendor\\Ext\\Sub\\FooClass', $classmap);
|
||||
$this->assertArrayHasKey('Vendor\\Ext\\BarInterface', $classmap);
|
||||
$this->assertArrayHasKey('Vendor\\Ext\\BazTrait', $classmap);
|
||||
$this->assertArrayHasKey('Vendor\\Ext\\QuxEnum', $classmap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects maps_fqcn_to_correct_relative_path
|
||||
*/
|
||||
public function test_maps_fqcn_to_correct_relative_path(): void
|
||||
{
|
||||
File::ensureDirectoryExists($this->fixtureDir.'/src/Services');
|
||||
File::put($this->fixtureDir.'/src/Services/OrderService.php',
|
||||
"<?php\nnamespace Vendor\\Ext\\Services;\nclass OrderService {}\n");
|
||||
|
||||
$psr4 = ['Vendor\\Ext\\' => $this->relative($this->fixtureDir.'/src')];
|
||||
$classmap = $this->manager->exposedBuildSourceClassmap($psr4);
|
||||
|
||||
$this->assertArrayHasKey('Vendor\\Ext\\Services\\OrderService', $classmap);
|
||||
$expected = $this->relative($this->fixtureDir.'/src/Services/OrderService.php');
|
||||
$this->assertSame($expected, $classmap['Vendor\\Ext\\Services\\OrderService']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects ignores_files_outside_declared_namespace
|
||||
*/
|
||||
public function test_ignores_files_outside_declared_namespace(): void
|
||||
{
|
||||
// PSR-4 네임스페이스와 다른 네임스페이스의 파일은 제외 (다른 PSR-4 항목이 담당)
|
||||
File::put($this->fixtureDir.'/src/Foreign.php',
|
||||
"<?php\nnamespace Other\\Package;\nclass Foreign {}\n");
|
||||
|
||||
$psr4 = ['Vendor\\Ext\\' => $this->relative($this->fixtureDir.'/src')];
|
||||
$classmap = $this->manager->exposedBuildSourceClassmap($psr4);
|
||||
|
||||
$this->assertArrayNotHasKey('Other\\Package\\Foreign', $classmap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects skips_files_without_top_level_declaration
|
||||
*/
|
||||
public function test_skips_files_without_top_level_declaration(): void
|
||||
{
|
||||
File::put($this->fixtureDir.'/src/helpers.php',
|
||||
"<?php\nfunction ext_helper() { return 1; }\n");
|
||||
|
||||
$psr4 = ['Vendor\\Ext\\' => $this->relative($this->fixtureDir.'/src')];
|
||||
$classmap = $this->manager->exposedBuildSourceClassmap($psr4);
|
||||
|
||||
$this->assertEmpty($classmap);
|
||||
}
|
||||
|
||||
/**
|
||||
* @effects missing_directory_returns_empty
|
||||
*/
|
||||
public function test_missing_directory_returns_empty(): void
|
||||
{
|
||||
$psr4 = ['Vendor\\Ext\\' => 'nonexistent/path/xyz'];
|
||||
$classmap = $this->manager->exposedBuildSourceClassmap($psr4);
|
||||
|
||||
$this->assertSame([], $classmap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 실제 생성된 autoload-extensions.php 의 src_classmap 이 소스 클래스만 담고
|
||||
* 서드파티 vendor 경로를 포함하지 않는지 검증 (vendor 격리 불변조건).
|
||||
*
|
||||
* 로컬에 파일이 없으면(테스트 환경 미생성) 스킵.
|
||||
*
|
||||
* @effects generated_src_classmap_excludes_vendor_paths, generated_src_classmap_only_extension_namespaces
|
||||
*/
|
||||
public function test_generated_src_classmap_excludes_vendor_paths(): void
|
||||
{
|
||||
$autoloadFile = base_path('bootstrap/cache/autoload-extensions.php');
|
||||
if (! file_exists($autoloadFile)) {
|
||||
$this->markTestSkipped('autoload-extensions.php 미생성 (extension:update-autoload 필요)');
|
||||
}
|
||||
|
||||
$data = require $autoloadFile;
|
||||
if (empty($data['src_classmap'])) {
|
||||
$this->markTestSkipped('src_classmap 비어있음 (활성 확장 없음)');
|
||||
}
|
||||
|
||||
foreach ($data['src_classmap'] as $fqcn => $path) {
|
||||
// 서드파티 vendor 디렉토리를 가리키면 안 됨 (확장별 독립 vendor 는 자체 autoload 담당)
|
||||
$this->assertStringNotContainsString('/vendor/', $path,
|
||||
"src_classmap 이 vendor 경로를 포함하면 안 됩니다: {$fqcn} => {$path}");
|
||||
// 확장 소스 네임스페이스여야 함
|
||||
$this->assertTrue(
|
||||
str_starts_with($fqcn, 'Modules\\') || str_starts_with($fqcn, 'Plugins\\'),
|
||||
"src_classmap 은 확장 소스 네임스페이스만 포함해야 합니다: {$fqcn}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* addClassMap 등록 시 findFile 이 classMap 에서 즉시 해석(파일시스템 스캔 없이)하고,
|
||||
* classmap 미등록 클래스는 PSR-4 폴백으로 해석되는지 검증한다.
|
||||
*
|
||||
* findFile 이 classMap 을 최우선 조회하므로(vendor/composer/ClassLoader.php),
|
||||
* 등록된 확장 클래스는 파일시스템 접근 없이 경로를 반환한다. 미등록 클래스는
|
||||
* addPsr4 폴백으로 안전하게 해석된다(안전망).
|
||||
*
|
||||
* @effects classmap_present_findFile_hits_without_filesystem_stat, classmap_absent_findFile_falls_back_to_psr4, class_loading_remains_lazy_include_on_use
|
||||
*/
|
||||
public function test_add_class_map_find_file_hit_and_psr4_fallback(): void
|
||||
{
|
||||
// 두 클래스 준비: 하나는 classmap 등록, 하나는 미등록(PSR-4 폴백 대상)
|
||||
File::ensureDirectoryExists($this->fixtureDir.'/src');
|
||||
File::put($this->fixtureDir.'/src/Mapped.php',
|
||||
"<?php\nnamespace Vendor\\CmTest;\nclass Mapped {}\n");
|
||||
File::put($this->fixtureDir.'/src/Unmapped.php',
|
||||
"<?php\nnamespace Vendor\\CmTest;\nclass Unmapped {}\n");
|
||||
|
||||
$loader = require base_path('vendor/autoload.php');
|
||||
|
||||
// PSR-4 등록 (폴백 경로)
|
||||
$loader->addPsr4('Vendor\\CmTest\\', $this->fixtureDir.'/src');
|
||||
|
||||
// classmap 에는 Mapped 만 등록
|
||||
$mappedPath = $this->fixtureDir.'/src/Mapped.php';
|
||||
$loader->addClassMap(['Vendor\\CmTest\\Mapped' => $mappedPath]);
|
||||
|
||||
// classmap hit: 등록 경로 그대로 반환 (파일시스템 스캔 없이)
|
||||
$this->assertSame($mappedPath, $loader->findFile('Vendor\\CmTest\\Mapped'));
|
||||
|
||||
// classmap miss: PSR-4 폴백으로 해석 (경로가 정상 반환)
|
||||
$fallback = $loader->findFile('Vendor\\CmTest\\Unmapped');
|
||||
$this->assertNotFalse($fallback);
|
||||
$this->assertStringEndsWith('Unmapped.php', str_replace('\\', '/', $fallback));
|
||||
|
||||
// 지연 로드: findFile 은 경로만 반환하며 클래스를 include 하지 않는다
|
||||
$this->assertFalse(class_exists('Vendor\\CmTest\\Mapped', false),
|
||||
'findFile 은 경로만 반환하고 include 하지 않아야 합니다 (lazy)');
|
||||
|
||||
// 정리: 이 프로세스 loader 에 남은 테스트 PSR-4/classmap 은 테스트 클래스라 무해
|
||||
}
|
||||
|
||||
/**
|
||||
* 재생성 시 addClassMap 이 동일 FQCN 의 경로를 새 값으로 덮어쓰는지 검증한다.
|
||||
*
|
||||
* 확장 업데이트로 클래스 파일 위치가 바뀌면(같은 FQCN, 새 경로) updateComposerAutoload 이
|
||||
* 재생성 후 런타임 addClassMap 을 호출한다. array_merge 로 새 경로가 옛 경로를 이긴다
|
||||
* (stale 경로 shadow 방지).
|
||||
*
|
||||
* @effects install_regenerates_src_classmap_via_updateComposerAutoload
|
||||
*/
|
||||
public function test_reregistration_overwrites_stale_path_for_same_fqcn(): void
|
||||
{
|
||||
$loader = require base_path('vendor/autoload.php');
|
||||
|
||||
$oldPath = base_path('storage/framework/testing/old_'.uniqid().'.php');
|
||||
$newPath = base_path('storage/framework/testing/new_'.uniqid().'.php');
|
||||
|
||||
// 옛 경로 등록 (요청 부팅 시점 상태 시뮬)
|
||||
$loader->addClassMap(['Vendor\\Regen\\Moved' => $oldPath]);
|
||||
$this->assertSame($oldPath, $loader->findFile('Vendor\\Regen\\Moved'));
|
||||
|
||||
// 재생성 후 새 경로 등록 (updateComposerAutoload → addClassMap 시뮬)
|
||||
$loader->addClassMap(['Vendor\\Regen\\Moved' => $newPath]);
|
||||
|
||||
// 새 경로가 옛 경로를 덮어써야 함 (stale shadow 방지)
|
||||
$this->assertSame($newPath, $loader->findFile('Vendor\\Regen\\Moved'),
|
||||
'재등록 시 동일 FQCN 은 새 경로로 덮어써져야 합니다');
|
||||
}
|
||||
|
||||
/**
|
||||
* src_classmap 키가 없는 구버전 autoload-extensions.php 도 안전하게 동작하는지 검증한다.
|
||||
*
|
||||
* B2 이전 버전에서 업데이트한 사이트는 재생성 전까지 src_classmap 키가 없는 파일을 갖는다.
|
||||
* 진입점 소비자는 `! empty(...)` 가드로 키 부재를 안전하게 건너뛰어야 한다(하위호환).
|
||||
*
|
||||
* @effects classmap_absent_findFile_falls_back_to_psr4
|
||||
*/
|
||||
public function test_missing_src_classmap_key_is_backward_compatible(): void
|
||||
{
|
||||
// 구버전 포맷 (src_classmap 키 없음)
|
||||
$legacy = ['psr4' => [], 'classmap' => [], 'files' => [], 'vendor_autoloads' => []];
|
||||
|
||||
// 소비자 가드 패턴 재현: 키 부재 시 addClassMap 미호출 (예외 없음)
|
||||
$this->assertTrue(empty($legacy['src_classmap']),
|
||||
'구버전 파일은 src_classmap 키가 없어야 하고, 소비자는 이를 안전하게 스킵해야 합니다');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* protected buildSourceClassmap 를 테스트에서 호출하기 위한 서브클래스.
|
||||
*/
|
||||
class ExposedExtensionManager extends ExtensionManager
|
||||
{
|
||||
public function exposedBuildSourceClassmap(array $psr4): array
|
||||
{
|
||||
return $this->buildSourceClassmap($psr4);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ use Tests\TestCase;
|
||||
/**
|
||||
* `FilePermissionHelper::copyDirectory` / `removeOrphanItems` 의 symlink 보존 동작 회귀 가드.
|
||||
*
|
||||
* 회귀 시나리오 (gnuboard/g7#28):
|
||||
* 회귀 시나리오 (이슈 #28 + 본 계획 §1):
|
||||
* - 코어 자동 롤백 시 `public/storage` symlink 가 target 디렉토리 내용으로 추적 복사되어
|
||||
* symlink 가 일반 디렉토리로 변질 → 운영자가 `storage:link` 재실행 필요
|
||||
* - `removeOrphanItems` 가 source 부재 symlink 를 디렉토리로 인식하여 target 의 모든 파일을
|
||||
@@ -134,78 +134,4 @@ class FilePermissionHelperSymlinkTest extends TestCase
|
||||
$this->assertSame('hi', File::get($dest.'/file.txt'));
|
||||
$this->assertSame('world', File::get($dest.'/sub/nested.txt'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows JUNCTION (`mklink /J`) 는 PHP 의 `SplFileInfo::isLink()` / `isDir()` 이
|
||||
* 모두 false 를 반환하는 reparse point 다. `php artisan storage:link` 가 Windows 에서
|
||||
* 생성하는 `public/storage` 가 이 형태이며, 이를 파일로 오판하면 `copyFile` 이
|
||||
* 디렉토리를 `copy()` 에 넘겨 `copy(): The first argument ... cannot be a directory` 로
|
||||
* 코어 업데이트가 실패한다 (회귀 가드).
|
||||
*
|
||||
* junction 은 Windows 전용이므로 비-Windows 환경에서는 skip.
|
||||
*/
|
||||
#[Test]
|
||||
public function copyDirectory_는_windows_junction_을_파일로_오판하지_않고_보존합니다(): void
|
||||
{
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
$this->markTestSkipped('junction 은 Windows 전용 (mklink /J)');
|
||||
}
|
||||
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
$linkTarget = $this->tempRoot.'/link_target';
|
||||
|
||||
File::ensureDirectoryExists($source);
|
||||
File::ensureDirectoryExists($linkTarget);
|
||||
File::put($linkTarget.'/inside.txt', 'junction 대상 안 파일');
|
||||
|
||||
$junctionPath = $source.'/storage';
|
||||
// mklink /J 는 관리자 권한 없이 생성 가능 (심볼릭 링크와 달리 SeCreateSymbolicLink 불필요)
|
||||
exec('cmd /c mklink /J '.escapeshellarg($junctionPath).' '.escapeshellarg($linkTarget).' 2>&1', $out, $code);
|
||||
if ($code !== 0 || ! is_dir($junctionPath)) {
|
||||
$this->markTestSkipped('junction 생성 실패: '.implode("\n", $out));
|
||||
}
|
||||
|
||||
// 사전 조건: PHP 가 junction 을 link/dir 어느 쪽으로도 인식하지 못함을 확인
|
||||
$this->assertFalse(is_link($junctionPath), 'junction 은 is_link() 가 false (전제)');
|
||||
|
||||
// copyFile 이 디렉토리를 받아 던지던 예외 없이 완료되어야 한다
|
||||
FilePermissionHelper::copyDirectory($source, $dest);
|
||||
|
||||
// junction 은 dest 에도 junction 으로 보존되어 target 내용에 접근 가능해야 한다
|
||||
$this->assertTrue(is_dir($dest.'/storage'), 'dest 의 storage 는 디렉토리(junction)로 접근 가능해야 한다');
|
||||
$this->assertFileExists($dest.'/storage/inside.txt', 'junction 통과 시 target 파일 접근 가능');
|
||||
}
|
||||
|
||||
/**
|
||||
* removeOrphanItems 가 source 부재 junction 을 재귀 삭제(target 내용 삭제)하지 않고
|
||||
* 링크 자체만 제거하는지 검증 (junction 은 isDir() 이 false 라 별도 rmdir 경로 필요).
|
||||
*/
|
||||
#[Test]
|
||||
public function removeOrphanItems_는_source_부재_junction_을_target_추적_없이_링크만_제거합니다(): void
|
||||
{
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
$this->markTestSkipped('junction 은 Windows 전용 (mklink /J)');
|
||||
}
|
||||
|
||||
$source = $this->tempRoot.'/src';
|
||||
$dest = $this->tempRoot.'/dst';
|
||||
$linkTarget = $this->tempRoot.'/link_target';
|
||||
|
||||
File::ensureDirectoryExists($source);
|
||||
File::ensureDirectoryExists($dest);
|
||||
File::ensureDirectoryExists($linkTarget);
|
||||
File::put($linkTarget.'/precious.txt', '중요한 파일');
|
||||
|
||||
// dest 에만 존재하는 junction (source 에는 없음)
|
||||
exec('cmd /c mklink /J '.escapeshellarg($dest.'/orphan_link').' '.escapeshellarg($linkTarget).' 2>&1', $out, $code);
|
||||
if ($code !== 0 || ! is_dir($dest.'/orphan_link')) {
|
||||
$this->markTestSkipped('junction 생성 실패: '.implode("\n", $out));
|
||||
}
|
||||
|
||||
FilePermissionHelper::copyDirectory($source, $dest, null, [], '', true);
|
||||
|
||||
$this->assertDirectoryDoesNotExist($dest.'/orphan_link', 'orphan junction 은 제거되어야 한다');
|
||||
$this->assertFileExists($linkTarget.'/precious.txt', 'junction target 의 파일은 보존되어야 한다 (재귀 삭제 사고 차단)');
|
||||
}
|
||||
}
|
||||
@@ -1,414 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Extension;
|
||||
|
||||
use App\Contracts\Extension\HookListenerInterface;
|
||||
use App\Extension\HookCacheManager;
|
||||
use App\Extension\HookListenerRegistrar;
|
||||
use App\Extension\HookManager;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\PluginManager;
|
||||
use App\Jobs\DispatchHookListenerJob;
|
||||
use App\Listeners\NotificationHookListener;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* 정적 훅 매핑 캐시 무결성 테스트.
|
||||
*
|
||||
* 성능 개선(서빙 API 부팅 비용)의 안전 게이트: 캐시 경로 등록이 스캔 경로 등록과
|
||||
* 바이트 동일해야 하며(훅 발화 누락 0), 캐시 미스는 안전 폴백해야 한다.
|
||||
*
|
||||
* @see HookCacheManager
|
||||
* @see HookListenerRegistrar::registerFromCache()
|
||||
*/
|
||||
class HookCacheManagerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private string $tmpCachePath;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
HookManager::resetAll();
|
||||
HookListenerRegistrar::clear();
|
||||
|
||||
// request-scoped static memo 를 테스트 간 리셋 (누출 방지).
|
||||
// 한 프로세스에서 여러 테스트가 도는 PHPUnit 특성상 read() 가 채운 static
|
||||
// memo 가 다음 테스트로 누출되면 격리가 깨진다 — clear() 가 memo 를 null 로 되돌린다.
|
||||
(new HookCacheManager)->clear();
|
||||
|
||||
// 실제 bootstrap/cache/hooks.php 를 건드리지 않도록 임시 경로 사용
|
||||
$this->tmpCachePath = storage_path('framework/testing/hooks_test_'.uniqid().'.php');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if (File::exists($this->tmpCachePath)) {
|
||||
File::delete($this->tmpCachePath);
|
||||
}
|
||||
HookManager::resetAll();
|
||||
HookListenerRegistrar::clear();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* getHooks/getFilters 를 [name => [priority => callbackCount]] 지문으로 변환합니다.
|
||||
*
|
||||
* 클로저는 직접 비교할 수 없으므로 구조(훅명·우선순위·콜백 수)만 비교한다.
|
||||
*
|
||||
* @return array{actions: array, filters: array}
|
||||
*/
|
||||
private function fingerprint(): array
|
||||
{
|
||||
$reduce = function (array $registry): array {
|
||||
$out = [];
|
||||
foreach ($registry as $name => $byPriority) {
|
||||
foreach ($byPriority as $priority => $callbacks) {
|
||||
$out[$name][$priority] = count($callbacks);
|
||||
}
|
||||
}
|
||||
ksort($out);
|
||||
|
||||
return $out;
|
||||
};
|
||||
|
||||
return [
|
||||
'actions' => $reduce(HookManager::getHooks()),
|
||||
'filters' => $reduce(HookManager::getFilters()),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 캐시 경로 등록 결과가 스캔(register) 경로와 바이트 동일한지 검증합니다.
|
||||
*
|
||||
* 스텁 리스너 3종(action/filter/sync)을 register() 로 등록한 지문과,
|
||||
* 동일 리스너의 getSubscribedHooks() 를 캐시로 저장 후 registerFromCache() 로
|
||||
* 등록한 지문이 완전히 일치해야 한다 (훅 발화 누락 0 게이트).
|
||||
*
|
||||
* @scenario cache_state=present_valid, listener_type=filter, regeneration_trigger=extension_update, registration_source=core
|
||||
*
|
||||
* @effects cache_path_registration_byte_identical_to_scan_path, cache_registered_filter_executes_synchronously_and_returns_value
|
||||
*/
|
||||
public function test_cache_path_registration_is_identical_to_scan_path(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$listeners = [
|
||||
HookCacheStubAction::class,
|
||||
HookCacheStubFilter::class,
|
||||
HookCacheStubSync::class,
|
||||
];
|
||||
|
||||
// --- 스캔 경로 (register → getSubscribedHooks 호출) ---
|
||||
HookManager::resetAll();
|
||||
HookListenerRegistrar::clear();
|
||||
foreach ($listeners as $listener) {
|
||||
HookListenerRegistrar::register($listener, 'stub-source');
|
||||
}
|
||||
$scanFingerprint = $this->fingerprint();
|
||||
|
||||
// --- 캐시 경로 (사전 계산된 getSubscribedHooks 를 registerFromCache) ---
|
||||
HookManager::resetAll();
|
||||
HookListenerRegistrar::clear();
|
||||
foreach ($listeners as $listener) {
|
||||
$hooks = $listener::getSubscribedHooks();
|
||||
HookListenerRegistrar::registerFromCache($listener, $hooks, 'stub-source');
|
||||
}
|
||||
$cacheFingerprint = $this->fingerprint();
|
||||
|
||||
$this->assertSame(
|
||||
$scanFingerprint,
|
||||
$cacheFingerprint,
|
||||
'캐시 경로 등록은 스캔 경로와 훅 매핑이 바이트 동일해야 합니다 (발화 누락 0)'
|
||||
);
|
||||
|
||||
// 지문이 비어있지 않은지(실제로 등록됐는지) 확인
|
||||
$this->assertNotEmpty($scanFingerprint['actions']);
|
||||
$this->assertNotEmpty($scanFingerprint['filters']);
|
||||
}
|
||||
|
||||
/**
|
||||
* registerFromCache 로 등록한 action 리스너가 큐 디스패치되는지 검증합니다.
|
||||
*
|
||||
* 캐시 경로도 register 와 동일한 큐 정책(DispatchHookListenerJob)을 따라야 한다.
|
||||
*
|
||||
* @scenario cache_state=present_valid, listener_type=action_queued, regeneration_trigger=hooks_clear_command, registration_source=plugin
|
||||
*
|
||||
* @effects cache_registered_action_dispatches_queue_job, listener_class_not_autoloaded_at_boot_when_registered_from_cache
|
||||
*/
|
||||
public function test_cache_registered_action_dispatches_job(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$hooks = HookCacheStubAction::class::getSubscribedHooks();
|
||||
HookListenerRegistrar::registerFromCache(HookCacheStubAction::class, $hooks, 'stub-source');
|
||||
|
||||
HookManager::doAction('test.hookcache.action', 'payload');
|
||||
|
||||
Queue::assertPushed(DispatchHookListenerJob::class, function ($job) {
|
||||
return $job->listenerClass === HookCacheStubAction::class;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* registerFromCache 로 등록한 filter 리스너가 동기 실행되고 반환값이 전달되는지 검증합니다.
|
||||
*
|
||||
* @scenario cache_state=corrupted_broken_structure, listener_type=filter, regeneration_trigger=hooks_cache_command, registration_source=plugin
|
||||
*
|
||||
* @effects cache_registered_sync_action_executes_immediately
|
||||
*/
|
||||
public function test_cache_registered_filter_executes_synchronously(): void
|
||||
{
|
||||
Queue::fake();
|
||||
|
||||
$hooks = HookCacheStubFilter::class::getSubscribedHooks();
|
||||
HookListenerRegistrar::registerFromCache(HookCacheStubFilter::class, $hooks, 'stub-source');
|
||||
|
||||
$result = HookManager::applyFilters('test.hookcache.filter', 'original');
|
||||
|
||||
$this->assertSame('original_cached', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 캐시 파일 부재 시 read() 가 null 을 반환(스캔 폴백)하는지 검증합니다.
|
||||
*
|
||||
* @scenario cache_state=absent, listener_type=action_queued, regeneration_trigger=extension_update, registration_source=core
|
||||
*
|
||||
* @effects absent_cache_falls_back_to_scan_registration
|
||||
*/
|
||||
public function test_read_returns_null_when_cache_absent(): void
|
||||
{
|
||||
$manager = new HookCacheManagerWithPath($this->tmpCachePath);
|
||||
|
||||
$this->assertFalse($manager->isCached());
|
||||
$this->assertNull($manager->read());
|
||||
}
|
||||
|
||||
/**
|
||||
* 손상된 캐시 파일은 read() 가 null 을 반환(안전 폴백)하는지 검증합니다.
|
||||
*
|
||||
* @scenario cache_state=corrupted_broken_structure, listener_type=action_sync, regeneration_trigger=hooks_clear_command, registration_source=core
|
||||
*
|
||||
* @effects corrupted_cache_returns_null_and_falls_back_to_scan, hooks_clear_is_safe_when_cache_absent
|
||||
*/
|
||||
public function test_read_returns_null_when_cache_corrupted(): void
|
||||
{
|
||||
File::ensureDirectoryExists(dirname($this->tmpCachePath));
|
||||
File::put($this->tmpCachePath, "<?php return ['broken' => true];");
|
||||
|
||||
$manager = new HookCacheManagerWithPath($this->tmpCachePath);
|
||||
|
||||
$this->assertTrue($manager->isCached());
|
||||
$this->assertNull($manager->read(), '구조가 올바르지 않은 캐시는 null 폴백해야 합니다');
|
||||
}
|
||||
|
||||
/**
|
||||
* generate() 가 core/modules/plugins 3-버킷 구조를 생성하고 read() 로 되읽히는지 검증합니다.
|
||||
*
|
||||
* 실제 활성 모듈/플러그인 인스턴스로 생성하여 코어 리스너가 다수 수집됨을 확인한다.
|
||||
*
|
||||
* @scenario cache_state=present_valid, listener_type=action_sync, regeneration_trigger=core_update, registration_source=module
|
||||
*
|
||||
* @effects generate_produces_three_bucket_cache_core_modules_plugins, each_cache_entry_has_listener_hooks_and_dynamic_keys
|
||||
*/
|
||||
public function test_generate_produces_readable_three_bucket_cache(): void
|
||||
{
|
||||
$manager = new HookCacheManagerWithPath($this->tmpCachePath);
|
||||
|
||||
$moduleManager = app(ModuleManager::class);
|
||||
$moduleManager->loadModules();
|
||||
$pluginManager = app(PluginManager::class);
|
||||
$pluginManager->loadPlugins();
|
||||
|
||||
$counts = $manager->generate($moduleManager, $pluginManager);
|
||||
|
||||
$this->assertTrue($manager->isCached());
|
||||
|
||||
$cache = $manager->read();
|
||||
$this->assertIsArray($cache);
|
||||
$this->assertArrayHasKey('core', $cache);
|
||||
$this->assertArrayHasKey('modules', $cache);
|
||||
$this->assertArrayHasKey('plugins', $cache);
|
||||
|
||||
// 코어 리스너는 app/Listeners 에 다수 존재
|
||||
$this->assertGreaterThan(0, $counts['core']);
|
||||
$this->assertGreaterThan(0, count($cache['core']));
|
||||
|
||||
// 각 코어 항목은 listener/hooks/dynamic 키를 가진다
|
||||
foreach ($cache['core'] as $entry) {
|
||||
$this->assertArrayHasKey('listener', $entry);
|
||||
$this->assertArrayHasKey('hooks', $entry);
|
||||
$this->assertArrayHasKey('dynamic', $entry);
|
||||
$this->assertIsBool($entry['dynamic']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 동적 훅 리스너(NotificationHookListener)가 dynamic=true 로 표시되는지 검증합니다.
|
||||
*
|
||||
* 코어 캐시에서 registerDynamicHooks 보유 리스너는 boot 후반부 지연 실행 대상이므로
|
||||
* dynamic 플래그가 정확해야 한다.
|
||||
*
|
||||
* @scenario cache_state=present_valid, listener_type=dynamic, regeneration_trigger=hooks_cache_command, registration_source=core
|
||||
*
|
||||
* @effects dynamic_listener_flagged_in_core_cache, dynamic_flagged_listener_deferred_to_boot_tail_like_scan_path
|
||||
*/
|
||||
public function test_dynamic_listener_is_flagged_in_cache(): void
|
||||
{
|
||||
$manager = new HookCacheManagerWithPath($this->tmpCachePath);
|
||||
|
||||
$moduleManager = app(ModuleManager::class);
|
||||
$moduleManager->loadModules();
|
||||
$pluginManager = app(PluginManager::class);
|
||||
$pluginManager->loadPlugins();
|
||||
|
||||
$manager->generate($moduleManager, $pluginManager);
|
||||
$cache = $manager->read();
|
||||
|
||||
$notificationEntry = collect($cache['core'])
|
||||
->firstWhere('listener', NotificationHookListener::class);
|
||||
|
||||
$this->assertNotNull($notificationEntry, 'NotificationHookListener 가 코어 캐시에 있어야 합니다');
|
||||
$this->assertTrue($notificationEntry['dynamic'], 'registerDynamicHooks 보유 리스너는 dynamic=true');
|
||||
}
|
||||
|
||||
/**
|
||||
* clear() 가 캐시 파일을 삭제하는지 검증합니다.
|
||||
*
|
||||
* @scenario cache_state=present_but_testing_env, listener_type=action_sync, regeneration_trigger=extension_update, registration_source=plugin
|
||||
*
|
||||
* @effects testing_env_always_scans_ignoring_cache_file
|
||||
*/
|
||||
public function test_clear_removes_cache_file(): void
|
||||
{
|
||||
File::ensureDirectoryExists(dirname($this->tmpCachePath));
|
||||
File::put($this->tmpCachePath, "<?php return ['core'=>[],'modules'=>[],'plugins'=>[]];");
|
||||
|
||||
$manager = new HookCacheManagerWithPath($this->tmpCachePath);
|
||||
$this->assertTrue($manager->isCached());
|
||||
|
||||
$this->assertTrue($manager->clear());
|
||||
$this->assertFalse($manager->isCached());
|
||||
}
|
||||
|
||||
/**
|
||||
* read() 는 request-scoped static 메모리 캐시로 파일을 요청당 1회만 로드한다.
|
||||
*
|
||||
* 회귀 대상: read() 가 매 호출 캐시 파일(수십 KB)을 require 하면, 부팅 경로에서
|
||||
* core/module/plugin 등록이 여러 번(관측상 13회) 호출해 OPcache 부재 시 요청당
|
||||
* 십수 ms 를 낭비한다. memo 도입 후 첫 로드 결과를 재사용해 파일 접근을 1회로 고정한다.
|
||||
*
|
||||
* 검증: memo 가 채워진 뒤 캐시 파일을 삭제해도 read() 가 여전히 데이터를 반환하면
|
||||
* (파일을 재접근하지 않는다는 증거), 요청당 1회 로드가 성립한다.
|
||||
*/
|
||||
public function test_read_memoizes_file_load_within_request(): void
|
||||
{
|
||||
File::ensureDirectoryExists(dirname($this->tmpCachePath));
|
||||
File::put(
|
||||
$this->tmpCachePath,
|
||||
"<?php return ['core'=>[['listener'=>'X','hooks'=>[]]],'modules'=>[],'plugins'=>[]];"
|
||||
);
|
||||
|
||||
$manager = new HookCacheManagerWithPath($this->tmpCachePath);
|
||||
$first = $manager->read();
|
||||
$this->assertIsArray($first);
|
||||
$this->assertArrayHasKey('core', $first);
|
||||
|
||||
// 파일을 삭제 — memo 가 없으면 다음 read() 는 null(파일 부재)을 반환한다.
|
||||
File::delete($this->tmpCachePath);
|
||||
|
||||
$second = $manager->read();
|
||||
$this->assertSame(
|
||||
$first,
|
||||
$second,
|
||||
'read() 는 파일을 재접근하지 않고 memo 를 반환해야 합니다 (요청당 1회 로드).'
|
||||
);
|
||||
|
||||
// 다른 인스턴스도 동일 static memo 를 공유한다 (부팅 경로의 여러 호출처 = 여러 인스턴스).
|
||||
$another = (new HookCacheManagerWithPath($this->tmpCachePath))->read();
|
||||
$this->assertSame($first, $another, 'static memo 는 인스턴스 간 공유되어야 합니다.');
|
||||
}
|
||||
|
||||
/**
|
||||
* clear()/generate() 는 memo 를 무효화해 stale 데이터 반환을 막는다.
|
||||
*
|
||||
* 확장 install/update 로 캐시가 재생성되면 이후 read() 는 새 매핑을 반환해야 한다.
|
||||
* memo 가 무효화되지 않으면 옛 매핑이 요청 내내 잔존하는 회귀가 발생한다.
|
||||
*/
|
||||
public function test_clear_invalidates_memo(): void
|
||||
{
|
||||
File::ensureDirectoryExists(dirname($this->tmpCachePath));
|
||||
File::put($this->tmpCachePath, "<?php return ['core'=>[['listener'=>'A','hooks'=>[]]],'modules'=>[],'plugins'=>[]];");
|
||||
|
||||
$manager = new HookCacheManagerWithPath($this->tmpCachePath);
|
||||
$this->assertIsArray($manager->read()); // memo 채움
|
||||
|
||||
// clear() 는 파일 + memo 를 모두 무효화한다.
|
||||
$manager->clear();
|
||||
|
||||
// 파일이 없으므로 read() 는 null (memo 가 무효화되지 않았다면 옛 데이터를 반환했을 것).
|
||||
$this->assertNull($manager->read(), 'clear() 후 read() 는 memo 를 버리고 null 폴백해야 합니다.');
|
||||
}
|
||||
}
|
||||
|
||||
// --- 테스트용 스텁 ---
|
||||
|
||||
class HookCacheStubAction implements HookListenerInterface
|
||||
{
|
||||
public static function getSubscribedHooks(): array
|
||||
{
|
||||
return [
|
||||
'test.hookcache.action' => ['method' => 'handleAction', 'priority' => 10],
|
||||
];
|
||||
}
|
||||
|
||||
public function handle(...$args): void {}
|
||||
|
||||
public function handleAction(string $value): void {}
|
||||
}
|
||||
|
||||
class HookCacheStubFilter implements HookListenerInterface
|
||||
{
|
||||
public static function getSubscribedHooks(): array
|
||||
{
|
||||
return [
|
||||
'test.hookcache.filter' => ['method' => 'handleFilter', 'priority' => 10, 'type' => 'filter'],
|
||||
];
|
||||
}
|
||||
|
||||
public function handle(...$args): void {}
|
||||
|
||||
public function handleFilter(string $value): string
|
||||
{
|
||||
return $value.'_cached';
|
||||
}
|
||||
}
|
||||
|
||||
class HookCacheStubSync implements HookListenerInterface
|
||||
{
|
||||
public static function getSubscribedHooks(): array
|
||||
{
|
||||
return [
|
||||
'test.hookcache.sync' => ['method' => 'handleSync', 'priority' => 5, 'sync' => true],
|
||||
];
|
||||
}
|
||||
|
||||
public function handle(...$args): void {}
|
||||
|
||||
public function handleSync(): void {}
|
||||
}
|
||||
|
||||
/**
|
||||
* 테스트에서 임시 캐시 경로를 주입하기 위한 서브클래스.
|
||||
*/
|
||||
class HookCacheManagerWithPath extends HookCacheManager
|
||||
{
|
||||
public function __construct(string $path)
|
||||
{
|
||||
$this->cacheFilePath = $path;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,9 @@
|
||||
|
||||
namespace Tests\Unit\Extension;
|
||||
|
||||
use App\Contracts\Repositories\IdentityPolicyRepositoryInterface;
|
||||
use App\Extension\ModuleManager;
|
||||
use App\Extension\PluginManager;
|
||||
use App\Extension\TemplateManager;
|
||||
use App\Listeners\NotificationHookListener;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
@@ -28,31 +26,18 @@ class InstallerCompletedGuardTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* 주어진 콜백 실행 중 발생한 information_schema.tables 쿼리만 수집합니다.
|
||||
*
|
||||
* @param callable $callback 계측할 코드
|
||||
* @return array<int, array<string, mixed>> information_schema.tables 쿼리 목록
|
||||
*/
|
||||
private function captureSchemaTableQueries(callable $callback): array
|
||||
{
|
||||
DB::enableQueryLog();
|
||||
$callback();
|
||||
$queries = DB::getQueryLog();
|
||||
DB::disableQueryLog();
|
||||
|
||||
return array_filter(
|
||||
$queries,
|
||||
fn ($q) => str_contains($q['query'], 'information_schema.tables')
|
||||
);
|
||||
}
|
||||
|
||||
public function test_module_trait_skips_has_table_when_installer_completed(): void
|
||||
{
|
||||
config(['app.installer_completed' => true]);
|
||||
|
||||
$schemaQueries = $this->captureSchemaTableQueries(
|
||||
fn () => ModuleManager::getActiveModuleIdentifiers()
|
||||
DB::enableQueryLog();
|
||||
ModuleManager::getActiveModuleIdentifiers();
|
||||
$queries = DB::getQueryLog();
|
||||
DB::disableQueryLog();
|
||||
|
||||
$schemaQueries = array_filter(
|
||||
$queries,
|
||||
fn ($q) => str_contains($q['query'], 'information_schema.tables')
|
||||
);
|
||||
|
||||
$this->assertCount(0, $schemaQueries, 'installer_completed=true 에서는 information_schema.tables 쿼리가 발생하지 않아야 합니다');
|
||||
@@ -62,8 +47,14 @@ class InstallerCompletedGuardTest extends TestCase
|
||||
{
|
||||
config(['app.installer_completed' => true]);
|
||||
|
||||
$schemaQueries = $this->captureSchemaTableQueries(
|
||||
fn () => PluginManager::getActivePluginIdentifiers()
|
||||
DB::enableQueryLog();
|
||||
PluginManager::getActivePluginIdentifiers();
|
||||
$queries = DB::getQueryLog();
|
||||
DB::disableQueryLog();
|
||||
|
||||
$schemaQueries = array_filter(
|
||||
$queries,
|
||||
fn ($q) => str_contains($q['query'], 'information_schema.tables')
|
||||
);
|
||||
|
||||
$this->assertCount(0, $schemaQueries);
|
||||
@@ -73,8 +64,14 @@ class InstallerCompletedGuardTest extends TestCase
|
||||
{
|
||||
config(['app.installer_completed' => true]);
|
||||
|
||||
$schemaQueries = $this->captureSchemaTableQueries(
|
||||
fn () => TemplateManager::getActiveTemplateIdentifiers()
|
||||
DB::enableQueryLog();
|
||||
TemplateManager::getActiveTemplateIdentifiers();
|
||||
$queries = DB::getQueryLog();
|
||||
DB::disableQueryLog();
|
||||
|
||||
$schemaQueries = array_filter(
|
||||
$queries,
|
||||
fn ($q) => str_contains($q['query'], 'information_schema.tables')
|
||||
);
|
||||
|
||||
$this->assertCount(0, $schemaQueries);
|
||||
@@ -84,105 +81,14 @@ class InstallerCompletedGuardTest extends TestCase
|
||||
{
|
||||
config(['app.installer_completed' => false]);
|
||||
|
||||
$schemaQueries = $this->captureSchemaTableQueries(
|
||||
fn () => ModuleManager::getActiveModuleIdentifiers()
|
||||
);
|
||||
DB::enableQueryLog();
|
||||
ModuleManager::getActiveModuleIdentifiers();
|
||||
$queries = DB::getQueryLog();
|
||||
DB::disableQueryLog();
|
||||
|
||||
$this->assertGreaterThan(0, count($schemaQueries), 'installer_completed=false 에서는 기존 hasTable 경로가 실행되어야 합니다');
|
||||
}
|
||||
|
||||
/**
|
||||
* NotificationHookListener::registerDynamicHooks() 의 hasTable 가드 검증.
|
||||
*
|
||||
* 부팅 시점 동적 훅 등록 경로 — 설치 완료 상태에서 매 요청
|
||||
* `information_schema.tables` 조회(notification_definitions)가 사라져야 합니다.
|
||||
*/
|
||||
public function test_notification_listener_skips_has_table_when_installer_completed(): void
|
||||
{
|
||||
config(['app.installer_completed' => true]);
|
||||
|
||||
$listener = app(NotificationHookListener::class);
|
||||
|
||||
$schemaQueries = $this->captureSchemaTableQueries(
|
||||
fn () => $listener->registerDynamicHooks()
|
||||
);
|
||||
|
||||
$this->assertCount(0, $schemaQueries, 'installer_completed=true 에서는 notification_definitions hasTable 조회가 발생하지 않아야 합니다');
|
||||
}
|
||||
|
||||
public function test_notification_listener_falls_back_to_has_table_when_installer_not_completed(): void
|
||||
{
|
||||
config(['app.installer_completed' => false]);
|
||||
|
||||
$listener = app(NotificationHookListener::class);
|
||||
|
||||
$schemaQueries = $this->captureSchemaTableQueries(
|
||||
fn () => $listener->registerDynamicHooks()
|
||||
);
|
||||
|
||||
$this->assertGreaterThan(0, count($schemaQueries), 'installer_completed=false 에서는 기존 hasTable 경로가 실행되어야 합니다');
|
||||
}
|
||||
|
||||
/**
|
||||
* IdentityPolicyRepository::listHookTargets() 의 hasTable 가드 검증.
|
||||
*
|
||||
* 부팅 시점 IDV 동적 hook target 동기화 경로 — 설치 완료 상태에서
|
||||
* `information_schema.tables` 조회(identity_policies)가 사라져야 합니다.
|
||||
*/
|
||||
public function test_identity_policy_list_hook_targets_skips_has_table_when_installer_completed(): void
|
||||
{
|
||||
config(['app.installer_completed' => true]);
|
||||
|
||||
$repository = app(IdentityPolicyRepositoryInterface::class);
|
||||
|
||||
$schemaQueries = $this->captureSchemaTableQueries(
|
||||
fn () => $repository->listHookTargets()
|
||||
);
|
||||
|
||||
$this->assertCount(0, $schemaQueries, 'installer_completed=true 에서는 identity_policies hasTable 조회가 발생하지 않아야 합니다');
|
||||
}
|
||||
|
||||
public function test_identity_policy_list_hook_targets_falls_back_when_installer_not_completed(): void
|
||||
{
|
||||
config(['app.installer_completed' => false]);
|
||||
|
||||
$repository = app(IdentityPolicyRepositoryInterface::class);
|
||||
|
||||
$schemaQueries = $this->captureSchemaTableQueries(
|
||||
fn () => $repository->listHookTargets()
|
||||
);
|
||||
|
||||
$this->assertGreaterThan(0, count($schemaQueries), 'installer_completed=false 에서는 기존 hasTable 경로가 실행되어야 합니다');
|
||||
}
|
||||
|
||||
/**
|
||||
* IdentityPolicyRepository::activeExtensionIdentifiers() 의 hasTable 가드 검증.
|
||||
*
|
||||
* `resolveByScopeTarget()` → `applyActiveExtensionScope()` → `activeExtensionIdentifiers()`
|
||||
* 경로로 modules/plugins 테이블 hasTable 조회가 트리거되며, 설치 완료 상태에서는
|
||||
* 해당 `information_schema.tables` 조회가 사라져야 합니다.
|
||||
*/
|
||||
public function test_active_extension_scope_skips_has_table_when_installer_completed(): void
|
||||
{
|
||||
config(['app.installer_completed' => true]);
|
||||
|
||||
$repository = app(IdentityPolicyRepositoryInterface::class);
|
||||
|
||||
$schemaQueries = $this->captureSchemaTableQueries(
|
||||
fn () => $repository->resolveByScopeTarget('hook', 'core.auth.signup_before_submit')
|
||||
);
|
||||
|
||||
$this->assertCount(0, $schemaQueries, 'installer_completed=true 에서는 modules/plugins hasTable 조회가 발생하지 않아야 합니다');
|
||||
}
|
||||
|
||||
public function test_active_extension_scope_falls_back_when_installer_not_completed(): void
|
||||
{
|
||||
config(['app.installer_completed' => false]);
|
||||
|
||||
$repository = app(IdentityPolicyRepositoryInterface::class);
|
||||
|
||||
$schemaQueries = $this->captureSchemaTableQueries(
|
||||
fn () => $repository->resolveByScopeTarget('hook', 'core.auth.signup_before_submit')
|
||||
$schemaQueries = array_filter(
|
||||
$queries,
|
||||
fn ($q) => str_contains($q['query'], 'information_schema.tables')
|
||||
);
|
||||
|
||||
$this->assertGreaterThan(0, count($schemaQueries), 'installer_completed=false 에서는 기존 hasTable 경로가 실행되어야 합니다');
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use ReflectionMethod;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -28,21 +29,19 @@ class ModuleCleanupStaleEntriesTest extends TestCase
|
||||
|
||||
private ModuleManager $moduleManager;
|
||||
|
||||
/**
|
||||
* 이 테스트는 파일시스템(활성 디렉토리)을 건드리지 않는다.
|
||||
*
|
||||
* 검증 대상은 cleanupStaleModuleEntries / removeModulePermissionsAndMenus 의 DB 권한
|
||||
* 로직이므로, 실제 installModule/uninstallModule(파일 복사·삭제·마이그레이션·오토로드
|
||||
* 포함)을 호출하는 대신 파일 무접촉 protected 메서드(createModulePermissions /
|
||||
* assignPermissionsToRoles / removeModulePermissionsAndMenus)만 Reflection 으로 호출한다.
|
||||
* 이커머스 활성 디렉토리는 setUp 의 loadModules() 로 이미 로드된 것을 재사용하며 절대
|
||||
* 삭제/변형하지 않는다 — 과거 실제 install/uninstall 호출이 dev 이커머스 디렉토리를
|
||||
* 삭제한 사고(feedback_test_must_protect_dev_directories)를 구조적으로 차단한다.
|
||||
*/
|
||||
private bool $ecommerceExistedBefore = false;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$modulesPath = base_path('modules');
|
||||
$activePath = $modulesPath.'/sirsoft-ecommerce';
|
||||
if (File::isDirectory($activePath) && ! File::exists($activePath.'/module.php')) {
|
||||
File::deleteDirectory($activePath);
|
||||
}
|
||||
$this->ecommerceExistedBefore = File::isDirectory($activePath);
|
||||
|
||||
$this->moduleManager = app(ModuleManager::class);
|
||||
$this->moduleManager->loadModules();
|
||||
|
||||
@@ -66,54 +65,38 @@ class ModuleCleanupStaleEntriesTest extends TestCase
|
||||
User::factory()->create(['email' => 'test@test.com']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 이커머스 모듈 권한을 DB 에 시드합니다 (파일시스템 무접촉).
|
||||
*
|
||||
* installModule 전체 대신 권한 생성/역할 할당 Phase 만 Reflection 으로 실행한다.
|
||||
* 이미 로드된 이커머스 모듈 인스턴스를 사용하므로 활성 디렉토리를 건드리지 않는다.
|
||||
*
|
||||
* @return \App\Contracts\Extension\ModuleInterface 이커머스 모듈 인스턴스
|
||||
*/
|
||||
private function seedEcommercePermissions()
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$module = $this->moduleManager->getModule('sirsoft-ecommerce');
|
||||
$this->assertNotNull($module, 'sirsoft-ecommerce 모듈이 로드되어 있어야 합니다.');
|
||||
if (! $this->ecommerceExistedBefore) {
|
||||
$activePath = base_path('modules/sirsoft-ecommerce');
|
||||
if (File::isDirectory($activePath)) {
|
||||
File::deleteDirectory($activePath);
|
||||
}
|
||||
}
|
||||
|
||||
$this->invokeProtected('createModulePermissions', $module);
|
||||
$this->invokeProtected('assignPermissionsToRoles', $module);
|
||||
|
||||
return $module;
|
||||
}
|
||||
|
||||
/**
|
||||
* ModuleManager 의 protected 메서드를 호출합니다 (파일 무접촉 Phase 격리 실행용).
|
||||
*
|
||||
* @param string $method 메서드명
|
||||
* @param mixed ...$args 인자
|
||||
* @return mixed 반환값
|
||||
*/
|
||||
private function invokeProtected(string $method, ...$args)
|
||||
{
|
||||
return (new ReflectionMethod($this->moduleManager, $method))
|
||||
->invoke($this->moduleManager, ...$args);
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_cleanup_stale_module_entries_does_not_delete_live_permissions(): void
|
||||
{
|
||||
$module = $this->seedEcommercePermissions();
|
||||
$this->moduleManager->installModule('sirsoft-ecommerce');
|
||||
|
||||
// 시드 후 ecommerce 모듈 권한 수 측정
|
||||
$module = $this->moduleManager->getModule('sirsoft-ecommerce');
|
||||
$this->assertNotNull($module);
|
||||
|
||||
// 설치 후 ecommerce 모듈 권한 수 측정
|
||||
$countBefore = Permission::where('extension_type', ExtensionOwnerType::Module)
|
||||
->where('extension_identifier', 'sirsoft-ecommerce')
|
||||
->count();
|
||||
$this->assertGreaterThan(
|
||||
10,
|
||||
$countBefore,
|
||||
'ecommerce 모듈은 권한 시드 직후 다수의 권한을 보유해야 합니다 (카테고리 + action 조합).'
|
||||
'ecommerce 모듈은 install 직후 다수의 권한을 보유해야 합니다 (카테고리 + action 조합).'
|
||||
);
|
||||
|
||||
// cleanupStaleModuleEntries 를 직접 실행 — 정의와 저장이 일치하는 상태라면 아무것도 삭제되면 안 됨
|
||||
$this->invokeProtected('cleanupStaleModuleEntries', $module);
|
||||
$method = new ReflectionMethod($this->moduleManager, 'cleanupStaleModuleEntries');
|
||||
$method->invoke($this->moduleManager, $module);
|
||||
|
||||
$countAfter = Permission::where('extension_type', ExtensionOwnerType::Module)
|
||||
->where('extension_identifier', 'sirsoft-ecommerce')
|
||||
@@ -129,7 +112,7 @@ class ModuleCleanupStaleEntriesTest extends TestCase
|
||||
|
||||
public function test_cleanup_stale_module_entries_removes_only_genuinely_stale_permissions(): void
|
||||
{
|
||||
$this->seedEcommercePermissions();
|
||||
$this->moduleManager->installModule('sirsoft-ecommerce');
|
||||
|
||||
// 인위적으로 stale 권한 1건 삽입 (정의에 없는 identifier)
|
||||
Permission::create([
|
||||
@@ -149,7 +132,8 @@ class ModuleCleanupStaleEntriesTest extends TestCase
|
||||
->where('identifier', '!=', 'sirsoft-ecommerce.removed-category.obsolete-action')
|
||||
->count();
|
||||
|
||||
$this->invokeProtected('cleanupStaleModuleEntries', $module);
|
||||
$method = new ReflectionMethod($this->moduleManager, 'cleanupStaleModuleEntries');
|
||||
$method->invoke($this->moduleManager, $module);
|
||||
|
||||
// stale 1건만 삭제되고 나머지는 보존되어야 함
|
||||
$this->assertNull(
|
||||
@@ -177,7 +161,8 @@ class ModuleCleanupStaleEntriesTest extends TestCase
|
||||
*/
|
||||
public function test_cleanup_preserves_dynamic_permissions(): void
|
||||
{
|
||||
$module = $this->seedEcommercePermissions();
|
||||
$this->moduleManager->installModule('sirsoft-ecommerce');
|
||||
$module = $this->moduleManager->getModule('sirsoft-ecommerce');
|
||||
|
||||
// 런타임 동적 권한 모사: 정적 정의에 없는 식별자를 삽입
|
||||
Permission::create([
|
||||
@@ -196,7 +181,8 @@ class ModuleCleanupStaleEntriesTest extends TestCase
|
||||
$wrapper->shouldReceive('getDynamicPermissionIdentifiers')
|
||||
->andReturn(['sirsoft-ecommerce.dynamic-scope.action-alpha']);
|
||||
|
||||
$this->invokeProtected('cleanupStaleModuleEntries', $wrapper);
|
||||
$method = new ReflectionMethod($this->moduleManager, 'cleanupStaleModuleEntries');
|
||||
$method->invoke($this->moduleManager, $wrapper);
|
||||
|
||||
$this->assertNotNull(
|
||||
Permission::where('identifier', 'sirsoft-ecommerce.dynamic-scope.action-alpha')->first(),
|
||||
@@ -207,21 +193,17 @@ class ModuleCleanupStaleEntriesTest extends TestCase
|
||||
/**
|
||||
* uninstall(deleteData=false) 시 권한·메뉴·역할이 보존되어 재설치 경로를 비파괴적으로 만드는지 검증.
|
||||
* 운영 정책: "동적 권한/메뉴는 데이터 삭제 옵션 체크 시에만 삭제".
|
||||
*
|
||||
* deleteData=false 경로는 removeModulePermissionsAndMenus 를 호출하지 않는 것과 동치이므로,
|
||||
* 권한 시드 후 삭제 메서드를 호출하지 않고 권한이 그대로 보존됨을 검증한다(파일 무접촉).
|
||||
*/
|
||||
public function test_uninstall_without_delete_data_preserves_permissions(): void
|
||||
{
|
||||
$this->seedEcommercePermissions();
|
||||
$this->moduleManager->installModule('sirsoft-ecommerce');
|
||||
|
||||
$countBefore = Permission::where('extension_type', ExtensionOwnerType::Module)
|
||||
->where('extension_identifier', 'sirsoft-ecommerce')
|
||||
->count();
|
||||
$this->assertGreaterThan(0, $countBefore);
|
||||
|
||||
// deleteData=false → removeModulePermissionsAndMenus 미호출 (권한 삭제 안 함).
|
||||
// 실제 uninstallModule 은 이 분기에서 권한 삭제 메서드를 건너뛴다.
|
||||
$this->moduleManager->uninstallModule('sirsoft-ecommerce', deleteData: false);
|
||||
|
||||
$countAfter = Permission::where('extension_type', ExtensionOwnerType::Module)
|
||||
->where('extension_identifier', 'sirsoft-ecommerce')
|
||||
@@ -236,20 +218,17 @@ class ModuleCleanupStaleEntriesTest extends TestCase
|
||||
|
||||
/**
|
||||
* uninstall(deleteData=true) 시 권한이 삭제되는지 (기존 동작 유지) 검증.
|
||||
*
|
||||
* deleteData=true 경로는 removeModulePermissionsAndMenus 를 호출하므로, 이 메서드를
|
||||
* 직접 실행해 권한이 전수 삭제됨을 검증한다(파일 무접촉).
|
||||
*/
|
||||
public function test_uninstall_with_delete_data_removes_permissions(): void
|
||||
{
|
||||
$module = $this->seedEcommercePermissions();
|
||||
$this->moduleManager->installModule('sirsoft-ecommerce');
|
||||
|
||||
$this->assertGreaterThan(
|
||||
0,
|
||||
Permission::where('extension_identifier', 'sirsoft-ecommerce')->count(),
|
||||
);
|
||||
|
||||
$this->invokeProtected('removeModulePermissionsAndMenus', $module);
|
||||
$this->moduleManager->uninstallModule('sirsoft-ecommerce', deleteData: true);
|
||||
|
||||
$this->assertSame(
|
||||
0,
|
||||
|
||||
Reference in new issue
Block a user