root = str_replace('\\', '/', sys_get_temp_dir()).'/kant-restore-'.bin2hex(random_bytes(6)); mkdir($this->root.'/var/media', 0o775, true); file_put_contents($this->root.'/VERSION', "1.0.0\n"); $this->db = ConnectionFactory::create('sqlite:///'.$this->root.'/var/cms.db'); TestSchema::build($this->db); } protected function tearDown(): void { $this->db->close(); gc_collect_cycles(); self::remove($this->root); } public function testAMaintenanceStateThatWasAlreadyOnStaysOn(): void { file_put_contents($this->root.'/'.Updater::MAINTENANCE_FILE, "an\n"); $this->command()->execute(['name' => 'sicherung-gibt-es-nicht'], ['interactive' => false]); self::assertFileExists($this->root.'/'.Updater::MAINTENANCE_FILE); } public function testAMaintenanceStateTheCommandSwitchedOnIsSwitchedOffAgain(): void { $this->command()->execute(['name' => 'sicherung-gibt-es-nicht'], ['interactive' => false]); self::assertFileDoesNotExist($this->root.'/'.Updater::MAINTENANCE_FILE); } private function command(): CommandTester { $runner = new CommandRunner(); $url = 'sqlite:///'.$this->root.'/var/cms.db'; return new CommandTester(new RestoreCommand( new Backup($this->root, $url, $this->root.'/var/media', $this->db, $runner), new Updater($this->root, $url, $runner, $this->db), )); } private static function remove(string $path): void { foreach (glob($path.'/{,.}[!.]*', GLOB_BRACE) ?: [] as $entry) { is_dir($entry) ? self::remove($entry) : @unlink($entry); } @rmdir($path); } }