From 8978e6b53b62c37e285ad50f7769127aaa14508b Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 14 Dec 2022 23:04:05 -0800 Subject: [PATCH] CiviUnitTestCase - Inline misleading function 'getConnection' This function returns a connection that nobody uses. It has only one caller. It's mostly interesting because it can reset the database. Hiding it under the name `getConnection` is misleading. --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 32 +++++---------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 603331a564..0660d25b77 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -254,26 +254,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { return $dbName; } - /** - * Create database connection for this instance. - * - * Initialize the test database if it hasn't been initialized - * - */ - protected function getConnection() { - if (!self::$dbInit) { - $dbName = self::getDBName(); - - // install test database - echo PHP_EOL . "Installing {$dbName} database" . PHP_EOL; - - static::_populateDB(FALSE, $this); - - self::$dbInit = TRUE; - } - - } - /** * @param bool $perClass * @param null $object @@ -331,11 +311,13 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { exit(1); } - // Get and save a connection to the database - $this->getConnection(); /* NOTE: Side-effects! */ - - // reload database before each test - // $this->_populateDB(); + if (!self::$dbInit) { + $dbName = self::getDBName(); + // install test database + echo PHP_EOL . "Installing {$dbName} database" . PHP_EOL; + static::_populateDB(FALSE, $this); + self::$dbInit = TRUE; + } // "initialize" CiviCRM to avoid problems when running single tests // FIXME: look at it closer in second stage -- 2.25.1