app->instance(AgentClient::class, new class extends AgentClient { public function send(string $action, array $params = []): array { return ['success' => true]; } }); $job = new RunCpanelRestore( jobId: $jobId, logPath: $logPath, backupPath: '/tmp/backup.tar.gz', username: 'example', restoreFiles: true, restoreDatabases: true, restoreEmails: true, restoreSsl: true, discoveredData: null, ); $job->handle($this->app->make(AgentClient::class)); $status = Cache::get('cpanel_restore_status_'.$jobId); $this->assertSame('completed', $status['status'] ?? null); $lines = file($logPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $this->assertNotEmpty($lines); $lastEntry = json_decode(end($lines), true); $this->assertSame('success', $lastEntry['status'] ?? null); } public function test_it_marks_restore_failed_on_exception(): void { $jobId = 'cpanel-restore-failed'; $logPath = storage_path('framework/testing/cpanel-restore-failed.log'); File::ensureDirectoryExists(dirname($logPath)); File::put($logPath, ''); $this->app->instance(AgentClient::class, new class extends AgentClient { public function send(string $action, array $params = []): array { throw new Exception('boom'); } }); $job = new RunCpanelRestore( jobId: $jobId, logPath: $logPath, backupPath: '/tmp/backup.tar.gz', username: 'example', restoreFiles: true, restoreDatabases: true, restoreEmails: true, restoreSsl: true, discoveredData: null, ); $job->handle($this->app->make(AgentClient::class)); $status = Cache::get('cpanel_restore_status_'.$jobId); $this->assertSame('failed', $status['status'] ?? null); } }