From 55dd6e5a5aabd0fac9dc2ddc70de52011e5bb4e0 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sat, 27 Feb 2016 02:03:24 +0100 Subject: [PATCH] BaseTestCase: improve db handling --- library/Director/Test/BaseTestCase.php | 29 +++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/library/Director/Test/BaseTestCase.php b/library/Director/Test/BaseTestCase.php index 6fe0deb1..3aaa402b 100644 --- a/library/Director/Test/BaseTestCase.php +++ b/library/Director/Test/BaseTestCase.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Test; use Icinga\Application\Cli; use Icinga\Application\Config; +use Icinga\Exception\ConfigurationError; use Icinga\Module\Director\Db; use PHPUnit_Framework_TestCase; @@ -18,10 +19,36 @@ class BaseTestCase extends PHPUnit_Framework_TestCase $this->app(); } + protected function skipForMissingDb() + { + if ($this->hasDb()) { + return false; + } + + $this->markTestSkipped('Test db resource has not been configured'); + + return true; + } + + protected function hasDb() + { + return $this->getDbResourceName() !== null; + } + + protected function getDbResourceName() + { + return Config::module('director')->get('testing', 'db_resource'); + } + protected function getDb() { if ($this->db === null) { - $resourceName = Config::module('director')->get('db', 'resource'); + $resourceName = $this->getDbResourceName(); + if (! $resourceName) { + throw new ConfigurationError( + 'Could not run DB-based tests, please configure a testing db resource' + ); + } $this->db = Db::fromResourceName($resourceName); }