diff options
Diffstat (limited to 'tests/unit/UnitTestCase.php')
-rw-r--r-- | tests/unit/UnitTestCase.php | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/tests/unit/UnitTestCase.php b/tests/unit/UnitTestCase.php index f6fb28555..4f2233042 100644 --- a/tests/unit/UnitTestCase.php +++ b/tests/unit/UnitTestCase.php @@ -29,6 +29,7 @@ use PHPUnit\Framework\TestCase; * tests. */ require_once __DIR__ . '/../../boot.php'; +require_once('include/dba/dba_driver.php'); /** * @brief Base class for our Unit Tests. @@ -39,6 +40,38 @@ require_once __DIR__ . '/../../boot.php'; * * @author Klaus Weidenbach */ -abstract class UnitTestCase extends TestCase { - // when needed we can define functionality here which is used in UnitTests. +class UnitTestCase extends TestCase { + public static function setUpBeforeClass() : void { + if ( !\DBA::$dba ) { + \DBA::dba_factory( + getenv('HZ_TEST_DB_HOST'), + getenv('HZ_TEST_DB_PORT', ''), + getenv('HZ_TEST_DB_USER'), + getenv('HZ_TEST_DB_PASS'), + getenv('HZ_TEST_DB_DATABASE'), + getenv('HZ_TEST_DB_TYPE'), + getenv('HZ_TEST_DB_CHARSET'), + false); + + if ( !\DBA::$dba->connected ) { + throw new \Exception("Unable to connect to db!"); + } + } + } + + protected function setUp() : void { + if ( \DBA::$dba->connected ) { + // Create a transaction, so that any actions taken by the + // tests does not change the actual contents of the database. + \DBA::$dba->beginTransaction(); + } + } + + protected function tearDown() : void { + if ( \DBA::$dba->connected ) { + // Roll back the transaction, restoring the db to the + // state it was before the test was run. + \DBA::$dba->rollBack(); + } + } } |