From 3090a72bdc4f58fac889bc2ef8521dca3f197f70 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 16 Dec 2022 00:00:46 -0800 Subject: [PATCH] CiviUnitTestCase - Remove redundant reset In CiviUnitTestCase, there are methods `setUpBeforeClass()` and `setUp()`. Both methods reset the database unconditionally. The general flow is like this: 1: setUpBeforeClass(); 2: setUp(); testApple(); tearDown(); 3: setUp(); testBanana(); tearDown(); 4: setUp(); testCherry(); tearDown(); 5: tearDownAfterClass(); You might say: "Aha! You need the call in `setUp`, because it runs more frequently!" But not really - because `setUp()` has an extra guard (`static::$dbInit`). In effect, you perform DB-reset at step 1 -- and then immediately again on step 2 -- and then never again (steps 3+4+5). It is conceivable that a subclass might override these methods and inject additional initialization steps -- in which case, this patch may affect their behavior. We'll just have to run the test-suite to find out. Final thought - If `static::$dbInit` were manipulated by other code, then `setUp()` would be much more interesting. But it's counterfactual -- grep finds nothing that manipulates `dbInit`. --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 8f08a91931..889cbf9736 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -78,13 +78,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { use \Civi\Test\MailingTestTrait; use \Civi\Test\LocaleTestTrait; - /** - * Database has been initialized. - * - * @var bool - */ - private static $dbInit = FALSE; - /** * API version in use. * @@ -289,11 +282,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { exit(1); } - if (!self::$dbInit) { - \Civi\Test::asPreInstall([static::CLASS, 'buildEnvironment'])->apply(TRUE); - self::$dbInit = TRUE; - } - // "initialize" CiviCRM to avoid problems when running single tests // FIXME: look at it closer in second stage -- 2.25.1