BaseTestCase: provide db for our tests

This commit is contained in:
Thomas Gelf 2016-02-25 19:01:48 +01:00
parent f9c694d39d
commit 77804d2b37
2 changed files with 15 additions and 10 deletions

View File

@ -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) {

View File

@ -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();