Merge pull request #12356 from pradpnayak/issue-202
[civicrm-core.git] / tests / phpunit / CiviTest / bootstrap.php
index 2dd6a2c442982d054e43497a26fb2bce04f7c26b..d50ff31fadaef4550c8714ec856223e24013d9a5 100644 (file)
@@ -18,14 +18,9 @@ ini_set('memory_limit', '2G');
 define('CIVICRM_TEST', 1);
 eval(cv('php:boot --level=settings', 'phpcode'));
 
-// This is exists to support CiviUnitTestCase::populateDB(). That doesn't make it a good idea.
-require_once "DB.php";
-$dsninfo = DB::parseDSN(CIVICRM_DSN);
-$GLOBALS['mysql_host'] = $dsninfo['hostspec'];
-$GLOBALS['mysql_port'] = @$dsninfo['port'];
-$GLOBALS['mysql_user'] = $dsninfo['username'];
-$GLOBALS['mysql_pass'] = $dsninfo['password'];
-$GLOBALS['mysql_db'] = $dsninfo['database'];
+if (CIVICRM_UF === 'UnitTests') {
+  Civi\Test::headless()->apply();
+}
 
 // ------------------------------------------------------------------------------
 
@@ -44,8 +39,10 @@ $GLOBALS['mysql_db'] = $dsninfo['database'];
 function cv($cmd, $decode = 'json') {
   $cmd = 'cv ' . $cmd;
   $descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => STDERR);
-  $env = $_ENV + array('CV_OUTPUT' => 'json');
-  $process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__, $env);
+  $oldOutput = getenv('CV_OUTPUT');
+  putenv("CV_OUTPUT=json");
+  $process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__);
+  putenv("CV_OUTPUT=$oldOutput");
   fclose($pipes[0]);
   $result = stream_get_contents($pipes[1]);
   fclose($pipes[1]);