tmpDir = sys_get_temp_dir() . '/magesail_tss_' . uniqid('', true); mkdir($this->tmpDir, 0777, true); } protected function tearDown(): void { $file = $this->tmpDir . '/magesail_tunnel_store.json'; if (is_file($file)) { @unlink($file); } @rmdir($this->tmpDir); parent::tearDown(); } public function testReadWriteRoundTrip(): void { $dir = new DirectoryList(); $dir->setTestPath(DirectoryList::VAR_DIR, $this->tmpDir); $json = new Json(); $state = new TunnelStoreState($dir, $json); $payload = [ 'store_id' => 5, 'store_code' => 'mgtun_x', 'unsecure_base_url' => 'http://a.test/', 'secure_base_url' => '', 'use_secure_urls' => true, 'nginx_pending_reload' => false, ]; $state->write($payload); $read = $state->read(); self::assertNotNull($read); self::assertSame(5, $read['store_id']); self::assertSame('mgtun_x', $read['store_code']); self::assertSame('http://a.test/', $read['unsecure_base_url']); self::assertTrue($read['use_secure_urls']); } public function testReadReturnsNullWhenFileMissing(): void { $dir = new DirectoryList(); $dir->setTestPath(DirectoryList::VAR_DIR, $this->tmpDir); $json = new Json(); $state = new TunnelStoreState($dir, $json); self::assertNull($state->read()); } public function testDeleteRemovesFile(): void { $dir = new DirectoryList(); $dir->setTestPath(DirectoryList::VAR_DIR, $this->tmpDir); $json = new Json(); $state = new TunnelStoreState($dir, $json); $state->write([ 'store_id' => 1, 'store_code' => 'x', 'unsecure_base_url' => '', 'secure_base_url' => '', 'use_secure_urls' => false, ]); $state->delete(); self::assertNull($state->read()); } }