mirror of
https://github.com/dg/dibi.git
synced 2025-08-16 19:14:17 +02:00
tests: improved testing environment
This commit is contained in:
@@ -14,5 +14,51 @@ Tester\Environment::setup();
|
||||
date_default_timezone_set('Europe/Prague');
|
||||
|
||||
|
||||
// load connections
|
||||
$config = require __DIR__ . '/config.php';
|
||||
// load connection
|
||||
try {
|
||||
$config = Tester\Environment::loadData();
|
||||
} catch (Exception $e) {
|
||||
$config = parse_ini_file(__DIR__ . '/../databases.ini', TRUE);
|
||||
$config = $config['sqlite3'];
|
||||
}
|
||||
|
||||
|
||||
// lock
|
||||
define('TEMP_DIR', __DIR__ . '/../tmp');
|
||||
@mkdir(TEMP_DIR); // @ - directory may already exist
|
||||
Tester\Environment::lock($config['system'], TEMP_DIR);
|
||||
|
||||
|
||||
try {
|
||||
new DibiConnection($config);
|
||||
} catch (DibiNotSupportedException $e) {
|
||||
Tester\Environment::skip($e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
function test(\Closure $function)
|
||||
{
|
||||
$function();
|
||||
}
|
||||
|
||||
|
||||
/** Replaces [] with driver-specific quotes */
|
||||
function reformat($s)
|
||||
{
|
||||
global $config;
|
||||
if (is_array($s)) {
|
||||
if (isset($s[$config['system']])) {
|
||||
return $s[$config['system']];
|
||||
}
|
||||
$s = $s[0];
|
||||
}
|
||||
if ($config['system'] === 'mysql') {
|
||||
return strtr($s, '[]', '``');
|
||||
} elseif ($config['system'] === 'pgsql') {
|
||||
return strtr($s, '[]', '""');
|
||||
} elseif ($config['system'] === 'odbc' || $config['system'] === 'sqlite') {
|
||||
return $s;
|
||||
} else {
|
||||
trigger_error("Unsupported driver $config[system]", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user