diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:47 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:47 +0000 |
commit | 5419d4428c86c488a43124f85e5407d7cbae6541 (patch) | |
tree | 772c4221a20fd7d1b3e7e67c6e21755a50e80fd7 /test | |
parent | Adding upstream version 1.10.2. (diff) | |
download | icingaweb2-module-director-upstream.tar.xz icingaweb2-module-director-upstream.zip |
Adding upstream version 1.11.1.upstream/1.11.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
21 files changed, 267 insertions, 202 deletions
diff --git a/test/config/config.ini b/test/config/config.ini deleted file mode 100644 index e69de29..0000000 --- a/test/config/config.ini +++ /dev/null diff --git a/test/php/library/Director/Data/AssignFilterHelperTest.php b/test/php/library/Director/Data/AssignFilterHelperTest.php index 5fcdd95..e7c2f84 100644 --- a/test/php/library/Director/Data/AssignFilterHelperTest.php +++ b/test/php/library/Director/Data/AssignFilterHelperTest.php @@ -11,7 +11,7 @@ class AssignFilterHelperTest extends BaseTestCase { protected static $exampleHost; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$exampleHost = (object) [ 'address' => '127.0.0.1', diff --git a/test/php/library/Director/Data/RecursiveUtf8ValidatorTest.php b/test/php/library/Director/Data/RecursiveUtf8ValidatorTest.php index 1434d4a..9b4bf33 100644 --- a/test/php/library/Director/Data/RecursiveUtf8ValidatorTest.php +++ b/test/php/library/Director/Data/RecursiveUtf8ValidatorTest.php @@ -7,11 +7,10 @@ use Icinga\Module\Director\Test\BaseTestCase; class RecursiveUtf8ValidatorTest extends BaseTestCase { - /** - * @expectedException \InvalidArgumentException - */ public function testDetectInvalidUtf8Character() { + $this->expectException(\InvalidArgumentException::class); + RecursiveUtf8Validator::validateRows([ (object) [ 'name' => 'test 1', diff --git a/test/php/library/Director/Form/IcingaObjectFieldFormTest.php b/test/php/library/Director/Form/IcingaObjectFieldFormTest.php new file mode 100644 index 0000000..8a5e0cc --- /dev/null +++ b/test/php/library/Director/Form/IcingaObjectFieldFormTest.php @@ -0,0 +1,151 @@ +<?php + +namespace Tests\Icinga\Module\Director\Field; + +use Icinga\Module\Director\Forms\IcingaObjectFieldForm; +use Icinga\Module\Director\Objects\DirectorDatafield; +use Icinga\Module\Director\Objects\IcingaHost; +use Icinga\Module\Director\Test\BaseTestCase; +use Icinga\Module\Director\Objects\IcingaCommand; + +class IcingaObjectFieldFormTest extends BaseTestCase +{ + /** @var string */ + protected const COMMAND_NAME = 'icingaTestCommand'; + + /** @var string */ + protected const DATAFIELD_NAME = 'dataFieldTest'; + + /** @var string */ + protected const HOST_NAME = 'testHost'; + + /** @var ?DirectorDatafield */ + protected $testDatafield = null; + + /** @var ?IcingaCommand */ + protected $testIcingaCommand = null; + + /** @var IcingaHost */ + private $testHost; + + public function setUp(): void + { + parent::setUp(); + if ($this->hasDb()) { + $db = $this->getDb(); + $this->testDatafield = DirectorDatafield::create([ + 'varname' => self::DATAFIELD_NAME, + 'caption' => 'Blah', + 'description' => '', + 'datatype' => 'Icinga\Module\Director\DataType\DataTypeArray', + 'format' => 'json' + ]); + $this->testDatafield->store($db); + + $this->testIcingaCommand = IcingaCommand::create( + [ + 'object_name' => self::COMMAND_NAME, + 'object_type' => 'object' + ], + $db + ); + $this->testIcingaCommand->store($db); + + $this->testHost = IcingaHost::create([ + 'object_name' => self::HOST_NAME, + 'object_type' => 'object', + 'display_name' => 'Whatever' + ], $this->getDb()); + } + } + + public function testFieldSuggestionsWithoutCheckCommand() + { + if ($this->skipForMissingDb()) { + return; + } + + $db = $this->getDb(); + + $icingaHostFieldForm = (new IcingaObjectFieldForm()) + ->setDb($db) + ->setIcingaObject($this->testHost); + + $icingaHostFieldForm->setup(); + /** @var array<string> $suggestions */ + $suggestions = $icingaHostFieldForm->getElement('datafield_id') + ->getAttrib('options'); + + array_shift($suggestions); + + $this->assertEquals( + [ + 'Other available fields' => [ + $this->testDatafield->get('id') => "Blah (dataFieldTest)" + ] + ], + $suggestions + ); + } + + public function testFieldSuggestionsWithCheckCommand() + { + if ($this->skipForMissingDb()) { + return; + } + + $db = $this->getDb(); + + $this->testHost->check_command = self::COMMAND_NAME; + $icingaHostFieldForm = (new IcingaObjectFieldForm()) + ->setDb($db) + ->setIcingaObject($this->testHost); + + $icingaHostFieldForm->setup(); + + /** @var array<string> $suggestions */ + $suggestions = $icingaHostFieldForm->getElement('datafield_id') + ->getAttrib('options'); + + array_shift($suggestions); + $this->assertEquals( + [ + 'Other available fields' => [ + $this->testDatafield->get('id') => "Blah (dataFieldTest)" + ] + ], + $suggestions + ); + } + + public function tearDown(): void + { + if ($this->hasDb()) { + $db = $this->getDb(); + $this->deleteDatafields(); + + if (IcingaHost::exists(self::HOST_NAME, $db)) { + IcingaHost::load(self::HOST_NAME, $db)->delete(); + } + + if (IcingaCommand::exists(self::COMMAND_NAME, $db)) { + IcingaCommand::load(self::COMMAND_NAME, $db)->delete(); + } + } + + parent::tearDown(); + } + + protected function deleteDatafields() + { + $db = $this->getDb(); + $dbAdapter = $db->getDbAdapter(); + + $query = $dbAdapter->select() + ->from('director_datafield') + ->where('varname = ?', self::DATAFIELD_NAME); + foreach (DirectorDatafield::loadAll($db, $query, 'id') as $datafield) { + $datafield->delete(); + } + } +} diff --git a/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php b/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php index 506f3b8..10cd644 100644 --- a/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php +++ b/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php @@ -18,11 +18,10 @@ class IcingaConfigHelperTest extends BaseTestCase $this->assertEquals(c::parseInterval('1h 5m 60s'), 3960); } - /** - * @expectedException \InvalidArgumentException - */ public function testWhetherInvalidIntervalStringRaisesException() { + $this->expectException(\InvalidArgumentException::class); + c::parseInterval('1h 5m 60x'); } diff --git a/test/php/library/Director/IcingaConfig/StateFilterTest.php b/test/php/library/Director/IcingaConfig/StateFilterTest.php index 82e94d8..2c997bd 100644 --- a/test/php/library/Director/IcingaConfig/StateFilterTest.php +++ b/test/php/library/Director/IcingaConfig/StateFilterTest.php @@ -2,6 +2,8 @@ namespace Tests\Icinga\Module\Director\IcingaConfig; +use Icinga\Exception\InvalidPropertyException; +use Icinga\Exception\ProgrammingError; use Icinga\Module\Director\IcingaConfig\StateFilterSet; use Icinga\Module\Director\Objects\IcingaUser; use Icinga\Module\Director\Test\BaseTestCase; @@ -23,19 +25,17 @@ class StateFilterSetTest extends BaseTestCase ); } - /** - * @expectedException \Icinga\Exception\InvalidPropertyException - */ public function testFailsForInvalidProperties() { + $this->expectException(InvalidPropertyException::class); + $set = new StateFilterSet('bla'); } - /** - * @expectedException \Icinga\Exception\ProgrammingError - */ public function testCannotBeStoredForAnUnstoredUser() { + $this->expectException(ProgrammingError::class); + StateFilterSet::forIcingaObject( $this->user1(), 'states' @@ -152,7 +152,7 @@ class StateFilterSetTest extends BaseTestCase )); } - public function tearDown() + public function tearDown(): void { if ($this->hasDb()) { $users = array( @@ -167,5 +167,7 @@ class StateFilterSetTest extends BaseTestCase } } } + + parent::tearDown(); } } diff --git a/test/php/library/Director/Import/HostSyncTest.php b/test/php/library/Director/Import/HostSyncTest.php index eeee7a4..a18fc3d 100644 --- a/test/php/library/Director/Import/HostSyncTest.php +++ b/test/php/library/Director/Import/HostSyncTest.php @@ -242,7 +242,7 @@ class HostSyncTest extends SyncTest } } - public function tearDown() + public function tearDown(): void { $this->removeGroups(['SYNCTEST_groupa', 'SYNCTEST_groupb']); parent::tearDown(); diff --git a/test/php/library/Director/Objects/HostGroupMembershipResolverTest.php b/test/php/library/Director/Objects/HostGroupMembershipResolverTest.php index cf2fb36..df4b24c 100644 --- a/test/php/library/Director/Objects/HostGroupMembershipResolverTest.php +++ b/test/php/library/Director/Objects/HostGroupMembershipResolverTest.php @@ -15,8 +15,9 @@ class HostGroupMembershipResolverTest extends BaseTestCase const PREFIX = '__groupmembership'; const TYPE = 'host'; - public function setUp() + public function setUp(): void { + parent::setUp(); IcingaTemplateRepository::clear(); } @@ -32,12 +33,12 @@ class HostGroupMembershipResolverTest extends BaseTestCase $db->delete('icinga_' . self::TYPE, $where); } - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { static::cleanArtifacts(); } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { static::cleanArtifacts(); } diff --git a/test/php/library/Director/Objects/IcingaCommandTest.php b/test/php/library/Director/Objects/IcingaCommandTest.php index 8e564d8..e3c9d89 100644 --- a/test/php/library/Director/Objects/IcingaCommandTest.php +++ b/test/php/library/Director/Objects/IcingaCommandTest.php @@ -206,11 +206,13 @@ class IcingaCommandTest extends BaseTestCase return file_get_contents(__DIR__ . '/rendered/' . $name . '.out'); } - public function tearDown() + public function tearDown(): void { $db = $this->getDb(); if (IcingaCommand::exists($this->testCommandName, $db)) { IcingaCommand::load($this->testCommandName, $db)->delete(); } + + parent::tearDown(); } } diff --git a/test/php/library/Director/Objects/IcingaHostTest.php b/test/php/library/Director/Objects/IcingaHostTest.php index b4902bf..f8ec222 100644 --- a/test/php/library/Director/Objects/IcingaHostTest.php +++ b/test/php/library/Director/Objects/IcingaHostTest.php @@ -2,6 +2,7 @@ namespace Tests\Icinga\Module\Director\Objects; +use Icinga\Exception\NotFoundError; use Icinga\Module\Director\Data\PropertiesFilter\ArrayCustomVariablesFilter; use Icinga\Module\Director\Data\PropertiesFilter\CustomVariablesFilter; use Icinga\Module\Director\IcingaConfig\IcingaConfig; @@ -255,14 +256,14 @@ class IcingaHostTest extends BaseTestCase $zone->delete(); } - /** - * @expectedException \RuntimeException - */ public function testFailsToStoreWithMissingLazyRelations() { if ($this->skipForMissingDb()) { return; } + + $this->expectException(\RuntimeException::class); + $db = $this->getDb(); $host = $this->host(); $host->zone = '___TEST___zone'; @@ -336,15 +337,14 @@ class IcingaHostTest extends BaseTestCase ); } - /** - * @expectedException \RuntimeException - */ public function testFailsToStoreWithInvalidUnresolvedDependencies() { if ($this->skipForMissingDb()) { return; } + $this->expectException(\RuntimeException::class); + $host = $this->host(); $host->zone = 'invalid'; $host->store($this->getDb()); @@ -396,10 +396,16 @@ class IcingaHostTest extends BaseTestCase $host->object_type = 'template'; $host->zone_id = null; + $zone = $this->newObject('zone', '___TEST___zone2'); + $zone->store($db); + $config = new IcingaConfig($db); $host->renderToConfig($config); $this->assertEquals( - array('zones.d/director-global/host_templates.conf'), + [ + 'zones.d/___TEST___zone/host_templates.conf', + 'zones.d/___TEST___zone2/host_templates.conf', + ], $config->getFileNames() ); } @@ -474,15 +480,14 @@ class IcingaHostTest extends BaseTestCase $b->delete(); } - /** - * @expectedException \Icinga\Exception\NotFoundError - */ public function testWhetherInvalidApiKeyThrows404() { if ($this->skipForMissingDb()) { return; } + $this->expectException(NotFoundError::class); + $db = $this->getDb(); IcingaHost::loadWithApiKey('No___such___key', $db); } @@ -694,36 +699,36 @@ class IcingaHostTest extends BaseTestCase protected function getDefaultHostProperties($prefix = '') { return array( - "${prefix}name" => "name", - "${prefix}action_url" => "action_url", - "${prefix}address" => "address", - "${prefix}address6" => "address6", - "${prefix}api_key" => "api_key", - "${prefix}check_command" => "check_command", - "${prefix}check_interval" => "check_interval", - "${prefix}check_period" => "check_period", - "${prefix}check_timeout" => "check_timeout", - "${prefix}command_endpoint" => "command_endpoint", - "${prefix}display_name" => "display_name", - "${prefix}enable_active_checks" => "enable_active_checks", - "${prefix}enable_event_handler" => "enable_event_handler", - "${prefix}enable_flapping" => "enable_flapping", - "${prefix}enable_notifications" => "enable_notifications", - "${prefix}enable_passive_checks" => "enable_passive_checks", - "${prefix}enable_perfdata" => "enable_perfdata", - "${prefix}event_command" => "event_command", - "${prefix}flapping_threshold_high" => "flapping_threshold_high", - "${prefix}flapping_threshold_low" => "flapping_threshold_low", - "${prefix}icon_image" => "icon_image", - "${prefix}icon_image_alt" => "icon_image_alt", - "${prefix}max_check_attempts" => "max_check_attempts", - "${prefix}notes" => "notes", - "${prefix}notes_url" => "notes_url", - "${prefix}retry_interval" => "retry_interval", - "${prefix}volatile" => "volatile", - "${prefix}zone" => "zone", - "${prefix}groups" => "Groups", - "${prefix}templates" => "templates" + "{$prefix}name" => "name", + "{$prefix}action_url" => "action_url", + "{$prefix}address" => "address", + "{$prefix}address6" => "address6", + "{$prefix}api_key" => "api_key", + "{$prefix}check_command" => "check_command", + "{$prefix}check_interval" => "check_interval", + "{$prefix}check_period" => "check_period", + "{$prefix}check_timeout" => "check_timeout", + "{$prefix}command_endpoint" => "command_endpoint", + "{$prefix}display_name" => "display_name", + "{$prefix}enable_active_checks" => "enable_active_checks", + "{$prefix}enable_event_handler" => "enable_event_handler", + "{$prefix}enable_flapping" => "enable_flapping", + "{$prefix}enable_notifications" => "enable_notifications", + "{$prefix}enable_passive_checks" => "enable_passive_checks", + "{$prefix}enable_perfdata" => "enable_perfdata", + "{$prefix}event_command" => "event_command", + "{$prefix}flapping_threshold_high" => "flapping_threshold_high", + "{$prefix}flapping_threshold_low" => "flapping_threshold_low", + "{$prefix}icon_image" => "icon_image", + "{$prefix}icon_image_alt" => "icon_image_alt", + "{$prefix}max_check_attempts" => "max_check_attempts", + "{$prefix}notes" => "notes", + "{$prefix}notes_url" => "notes_url", + "{$prefix}retry_interval" => "retry_interval", + "{$prefix}volatile" => "volatile", + "{$prefix}zone" => "zone", + "{$prefix}groups" => "Groups", + "{$prefix}templates" => "templates" ); } protected function loadRendered($name) @@ -731,7 +736,7 @@ class IcingaHostTest extends BaseTestCase return file_get_contents(__DIR__ . '/rendered/' . $name . '.out'); } - public function tearDown() + public function tearDown(): void { if ($this->hasDb()) { $db = $this->getDb(); @@ -742,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(); @@ -751,6 +756,8 @@ class IcingaHostTest extends BaseTestCase $this->deleteDatafields(); } + + parent::tearDown(); } protected function deleteDatafields() diff --git a/test/php/library/Director/Objects/IcingaNotificationTest.php b/test/php/library/Director/Objects/IcingaNotificationTest.php index 9d9436a..dbbce91 100644 --- a/test/php/library/Director/Objects/IcingaNotificationTest.php +++ b/test/php/library/Director/Objects/IcingaNotificationTest.php @@ -226,7 +226,7 @@ class IcingaNotificationTest extends BaseTestCase return file_get_contents(__DIR__ . '/rendered/' . $name . '.out'); } - public function tearDown() + public function tearDown(): void { if ($this->hasDb()) { $db = $this->getDb(); @@ -244,5 +244,7 @@ class IcingaNotificationTest extends BaseTestCase } } } + + parent::tearDown(); } } diff --git a/test/php/library/Director/Objects/IcingaServiceSetTest.php b/test/php/library/Director/Objects/IcingaServiceSetTest.php index ad7c135..a9a9fa1 100644 --- a/test/php/library/Director/Objects/IcingaServiceSetTest.php +++ b/test/php/library/Director/Objects/IcingaServiceSetTest.php @@ -10,8 +10,9 @@ class IcingaServiceSetTest extends IcingaObjectTestCase protected $table = 'icinga_service_set'; protected $testObjectName = '___TEST___set'; - public function setUp() + public function setUp(): void { + parent::setUp(); $this->assertNull($this->subject, 'subject must have been taken down before!'); if ($this->hasDb()) { @@ -106,22 +107,20 @@ class IcingaServiceSetTest extends IcingaObjectTestCase $this->checkForDanglingServices(); } - /** - * @expectedException \RuntimeException - */ public function testCreatingSetWithoutType() { + $this->expectException(\RuntimeException::class); + $set = IcingaServiceSet::create(array( 'object_name' => '___TEST__set_BAD', )); $set->store($this->getDb()); } - /** - * @expectedException \InvalidArgumentException - */ public function testCreatingServiceSetWithoutHost() { + $this->expectException(\InvalidArgumentException::class); + $set = IcingaServiceSet::create(array( 'object_name' => '___TEST__set_BAD2', 'object_type' => 'object', diff --git a/test/php/library/Director/Objects/IcingaServiceTest.php b/test/php/library/Director/Objects/IcingaServiceTest.php index 468db67..3005349 100644 --- a/test/php/library/Director/Objects/IcingaServiceTest.php +++ b/test/php/library/Director/Objects/IcingaServiceTest.php @@ -26,15 +26,14 @@ class IcingaServiceTest extends BaseTestCase ); } - /** - * @expectedException \RuntimeException - */ public function testFailsToStoreWithMissingLazyRelations() { if ($this->skipForMissingDb()) { return; } + $this->expectException(\RuntimeException::class); + $db = $this->getDb(); $service = $this->service(); $service->display_name = 'Something else'; @@ -45,16 +44,16 @@ class IcingaServiceTest extends BaseTestCase public function testAcceptsAssignRules() { + $this->expectNotToPerformAssertions(); $service = $this->service(); $service->object_type = 'apply'; $service->assign_filter = 'host.address="127.*"'; } - /** - * @expectedException \LogicException - */ public function testRefusesAssignRulesWhenNotBeingAnApply() { + $this->expectException(\LogicException::class); + $service = $this->service(); $service->assign_filter = 'host.address=127.*'; } @@ -271,7 +270,7 @@ class IcingaServiceTest extends BaseTestCase return file_get_contents(__DIR__ . '/rendered/' . $name . '.out'); } - public function tearDown() + public function tearDown(): void { if ($this->hasDb()) { $db = $this->getDb(); @@ -289,5 +288,7 @@ class IcingaServiceTest extends BaseTestCase } } } + + parent::tearDown(); } } diff --git a/test/php/library/Director/Objects/IcingaTemplateResolverTest.php b/test/php/library/Director/Objects/IcingaTemplateResolverTest.php index 09d0ead..f521d74 100644 --- a/test/php/library/Director/Objects/IcingaTemplateResolverTest.php +++ b/test/php/library/Director/Objects/IcingaTemplateResolverTest.php @@ -144,7 +144,7 @@ class IcingaTemplateResolverTest extends BaseTestCase return $host; } - public function tearDown() + public function tearDown(): void { $db = $this->getDb(); $kill = array('t1', 't2', 't6', 't3', 't4', 't5'); @@ -154,5 +154,7 @@ class IcingaTemplateResolverTest extends BaseTestCase IcingaHost::load($name, $db)->delete(); } } + + parent::tearDown(); } } diff --git a/test/php/library/Director/Objects/IcingaTimePeriodTest.php b/test/php/library/Director/Objects/IcingaTimePeriodTest.php index 84496d3..9888fa4 100644 --- a/test/php/library/Director/Objects/IcingaTimePeriodTest.php +++ b/test/php/library/Director/Objects/IcingaTimePeriodTest.php @@ -171,7 +171,7 @@ class IcingaTimePeriodTest extends BaseTestCase return IcingaTimePeriod::load($this->testPeriodName . $suffix, $this->getDb()); } - public function tearDown() + public function tearDown(): void { $db = $this->getDb(); @@ -180,5 +180,7 @@ class IcingaTimePeriodTest extends BaseTestCase IcingaTimePeriod::load($name, $db)->delete(); } } + + parent::tearDown(); } } diff --git a/test/php/library/Director/PropertyModifier/PropertyModifierArrayElementByPositionTest.php b/test/php/library/Director/PropertyModifier/PropertyModifierArrayElementByPositionTest.php index 84465f3..2f0522a 100644 --- a/test/php/library/Director/PropertyModifier/PropertyModifierArrayElementByPositionTest.php +++ b/test/php/library/Director/PropertyModifier/PropertyModifierArrayElementByPositionTest.php @@ -31,11 +31,10 @@ class PropertyModifierArrayElementByPositionTest extends BaseTestCase ); } - /** - * @expectedException \InvalidArgumentException - */ public function testGettingFirstFailsForEmptyArray() { + $this->expectException(\InvalidArgumentException::class); + $this->buildModifier('first')->transform([]); } @@ -60,11 +59,10 @@ class PropertyModifierArrayElementByPositionTest extends BaseTestCase ); } - /** - * @expectedException \InvalidArgumentException - */ public function testGettingLastFailsForEmptyArray() { + $this->expectException(\InvalidArgumentException::class); + $this->buildModifier('last')->transform([]); } @@ -89,11 +87,10 @@ class PropertyModifierArrayElementByPositionTest extends BaseTestCase ); } - /** - * @expectedException \InvalidArgumentException - */ public function testGettingSpecificFailsForEmptyArray() { + $this->expectException(\InvalidArgumentException::class); + $this->buildModifier('fixed', 1)->transform([]); } @@ -102,11 +99,10 @@ class PropertyModifierArrayElementByPositionTest extends BaseTestCase $this->assertNull($this->buildModifier('fixed', 1, 'null')->transform([])); } - /** - * @expectedException \InvalidArgumentException - */ public function testGettingSpecificFailsForMissingValue() { + $this->expectException(\InvalidArgumentException::class); + $this->buildModifier('fixed', 3)->transform(['one', 'two', 'three']); } @@ -115,11 +111,10 @@ class PropertyModifierArrayElementByPositionTest extends BaseTestCase $this->assertNull($this->buildModifier('fixed', 3, 'null')->transform(['one', 'two', 'three'])); } - /** - * @expectedException \InvalidArgumentException - */ public function testFailsForStrings() { + $this->expectException(\InvalidArgumentException::class); + $this->buildModifier('first')->transform('string'); } diff --git a/test/php/library/Director/PropertyModifier/PropertyModifierListToObjectTest.php b/test/php/library/Director/PropertyModifier/PropertyModifierListToObjectTest.php index 93d498c..0a150be 100644 --- a/test/php/library/Director/PropertyModifier/PropertyModifierListToObjectTest.php +++ b/test/php/library/Director/PropertyModifier/PropertyModifierListToObjectTest.php @@ -23,21 +23,19 @@ class PropertyModifierListToObjectTest extends BaseTestCase ); } - /** - * @expectedException \InvalidArgumentException - */ public function testFailsOnMissingKey() { + $this->expectException(\InvalidArgumentException::class); + $input = $this->getInputArrays(); unset($input[0]['name']); $this->getNewModifier()->transform($input); } - /** - * @expectedException \InvalidArgumentException - */ public function testFailsWithDuplicateRows() { + $this->expectException(\InvalidArgumentException::class); + $input = $this->getInputArrays(); $input[1]['name'] = 'row1'; $this->getNewModifier()->transform($input); diff --git a/test/php/library/Director/PropertyModifier/PropertyModifierParseURLTest.php b/test/php/library/Director/PropertyModifier/PropertyModifierParseURLTest.php index a5ccb79..fe89ac6 100644 --- a/test/php/library/Director/PropertyModifier/PropertyModifierParseURLTest.php +++ b/test/php/library/Director/PropertyModifier/PropertyModifierParseURLTest.php @@ -2,6 +2,7 @@ namespace Tests\Icinga\Module\Director\PropertyModifier; +use Icinga\Exception\InvalidPropertyException; use Icinga\Module\Director\PropertyModifier\PropertyModifierParseURL; use Icinga\Module\Director\Test\BaseTestCase; @@ -50,11 +51,10 @@ class PropertyModifierParseURLTest extends BaseTestCase $this->assertEquals('http://www.icinga.org/path/', $modifier->transform('http://www.icinga.org/path/')); } - /** - * @expectedException \Icinga\Exception\InvalidPropertyException - */ public function testMissingComponentThrowsExceptionOnfailureFail() { + $this->expectException(InvalidPropertyException::class); + $modifier = new PropertyModifierParseURL(); $modifier->setSettings([ 'url_component' => 'query', @@ -87,11 +87,10 @@ class PropertyModifierParseURLTest extends BaseTestCase $this->assertEquals(self::$invalidurl, $modifier->transform(self::$invalidurl)); } - /** - * @expectedException \Icinga\Exception\InvalidPropertyException - */ public function testInvalidUrlThrowsExceptionOnfailureFail() { + $this->expectException(InvalidPropertyException::class); + $modifier = new PropertyModifierParseURL(); $modifier->setSettings([ 'url_component' => 'host', diff --git a/test/php/library/Director/Resolver/TemplateTreeTest.php b/test/php/library/Director/Resolver/TemplateTreeTest.php index f44d081..c2ed916 100644 --- a/test/php/library/Director/Resolver/TemplateTreeTest.php +++ b/test/php/library/Director/Resolver/TemplateTreeTest.php @@ -248,12 +248,14 @@ class TemplateTreeTest extends BaseTestCase } } - public function tearDown() + public function tearDown(): void { if ($this->hasDb()) { $db = $this->getDb(); $this->removeHosts($db); $this->removeServices($db); } + + parent::tearDown(); } } diff --git a/test/setup_vendor.sh b/test/setup_vendor.sh deleted file mode 100755 index c53982f..0000000 --- a/test/setup_vendor.sh +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash - -set -ex - -MODULE_HOME=${MODULE_HOME:="$(dirname "$(readlink -f "$(dirname "$0")")")"} -PHP_VERSION="$(php -r 'echo phpversion();')" - -ICINGAWEB_VERSION=${ICINGAWEB_VERSION:=2.7.1} -ICINGAWEB_GITREF=${ICINGAWEB_GITREF:=} - -if [ "$PHP_VERSION" '<' 7.1.0 ]; then - PHPCS_VERSION=${PHPCS_VERSION:=3.3.2} -else - PHPCS_VERSION=${PHPCS_VERSION:=3.5.2} -fi - -if [ "$PHP_VERSION" '<' 5.6.0 ]; then - PHPUNIT_VERSION=${PHPUNIT_VERSION:=4.8} -else - PHPUNIT_VERSION=${PHPUNIT_VERSION:=5.7} -fi - -cd "${MODULE_HOME}" - -test -d vendor || mkdir vendor -cd vendor/ - -# icingaweb2 -if [ -n "$ICINGAWEB_GITREF" ]; then - icingaweb_path="icingaweb2" - test ! -L "$icingaweb_path" || rm "$icingaweb_path" - - if [ ! -d "$icingaweb_path" ]; then - git clone https://github.com/Icinga/icingaweb2.git "$icingaweb_path" - fi - - ( - set -e - cd "$icingaweb_path" - git fetch -p - git checkout -f "$ICINGAWEB_GITREF" - ) -else - icingaweb_path="icingaweb2-${ICINGAWEB_VERSION}" - if [ ! -e "${icingaweb_path}".tar.gz ]; then - wget -O "${icingaweb_path}".tar.gz https://github.com/Icinga/icingaweb2/archive/v"${ICINGAWEB_VERSION}".tar.gz - fi - if [ ! -d "${icingaweb_path}" ]; then - tar xf "${icingaweb_path}".tar.gz - fi - - rm -f icingaweb2 - ln -svf "${icingaweb_path}" icingaweb2 -fi -ln -svf "${icingaweb_path}"/library/Icinga Icinga -ln -svf "${icingaweb_path}"/library/vendor/Zend Zend - -# phpunit -phpunit_path="phpunit-${PHPUNIT_VERSION}" -if [ ! -e "${phpunit_path}".phar ]; then - wget -O "${phpunit_path}".phar https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar -fi -ln -svf "${phpunit_path}".phar phpunit.phar - -# phpcs -phpcs_path="phpcs-${PHPCS_VERSION}" -if [ ! -e "${phpcs_path}".phar ]; then - wget -O "${phpcs_path}".phar \ - https://github.com/squizlabs/PHP_CodeSniffer/releases/download/${PHPCS_VERSION}/phpcs.phar -fi -ln -svf "${phpcs_path}".phar phpcs.phar diff --git a/test/travis-prepare.sh b/test/travis-prepare.sh deleted file mode 100755 index 7a303e8..0000000 --- a/test/travis-prepare.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -set -ex - -: "${DIRECTOR_TESTDB:=director_test}" - -psql_cmd() { - psql -U postgres ${DIRECTOR_TESTDB} -q -c "$@" -} - -if [ "$DB" = mysql ]; then - mysql -u root -e "DROP DATABASE IF EXISTS ${DIRECTOR_TESTDB}; CREATE DATABASE ${DIRECTOR_TESTDB};" -elif [ "$DB" = pgsql ]; then - : "${DIRECTOR_TESTDB_USER:=director_test}" - - psql -U postgres postgres -q -c "DROP DATABASE IF EXISTS ${DIRECTOR_TESTDB};" - psql -U postgres postgres -q -c "CREATE DATABASE ${DIRECTOR_TESTDB} WITH ENCODING 'UTF8';" - psql_cmd "CREATE USER ${DIRECTOR_TESTDB_USER} WITH PASSWORD 'testing';" - psql_cmd "GRANT ALL PRIVILEGES ON DATABASE ${DIRECTOR_TESTDB} TO ${DIRECTOR_TESTDB_USER};" - psql_cmd "CREATE EXTENSION pgcrypto;" -else - echo "Unknown database set in environment!" >&2 - env - exit 1 -fi |