From 11e5ef0362ace09cace1bdffbec365dfd49152e5 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 28 Feb 2016 16:25:15 +0100 Subject: [PATCH] IcingaConfigHelper: empty intervals are null --- library/Director/IcingaConfig/IcingaConfigHelper.php | 4 ++++ .../Director/IcingaConfig/IcingaConfigHelperTest.php | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php index 5f11eb31..de095c39 100644 --- a/library/Director/IcingaConfig/IcingaConfigHelper.php +++ b/library/Director/IcingaConfig/IcingaConfigHelper.php @@ -171,6 +171,10 @@ class IcingaConfigHelper public static function parseInterval($interval) { + if ($interval === null || $interval === '') { + return null; + } + if (ctype_digit($interval)) { return (int) $interval; } diff --git a/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php b/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php index 5055a7e6..7bde0bdb 100644 --- a/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php +++ b/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php @@ -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');