config = Server::get(IConfig::class); $this->config->deleteSystemValue(self::KEY); } #[\Override] protected function tearDown(): void { parent::tearDown(); $this->config->deleteSystemValue(self::KEY); } public function testOverwriteSetsTheValue(): void { $this->overwriteSystemConfig(self::KEY, 'overwritten'); $this->assertSame('overwritten', $this->config->getSystemValue(self::KEY)); } public function testRestoreRemovesAPreviouslyUnsetKey(): void { $this->overwriteSystemConfig(self::KEY, 'overwritten'); $this->restoreAllSystemConfig(); $this->assertSame('fallback', $this->config->getSystemValue(self::KEY, 'fallback')); } public function testRestoreReturnsThePreviousValue(): void { $this->config->setSystemValue(self::KEY, 'original'); $this->overwriteSystemConfig(self::KEY, 'overwritten'); $this->restoreAllSystemConfig(); $this->assertSame('original', $this->config->getSystemValue(self::KEY)); } public function testRestoreReturnsThePreviousValueAfterRepeatedOverwrites(): void { $this->config->setSystemValue(self::KEY, 'original'); $this->overwriteSystemConfig(self::KEY, 'first'); $this->overwriteSystemConfig(self::KEY, 'second'); $this->restoreAllSystemConfig(); $this->assertSame('original', $this->config->getSystemValue(self::KEY)); } public function testRestoreIsIdempotent(): void { $this->config->setSystemValue(self::KEY, 'original'); $this->overwriteSystemConfig(self::KEY, 'overwritten'); $this->restoreAllSystemConfig(); $this->config->setSystemValue(self::KEY, 'set afterwards'); $this->restoreAllSystemConfig(); $this->assertSame('set afterwards', $this->config->getSystemValue(self::KEY)); } /** false is falsy but set: an isset-based check would wrongly delete the key. */ public function testRestoreReturnsAPreviousFalseValue(): void { $this->config->setSystemValue(self::KEY, false); $this->overwriteSystemConfig(self::KEY, true); $this->restoreAllSystemConfig(); $this->assertFalse($this->config->getSystemValue(self::KEY, 'fallback')); } }