[icinga-checkins] icinga.org: icingaweb2-module-director/master: BaseTestCase: provide db for our tests

git at icinga.org git at icinga.org
Thu Feb 25 19:21:37 CET 2016


Module: icingaweb2-module-director
Branch: master
Commit: 77804d2b373d1d5c702a18ec096ef857487426a8
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=77804d2b373d1d5c702a18ec096ef857487426a8

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Feb 25 19:01:48 2016 +0100

BaseTestCase: provide db for our tests

---

 library/Director/Test/BaseTestCase.php                   |   14 ++++++++++++++
 .../library/Director/Objects/TimePeriodRangesTest.php    |   11 +----------
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/library/Director/Test/BaseTestCase.php b/library/Director/Test/BaseTestCase.php
index cb513fc..6fe0deb 100644
--- a/library/Director/Test/BaseTestCase.php
+++ b/library/Director/Test/BaseTestCase.php
@@ -3,17 +3,31 @@
 namespace Icinga\Module\Director\Test;
 
 use Icinga\Application\Cli;
+use Icinga\Application\Config;
+use Icinga\Module\Director\Db;
 use PHPUnit_Framework_TestCase;
 
 class BaseTestCase extends PHPUnit_Framework_TestCase
 {
     private static $app;
 
+    private $db;
+
     public function setUp()
     {
         $this->app();
     }
 
+    protected function getDb()
+    {
+        if ($this->db === null) {
+            $resourceName = Config::module('director')->get('db', 'resource');
+            $this->db = Db::fromResourceName($resourceName);
+        }
+
+        return $this->db;
+    }
+
     protected function app()
     {
         if (self::$app === null) {
diff --git a/test/php/library/Director/Objects/TimePeriodRangesTest.php b/test/php/library/Director/Objects/TimePeriodRangesTest.php
index 3b8dfd6..96fc7d1 100644
--- a/test/php/library/Director/Objects/TimePeriodRangesTest.php
+++ b/test/php/library/Director/Objects/TimePeriodRangesTest.php
@@ -2,24 +2,15 @@
 
 namespace Tests\Icinga\Modules\Director\Objects;
 
-use Icinga\Application\Config;
-use Icinga\Module\Director\Db;
 use Icinga\Module\Director\Objects\IcingaTimePeriodRange;
 use Icinga\Module\Director\Objects\IcingaTimePeriodRanges;
 use Icinga\Module\Director\Objects\IcingaTimePeriod;
 use Icinga\Module\Director\Test\BaseTestCase;
 
-class TimePeriodRangesTest extends BaseTestCase
+class IcingaTimePeriodRangesTest extends BaseTestCase
 {
     protected $testPeriodName = '___TEST___timerange';
 
-    public function getDb()
-    {
-        $resourceName = Config::module('director')->get('db', 'resource');
-        $db = Db::fromResourceName($resourceName);
-        return $db;
-    }
-
     public function testUpdate()
     {
         $period = $this->createTestPeriod();



More information about the icinga-checkins mailing list