From 0f591678ee86edf67f26965994acacc37bfda68c Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 15 Dec 2022 23:52:27 -0800 Subject: [PATCH] CiviUnitTestCase - Display more accurate debug note If you skimmed, you might say: It prints a console message when it resets the DB. That seems like useful information for someone who wants to understand the overall behavior, so good. The reality is different. `setUpBeforeClass()` and `setUp()` both reset the DB. `setUpBeforeClass()` does it for every test-class, but it never says so. `setUp()` does it for the first test-method (and then no others). So when it showed the message "Installing database", it should have really said: > I just installed the database a minute ago without telling you. > Now I'm installing it a second time, and you should know that. > In the future, I will install twenty more times, but you don't need to know that. That's a silly thing to say. Better to say when it's happening for realz. --- tests/phpunit/CiviTest/CiviUnitTestCase.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index a6986d28f2..71b233213d 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -264,6 +264,9 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { final public static function buildEnvironment(): \Civi\Test\CiviEnvBuilder { // Ideally: return Civi\Test::headless(); $b = new \Civi\Test\CiviEnvBuilder(); + $b->callback(function () { + fprintf(STDERR, "\nInstalling %s database\n", \Civi\Test::dsn('database')); + }); $b->callback([\Civi\Test::data(), 'populate']); return $b; } @@ -297,7 +300,6 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { } if (!self::$dbInit) { - fprintf(STDERR, "\nInstalling %s database\n", \Civi\Test::dsn('database')); \Civi\Test::asPreInstall([static::CLASS, 'buildEnvironment'])->apply(TRUE); self::$dbInit = TRUE; } -- 2.25.1