aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/UnitTestCase.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-05-27 06:17:05 +0000
committerMario <mario@mariovavti.com>2024-05-27 06:17:05 +0000
commit84abf28ceca3632c22983f23326297c17b994224 (patch)
treefcc58ecd7ad3c9f9768c168d5a15f557545a52ad /tests/unit/UnitTestCase.php
parenta10402a7883efd4886ad17c8133c10237f443181 (diff)
parentcad82d12d2aad1a54fa821061dd3dc1ffc732c5a (diff)
downloadvolse-hubzilla-84abf28ceca3632c22983f23326297c17b994224.tar.gz
volse-hubzilla-84abf28ceca3632c22983f23326297c17b994224.tar.bz2
volse-hubzilla-84abf28ceca3632c22983f23326297c17b994224.zip
Merge branch 'update-phpunit-10x' into 'dev'
Upgrade test framework to PHPUnit 10.5 See merge request hubzilla/core!2128
Diffstat (limited to 'tests/unit/UnitTestCase.php')
-rw-r--r--tests/unit/UnitTestCase.php31
1 files changed, 21 insertions, 10 deletions
diff --git a/tests/unit/UnitTestCase.php b/tests/unit/UnitTestCase.php
index 9ab6a534a..844746a51 100644
--- a/tests/unit/UnitTestCase.php
+++ b/tests/unit/UnitTestCase.php
@@ -22,8 +22,8 @@
namespace Zotlabs\Tests\Unit;
+use PHPUnit\Framework\Attributes\{Before, After};
use PHPUnit\Framework\TestCase;
-use PHPUnit\Framework\TestResult;
/*
* Make sure global constants and the global App object is available to the
@@ -46,33 +46,44 @@ require_once 'include/dba/dba_driver.php' ;
*/
class UnitTestCase extends TestCase {
protected array $fixtures = array();
+ protected ?\DbaTransaction $db_transacton = null;
/**
- * Override the run method, so we can wrap it in a database transaction.
+ * Connect to the test db, load fixtures and global config.
*
- * The transaction is automatically rolled back when the test completes, to
- * leave the test database in a known pristine state.
+ * This function is executed before every test.
*
- * @SuppressWarnings(PHPMD.UnusedLocalVariable)
+ * The transaction is rolled back in the `cleanup_test_db()` function
+ * that's executed after every test.
*/
- public function run(TestResult $result = null): TestResult {
+ #[Before]
+ protected function setup_test_db(): void {
if (! \DBA::$dba) {
$this->connect_to_test_db();
}
// The $transactuion variable is needed to hold the transaction until the
// function returns.
- $transaction = new \DbaTransaction(\DBA::$dba);
+ $this->db_transaction = new \DbaTransaction(\DBA::$dba);
$this->loadFixtures();
// Make sure app config is reset and loaded from fixtures
\App::$config = array();
\Zotlabs\Lib\Config::Load('system');
+ }
- $result = parent::run($result);
-
- return $result;
+ /**
+ * Roll back test database to it's original state, cleaning up
+ * any changes from the test.
+ *
+ * This function is executes after evert tests.
+ */
+ #[After]
+ protected function cleanup_test_db(): void {
+ // Setting the transaction to `null`, runs the destructor
+ // which rolls backk the transacton.
+ $this->db_transaction = null;
}
/**