service = app(CoreUpdateService::class); $this->pendingDir = storage_path('app/test-core-vendor-pending-'.uniqid()); File::ensureDirectoryExists($this->pendingDir); } protected function tearDown(): void { if (File::isDirectory($this->pendingDir)) { File::deleteDirectory($this->pendingDir); } parent::tearDown(); } /** * 테스트용 _pending 디렉토리에 vendor-bundle.zip 생성. */ private function createPendingWithBundle(): void { File::put($this->pendingDir.'/composer.json', json_encode([ 'name' => 'test/core', 'require' => ['php' => '^8.2'], ])); $zipPath = $this->pendingDir.'/vendor-bundle.zip'; $zip = new \ZipArchive; $zip->open($zipPath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); $zip->addFromString('vendor/autoload.php', 'addFromString('vendor/laravel/framework/src/file.php', 'close(); File::put($this->pendingDir.'/vendor-bundle.json', json_encode([ 'schema_version' => VendorBundler::SCHEMA_VERSION, 'zip_sha256' => hash_file('sha256', $zipPath), 'package_count' => 1, ])); } public function test_bundled_mode_extracts_vendor_bundle_zip(): void { $this->createPendingWithBundle(); $result = $this->service->runVendorInstallInPending($this->pendingDir, VendorMode::Bundled); $this->assertSame(VendorMode::Bundled, $result->mode); $this->assertSame('bundled', $result->strategy); $this->assertFileExists($this->pendingDir.'/vendor/autoload.php'); } public function test_bundled_mode_fails_when_no_bundle_present(): void { File::put($this->pendingDir.'/composer.json', json_encode(['name' => 'test/core'])); $this->expectException(VendorInstallException::class); $this->service->runVendorInstallInPending($this->pendingDir, VendorMode::Bundled); } public function test_auto_mode_prefers_bundle_when_composer_cannot_execute(): void { $this->createPendingWithBundle(); // canExecuteComposer를 직접 제어할 수 없으므로 bundle 존재를 전제로 // Auto가 composer 가능하면 composer 콜백을 호출하려 시도할 것이고, // composer 콜백은 실패할 것 — 대신 bundled로 해결되는 경로를 Bundled 명시로 시뮬레이션 $result = $this->service->runVendorInstallInPending($this->pendingDir, VendorMode::Bundled); $this->assertSame('bundled', $result->strategy); } }