IcingaConfigHelper: empty intervals are null

This commit is contained in:
Thomas Gelf 2016-02-28 16:25:15 +01:00
parent 7f949e1b5a
commit 11e5ef0362
2 changed files with 12 additions and 0 deletions

View File

@ -171,6 +171,10 @@ class IcingaConfigHelper
public static function parseInterval($interval)
{
if ($interval === null || $interval === '') {
return null;
}
if (ctype_digit($interval)) {
return (int) $interval;
}

View File

@ -9,6 +9,8 @@ class IcingaConfigHelperTest extends BaseTestCase
{
public function testWhetherIntervalStringIsCorrectlyParsed()
{
$this->assertEquals(c::parseInterval('0'), 0);
$this->assertEquals(c::parseInterval('0s'), 0);
$this->assertEquals(c::parseInterval('10'), 10);
$this->assertEquals(c::parseInterval('70s'), 70);
$this->assertEquals(c::parseInterval('5m 10s'), 310);
@ -24,6 +26,12 @@ class IcingaConfigHelperTest extends BaseTestCase
c::parseInterval('1h 5m 60x');
}
public function testWhetherAnEmptyValueGivesNull()
{
$this->assertNull(c::parseInterval(''));
$this->assertNull(c::parseInterval(null));
}
public function testWhetherIntervalStringIsCorrectlyRendered()
{
$this->assertEquals(c::renderInterval(10), '10s');