From 8cfba744faab400d5cf72cc2fad328f787127214 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 15 Dec 2022 00:31:45 -0800 Subject: [PATCH] CiviUnitTestCase - Inline method '_populateDB()' At this point, it's just a bunch of verbosely written conditions that appear to be trueisms; * When called via `setUpBeforeClass()`, the `$perClass` flag is TRUE, so it does the reset. * When called via `setUp()`, the `$object` flag is non-null, so it does the reset. At this point, the actual reset bit is 1-line. Easier to just call that. --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 27 ++------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 06762cc51a..99484fe82e 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -254,29 +254,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { return $dbName; } - /** - * @param bool $perClass - * @param null $object - * - * @return bool - * TRUE if the populate logic runs; FALSE if it is skipped - */ - protected static function _populateDB($perClass = FALSE, &$object = NULL) { - if ($perClass || $object == NULL) { - $dbreset = TRUE; - } - else { - $dbreset = $object->DBResetRequired; - } - - if (!$dbreset) { - return FALSE; - } - - \Civi\Test::asPreInstall([static::CLASS, 'buildEnvironment'])->apply(TRUE); - return TRUE; - } - /** * Declare the environment that we wish to run in. * @@ -299,7 +276,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { throw new \RuntimeException("CiviUnitTestCase requires CIVICRM_UF=UnitTests"); } - static::_populateDB(TRUE); + \Civi\Test::asPreInstall([static::CLASS, 'buildEnvironment'])->apply(TRUE); // also set this global hack $GLOBALS['_PEAR_ERRORSTACK_OVERRIDE_CALLBACK'] = []; @@ -327,7 +304,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { $dbName = self::getDBName(); // install test database echo PHP_EOL . "Installing {$dbName} database" . PHP_EOL; - static::_populateDB(FALSE, $this); + \Civi\Test::asPreInstall([static::CLASS, 'buildEnvironment'])->apply(TRUE); self::$dbInit = TRUE; } -- 2.25.1