Add unit tests for the fixed IniWriter implementation

refs #11743
This commit is contained in:
Alexander A. Klimov 2016-10-12 13:41:42 +02:00
parent 014e7c136a
commit 58b2e6c00f
1 changed files with 49 additions and 0 deletions

View File

@ -400,4 +400,53 @@ EOD;
file_put_contents($this->tempFile, $config);
return $this->tempFile;
}
public function testWhetherNullValuesGetPersisted()
{
$config = Config::fromArray(array());
$section = $config->getSection('garbage');
$section->foobar = null;
$config->setSection('garbage', $section);
$iniWriter = new IniWriter($config, '/dev/null');
$this->assertEquals(
0,
preg_match('/foobar/', $iniWriter->render()),
'IniWriter persists section keys with null values'
);
}
public function testWhetherEmptyValuesGetPersisted()
{
$config = Config::fromArray(array());
$section = $config->getSection('garbage');
$section->foobar = '';
$config->setSection('garbage', $section);
$iniWriter = new IniWriter($config, '/dev/null');
$this->assertEquals(
1,
preg_match('/foobar/', $iniWriter->render()),
'IniWriter doesn\'t persist section keys with empty values'
);
}
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->assertEquals(
0,
preg_match('/foobar/', $iniWriter->render()),
'IniWriter doesn\'t remove section keys with null values'
);
unlink($filename);
}
}