From dd6530f69fec27d079cd192b3e174d8691a12af7 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 15 Dec 2022 00:26:46 -0800 Subject: [PATCH] CiviUnitTestCase - Extract method 'buildEnvironment'. Future target for method-overrides. --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 24 +++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index eafb871002..06762cc51a 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -273,15 +273,27 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { return FALSE; } - Civi\Test::data()->populate(); - - // `CiviUnitTestCase` has replaced the baseline DB configuration. To coexist with other - // tests based on `CiviEnvBuilder`, we need to store a signature marking the current DB configuration. - (new \Civi\Test\CiviEnvBuilder())->callback(function(){}, 'CiviUnitTestCase')->apply(TRUE); - + \Civi\Test::asPreInstall([static::CLASS, 'buildEnvironment'])->apply(TRUE); return TRUE; } + /** + * Declare the environment that we wish to run in. + * + * TODO: The hope is to get this to align with `Civi\Test::headless()` and perhaps + * assimilate other steps from 'setUp()'. The method is reserved while we look + * for the right split. However, when we're a little further along on that, this + * should be made overrideable. + * + * @return \Civi\Test\CiviEnvBuilder + */ + final public static function buildEnvironment(): \Civi\Test\CiviEnvBuilder { + // Ideally: return Civi\Test::headless(); + $b = new \Civi\Test\CiviEnvBuilder(); + $b->callback([\Civi\Test::data(), 'populate']); + return $b; + } + public static function setUpBeforeClass(): void { if (CIVICRM_UF !== 'UnitTests') { throw new \RuntimeException("CiviUnitTestCase requires CIVICRM_UF=UnitTests"); -- 2.25.1