fix-multiple-test-runs

This commit is contained in:
Johannes Meyer 2024-01-15 11:03:33 +01:00
parent 12cca3ebcf
commit a1fc75f745
4 changed files with 10 additions and 6 deletions

View File

@ -12,14 +12,14 @@ use Icinga\Module\Director\Objects\IcingaObject;
use Icinga\Module\Director\Objects\IcingaZone; use Icinga\Module\Director\Objects\IcingaZone;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
abstract class BaseTestCase extends TestCase abstract class BaseTestCase extends \Icinga\Test\BaseTestCase
{ {
private static $app; private static $app;
/** @var Db */ /** @var Db */
private static $db; private static $db;
public function setUp(): void public function ssetUp(): void
{ {
$this->app(); $this->app();
} }
@ -81,11 +81,14 @@ abstract class BaseTestCase extends TestCase
self::$db = new Db($dbConfig); self::$db = new Db($dbConfig);
$migrations = new Migrations(self::$db); $migrations = new Migrations(self::$db);
$migrations->applyPendingMigrations(); $migrations->applyPendingMigrations();
IcingaZone::create([ $zone = IcingaZone::create([
'object_name' => 'director-global', 'object_name' => 'director-global',
'object_type' => 'external_object', 'object_type' => 'external_object',
'is_global' => 'y' 'is_global' => 'y'
])->store(self::$db); ]);
if (! IcingaZone::exists($zone->getId(), self::$db)) {
$zone->store(self::$db);
}
} }
return self::$db; return self::$db;

View File

View File

@ -435,7 +435,7 @@ class IcingaHostTest extends BaseTestCase
$msg = $e->getMessage(); $msg = $e->getMessage();
$matchMysql = strpos( $matchMysql = strpos(
$msg, $msg,
"Duplicate entry 'a' for key 'api_key'" "Duplicate entry 'a' for key 'icinga_host.api_key'"
) !== false; ) !== false;
$matchPostgres = strpos( $matchPostgres = strpos(
@ -747,7 +747,7 @@ class IcingaHostTest extends BaseTestCase
} }
} }
$kill = array('___TEST___zone'); $kill = ['___TEST___zone', '___TEST___zone2'];
foreach ($kill as $name) { foreach ($kill as $name) {
if (IcingaZone::exists($name, $db)) { if (IcingaZone::exists($name, $db)) {
IcingaZone::load($name, $db)->delete(); IcingaZone::load($name, $db)->delete();

View File

@ -44,6 +44,7 @@ class IcingaServiceTest extends BaseTestCase
public function testAcceptsAssignRules() public function testAcceptsAssignRules()
{ {
$this->expectNotToPerformAssertions();
$service = $this->service(); $service = $this->service();
$service->object_type = 'apply'; $service->object_type = 'apply';
$service->assign_filter = 'host.address="127.*"'; $service->assign_filter = 'host.address="127.*"';