diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2023-07-17 22:09:36 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2023-08-12 20:26:02 +0200 |
commit | 50a7aca88aca38e632928083bb4ac34ced41b464 (patch) | |
tree | 6a469d6714932982b2ddcc020a635bc0f6aac9f0 /tests/unit/UnitTestCase.php | |
parent | 87c41cb9ac3c1bd147e8cc2eae66d01f0eaa9c05 (diff) | |
download | volse-hubzilla-50a7aca88aca38e632928083bb4ac34ced41b464.tar.gz volse-hubzilla-50a7aca88aca38e632928083bb4ac34ced41b464.tar.bz2 volse-hubzilla-50a7aca88aca38e632928083bb4ac34ced41b464.zip |
WIP: begin integrating DB testing.
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(); + } + } } |