From ee247ab383e85ca9fdf4a00c1feb24ff5ec731f9 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 25 Aug 2017 22:54:00 +0200 Subject: [PATCH] test/php: provide DB mostly everwhere... ...as template repository would otherwise complain. Also, fit new boolean true rendering --- library/Director/Test/BaseTestCase.php | 2 +- .../Director/IcingaConfig/AssignRendererTest.php | 2 +- .../Director/Objects/HostApplyMatchesTest.php | 2 +- .../library/Director/Objects/IcingaCommandTest.php | 3 ++- .../library/Director/Objects/IcingaHostTest.php | 11 +++++++---- .../library/Director/Resolver/TemplateTreeTest.php | 14 ++++++++------ 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/library/Director/Test/BaseTestCase.php b/library/Director/Test/BaseTestCase.php index 07b82ea3..31a6b50f 100644 --- a/library/Director/Test/BaseTestCase.php +++ b/library/Director/Test/BaseTestCase.php @@ -89,7 +89,7 @@ abstract class BaseTestCase extends PHPUnit_Framework_TestCase } $properties['object_name'] = $name; - return IcingaObject::createByType($type, $properties); + return IcingaObject::createByType($type, $properties, $this->getDb()); } protected function app() diff --git a/test/php/library/Director/IcingaConfig/AssignRendererTest.php b/test/php/library/Director/IcingaConfig/AssignRendererTest.php index 372b52d3..38336b74 100644 --- a/test/php/library/Director/IcingaConfig/AssignRendererTest.php +++ b/test/php/library/Director/IcingaConfig/AssignRendererTest.php @@ -34,7 +34,7 @@ class AssignRendererTest extends BaseTestCase . '&host.vars.is_clustered=true)'; $expected = 'assign where match("*internal", host.name) ||' - . ' (service.vars.priority < 2 && host.vars.is_clustered == true)'; + . ' (service.vars.priority < 2 && host.vars.is_clustered)'; $this->assertEquals( $expected, diff --git a/test/php/library/Director/Objects/HostApplyMatchesTest.php b/test/php/library/Director/Objects/HostApplyMatchesTest.php index 3c7f4328..b9f22ca0 100644 --- a/test/php/library/Director/Objects/HostApplyMatchesTest.php +++ b/test/php/library/Director/Objects/HostApplyMatchesTest.php @@ -88,6 +88,6 @@ class HostApplyMatchesTest extends BaseTestCase 'location' => 'Nuremberg', 'tags' => array('Special', 'Amazing'), ) - )); + ), $this->getDb()); } } diff --git a/test/php/library/Director/Objects/IcingaCommandTest.php b/test/php/library/Director/Objects/IcingaCommandTest.php index 8c3dd203..8e564d85 100644 --- a/test/php/library/Director/Objects/IcingaCommandTest.php +++ b/test/php/library/Director/Objects/IcingaCommandTest.php @@ -196,7 +196,8 @@ class IcingaCommandTest extends BaseTestCase array( 'object_name' => $this->testCommandName, 'object_type' => 'object' - ) + ), + $this->getDb() ); } diff --git a/test/php/library/Director/Objects/IcingaHostTest.php b/test/php/library/Director/Objects/IcingaHostTest.php index ce3ff381..ab7900e0 100644 --- a/test/php/library/Director/Objects/IcingaHostTest.php +++ b/test/php/library/Director/Objects/IcingaHostTest.php @@ -30,7 +30,8 @@ class IcingaHostTest extends BaseTestCase { $host = $this->host(); $newHost = IcingaHost::create( - array('display_name' => 'Replaced display') + array('display_name' => 'Replaced display'), + $this->getDb() ); $this->assertEquals( @@ -62,7 +63,8 @@ class IcingaHostTest extends BaseTestCase { $host = $this->host(); $newHost = IcingaHost::create( - array('display_name' => 'Replaced display') + array('display_name' => 'Replaced display'), + $this->getDb() ); $this->assertEquals( @@ -108,7 +110,8 @@ class IcingaHostTest extends BaseTestCase 'test2' => 18, 'initially' => 'set and then preserved', ) - ) + ), + $this->getDb() ); $preserve = array('address', 'vars.test1', 'vars.initially'); @@ -649,7 +652,7 @@ class IcingaHostTest extends BaseTestCase ) ) ) - )); + ), $this->getDb()); } protected function getDefaultHostProperties($prefix = '') diff --git a/test/php/library/Director/Resolver/TemplateTreeTest.php b/test/php/library/Director/Resolver/TemplateTreeTest.php index 27dbf60e..f44d0816 100644 --- a/test/php/library/Director/Resolver/TemplateTreeTest.php +++ b/test/php/library/Director/Resolver/TemplateTreeTest.php @@ -10,6 +10,8 @@ use Icinga\Module\Director\Test\BaseTestCase; class TemplateTreeTest extends BaseTestCase { + protected $applyId; + protected function prepareHosts(Db $db) { $o1 = IcingaHost::create([ @@ -195,6 +197,7 @@ class TemplateTreeTest extends BaseTestCase $o5->store(); $o6->store(); $o7->store(); + $this->applyId = (int) $o7->get('id'); $tree = new TemplateTree('service', $db); $this->assertEquals([ @@ -226,12 +229,11 @@ class TemplateTreeTest extends BaseTestCase protected function removeServices(Db $db) { - $key = [ - 'object_name' => 'o7', - 'object_type' => 'apply', - ]; - if (IcingaService::exists($key, $db)) { - IcingaService::load($key, $db)->delete(); + if ($this->applyId) { + $key = ['id' => $this->applyId]; + if (IcingaService::exists($key, $db)) { + IcingaService::load($key, $db)->delete(); + } } $kill = array('o6', 'o5', 'o4', 'o3', 'o2', 'o1');