public function testExplicitRemove() { $filename = tempnam(sys_get_temp_dir(), 'iw2'); $config = Config::fromArray(array('garbage' => array('foobar' => 'lolcat'))); $iniWriter = new IniWriter($config, $filename); $iniWriter->write(); $section = $config->getSection('garbage'); $section->foobar = null; $iniWriter = new IniWriter($config, $filename); $this->assertNotContains('foobar', $iniWriter->render(), 'IniWriter doesn\'t remove section keys with null values'); unlink($filename); }
public function testWhetherLinebreaksAreRemoved() { $target = $this->writeConfigToTemporaryFile(''); $writer = new IniWriter(array('config' => Config::fromArray(array('section' => array('foo' => 'linebreak in line', 'linebreak inkey' => 'blarg'))), 'filename' => $target)); $rendered = $writer->render(); $this->assertEquals(count(explode("\n", $rendered)), 4, 'generated config should not contain more than three line breaks'); }
public function testSectionDeleted() { $config = <<<'EOD' [section 1] guarg = "1" [section 2] foo = "1337" foo2 = "baz" foo3 = "nope" foo4 = "bar" [section 3] guard = "2" EOD; $deleted = <<<'EOD' [section 1] guarg = "1" [section 3] guard = "2" EOD; $target = $this->writeConfigToTemporaryFile($config); $writer = new IniWriter(Config::fromArray(array('section 1' => array('guarg' => 1), 'section 3' => array('guard' => 2))), $target); $this->assertEquals(trim($deleted), trim($writer->render()), 'IniWriter does not delete sections properly'); }