// we need full error reporting
error_reporting(E_ALL & ~E_NOTICE);
- if (!empty($GLOBALS['mysql_db'])) {
- self::$_dbName = $GLOBALS['mysql_db'];
- }
- else {
- self::$_dbName = 'civicrm_tests_dev';
- }
+ self::$_dbName = self::getDBName();
// create test database
- self::$utils = new Utils($GLOBALS['mysql_host'],
- $GLOBALS['mysql_port'],
- $GLOBALS['mysql_user'],
- $GLOBALS['mysql_pass']
- );
+ self::$utils = new Utils(CIVICRM_DSN);
// also load the class loader
require_once 'CRM/Core/ClassLoader.php';
* @return string
*/
public static function getDBName() {
- $dbName = !empty($GLOBALS['mysql_db']) ? $GLOBALS['mysql_db'] : 'civicrm_tests_dev';
+ static $dbName = NULL;
+ if ($dbName === NULL ) {
+ require_once "DB.php";
+ $dsninfo = DB::parseDSN(CIVICRM_DSN);
+ $dbName = $dsninfo['database'];
+ }
return $dbName;
}
* FIXME: Maybe a better way to do it
*/
public function foreignKeyChecksOff() {
- self::$utils = new Utils($GLOBALS['mysql_host'],
- $GLOBALS['mysql_port'],
- $GLOBALS['mysql_user'],
- $GLOBALS['mysql_pass']
- );
+ self::$utils = new Utils(CIVICRM_DSN);
$dbName = self::getDBName();
$query = "USE {$dbName};" . "SET foreign_key_checks = 1";
if (self::$utils->do_query($query) === FALSE) {
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'];
-
// ------------------------------------------------------------------------------
/**
/**
* Construct an object for this database.
- * @param $host
- * @param $port
- * @param $user
- * @param $pass
*/
- public function __construct($host, $port, $user, $pass) {
+ public function __construct($dsn) {
+ require_once "DB.php";
+ $dsninfo = DB::parseDSN($dsn);
+ $host = $dsninfo['hostspec'];
+ $port = @$dsninfo['port'];
+ $user = $dsninfo['username'];
+ $pass = $dsninfo['password'];
+
try {
$this->pdo = new PDO("mysql:host={$host}" . ($port ? ";port=$port" : ""),
$user, $pass,