aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2023-08-13 13:49:48 +0200
committerHarald Eilertsen <haraldei@anduin.net>2023-08-13 13:49:48 +0200
commitfd8aca2cba2530265a58d8966babdbbcb01d64e1 (patch)
tree3572de5e42de7168aebc7259be5b753b85b9732d /tests
parent50a7aca88aca38e632928083bb4ac34ced41b464 (diff)
downloadvolse-hubzilla-fd8aca2cba2530265a58d8966babdbbcb01d64e1.tar.gz
volse-hubzilla-fd8aca2cba2530265a58d8966babdbbcb01d64e1.tar.bz2
volse-hubzilla-fd8aca2cba2530265a58d8966babdbbcb01d64e1.zip
tests: Fix transactions handling in UnitTestCase.
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/UnitTestCase.php18
1 files changed, 14 insertions, 4 deletions
diff --git a/tests/unit/UnitTestCase.php b/tests/unit/UnitTestCase.php
index 4f2233042..afdaf1c9a 100644
--- a/tests/unit/UnitTestCase.php
+++ b/tests/unit/UnitTestCase.php
@@ -41,6 +41,8 @@ require_once('include/dba/dba_driver.php');
* @author Klaus Weidenbach
*/
class UnitTestCase extends TestCase {
+ private bool $in_transaction = false;
+
public static function setUpBeforeClass() : void {
if ( !\DBA::$dba ) {
\DBA::dba_factory(
@@ -54,7 +56,9 @@ class UnitTestCase extends TestCase {
false);
if ( !\DBA::$dba->connected ) {
- throw new \Exception("Unable to connect to db!");
+ throw new \Exception(
+ "Unable to connect to db! Error is: "
+ . \DBA::$dba->db->errorInfo());
}
}
}
@@ -63,15 +67,21 @@ class UnitTestCase extends TestCase {
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();
+ $this->in_transaction = \DBA::$dba->db->beginTransaction();
}
}
protected function tearDown() : void {
- if ( \DBA::$dba->connected ) {
+ if ( \DBA::$dba->connected && $this->in_transaction ) {
// Roll back the transaction, restoring the db to the
// state it was before the test was run.
- \DBA::$dba->rollBack();
+ if ( \DBA::$dba->db->rollBack() ) {
+ $this->in_transaction = false;
+ } else {
+ throw new \Exception(
+ "Transaction rollback failed! Error is: "
+ . \DBA::$dba->db->errorInfo());
+ }
}
}
}