0
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2024-09-19 19:22:14 +02:00
postfixadmin/tests/bootstrap.php

92 lines
2.8 KiB
PHP
Raw Normal View History

2018-12-29 22:45:12 +01:00
<?php
define('POSTFIXADMIN', 1);
define('POSTFIXADMIN_CLI', 1);
require_once(dirname(__FILE__) . '/../vendor/autoload.php');
require_once(dirname(__FILE__) . '/../common.php');
2019-01-03 19:51:11 +01:00
$CONF['default_language'] = 'en';
$CONF['language_hook'] = '';
2018-12-29 22:45:12 +01:00
if (getenv('DATABASE') == 'sqlite' || getenv('DATABASE') == false) {
2021-01-25 23:08:36 +01:00
$version = PHP_VERSION_ID; // try and stop different tests running at the same trying to use the same sqlite db at once
$db_file = tempnam(sys_get_temp_dir(), 'postfixadmin-test');
$CONF['database_type'] = 'sqlite';
$CONF['database_name'] = $db_file;
Config::write('database_type', 'sqlite');
Config::write('database_name', $db_file);
clearstatcache();
if (file_exists($db_file)) {
unlink($db_file);
}
touch($db_file);
2019-02-15 22:58:41 +01:00
error_log("Using: SQLite database for tests - $db_file");
}
if (getenv('DATABASE') == 'postgresql') {
$user = getenv('PGUSER') ?: 'postgres';
$pass = getenv('PGPASSWORD') ?: '';
$host = getenv('PGHOST') ?: 'localhost';
$CONF['database_type'] = 'pgsql';
$CONF['database_user'] = $user;
2019-02-16 20:27:27 +01:00
$CONF['database_password'] = $pass;
$CONF['database_host'] = $host;
$CONF['database_name'] = 'postfixadmin';
Config::write('database_type', 'pgsql');
Config::write('database_user', $user);
2019-02-16 20:27:27 +01:00
Config::write('database_password', $pass);
Config::write('database_name', 'postfixadmin');
Config::write('database_host', $host);
2019-02-15 22:58:41 +01:00
error_log("Using: PostgreSQL database for tests\n");
}
if (getenv('DATABASE') == 'mysql') {
2019-02-15 22:38:42 +01:00
$expand_tilde = function ($path) {
if (function_exists('posix_getuid') && strpos($path, '~') !== false) {
$info = posix_getpwuid(posix_getuid());
$path = str_replace('~', $info['dir'], $path);
}
2018-12-29 22:45:12 +01:00
return $path;
};
2018-12-29 22:45:12 +01:00
$config = parse_ini_file($expand_tilde('~/.my.cnf'));
2019-02-15 22:38:42 +01:00
if (empty($config)) {
$config = ['user' => 'root', 'host' => '127.0.0.1', 'password' => ''];
}
2019-02-15 23:10:31 +01:00
if (isset($config['socket'])) {
$CONF['database_socket'] = $config['socket'];
Config::write('database_socket', $config['socket']);
} else {
$CONF['database_host'] = $config['host'];
Config::write('database_host', $config['host']);
}
$CONF['database_type'] = 'mysql';
$CONF['database_user'] = $config['user'];
2019-02-16 20:27:27 +01:00
$CONF['database_password'] = $config['password'];
$CONF['database_name'] = 'postfixadmin';
Config::write('database_type', 'mysql');
Config::write('database_user', $config['user']);
2019-02-16 20:27:27 +01:00
Config::write('database_password', $config['password']);
Config::write('database_name', 'postfixadmin');
2019-02-15 22:58:41 +01:00
error_log("Using: MySQL database for tests");
}
2018-12-29 22:45:12 +01:00
try {
$db = db_connect();
} catch (Exception $e) {
2019-02-10 12:08:18 +01:00
echo "failed to connect to database\n";
echo $e->getMessage();
2019-02-10 12:08:18 +01:00
exit(1);
}
2018-12-29 22:45:12 +01:00
2019-01-03 19:51:11 +01:00
require_once(dirname(__FILE__) . '/../public/upgrade.php');