From a1fc75f745740cbdef31edaa029527a1881b0b75 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Mon, 15 Jan 2024 11:03:33 +0100 Subject: [PATCH] fix-multiple-test-runs --- library/Director/Test/BaseTestCase.php | 11 +++++++---- test/config/config.ini | 0 test/php/library/Director/Objects/IcingaHostTest.php | 4 ++-- .../library/Director/Objects/IcingaServiceTest.php | 1 + 4 files changed, 10 insertions(+), 6 deletions(-) delete mode 100644 test/config/config.ini diff --git a/library/Director/Test/BaseTestCase.php b/library/Director/Test/BaseTestCase.php index 07217c1b..f1d6eeb4 100644 --- a/library/Director/Test/BaseTestCase.php +++ b/library/Director/Test/BaseTestCase.php @@ -12,14 +12,14 @@ use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Objects\IcingaZone; use PHPUnit\Framework\TestCase; -abstract class BaseTestCase extends TestCase +abstract class BaseTestCase extends \Icinga\Test\BaseTestCase { private static $app; /** @var Db */ private static $db; - public function setUp(): void + public function ssetUp(): void { $this->app(); } @@ -81,11 +81,14 @@ abstract class BaseTestCase extends TestCase self::$db = new Db($dbConfig); $migrations = new Migrations(self::$db); $migrations->applyPendingMigrations(); - IcingaZone::create([ + $zone = IcingaZone::create([ 'object_name' => 'director-global', 'object_type' => 'external_object', 'is_global' => 'y' - ])->store(self::$db); + ]); + if (! IcingaZone::exists($zone->getId(), self::$db)) { + $zone->store(self::$db); + } } return self::$db; diff --git a/test/config/config.ini b/test/config/config.ini deleted file mode 100644 index e69de29b..00000000 diff --git a/test/php/library/Director/Objects/IcingaHostTest.php b/test/php/library/Director/Objects/IcingaHostTest.php index 0fed9472..e1282844 100644 --- a/test/php/library/Director/Objects/IcingaHostTest.php +++ b/test/php/library/Director/Objects/IcingaHostTest.php @@ -435,7 +435,7 @@ class IcingaHostTest extends BaseTestCase $msg = $e->getMessage(); $matchMysql = strpos( $msg, - "Duplicate entry 'a' for key 'api_key'" + "Duplicate entry 'a' for key 'icinga_host.api_key'" ) !== false; $matchPostgres = strpos( @@ -747,7 +747,7 @@ class IcingaHostTest extends BaseTestCase } } - $kill = array('___TEST___zone'); + $kill = ['___TEST___zone', '___TEST___zone2']; foreach ($kill as $name) { if (IcingaZone::exists($name, $db)) { IcingaZone::load($name, $db)->delete(); diff --git a/test/php/library/Director/Objects/IcingaServiceTest.php b/test/php/library/Director/Objects/IcingaServiceTest.php index 8899361c..761230fb 100644 --- a/test/php/library/Director/Objects/IcingaServiceTest.php +++ b/test/php/library/Director/Objects/IcingaServiceTest.php @@ -44,6 +44,7 @@ class IcingaServiceTest extends BaseTestCase public function testAcceptsAssignRules() { + $this->expectNotToPerformAssertions(); $service = $this->service(); $service->object_type = 'apply'; $service->assign_filter = 'host.address="127.*"';