mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2024-09-19 19:22:14 +02:00
try adding mysql + postgres support to tests
This commit is contained in:
parent
4d7ac16bfb
commit
dcb60a670c
12
.travis.yml
12
.travis.yml
@ -2,13 +2,25 @@ language: php
|
||||
php:
|
||||
- 7.2
|
||||
|
||||
services:
|
||||
- mysql
|
||||
- postgresql
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
before_install:
|
||||
- mysql -e 'CREATE DATABASE postfixadmin;'
|
||||
- psql -c 'create database postfixadmin;' -U postgres
|
||||
|
||||
|
||||
before_script:
|
||||
- composer install
|
||||
|
||||
script:
|
||||
- composer build
|
||||
- composer test-sqlite
|
||||
- composer test-mysql
|
||||
- composer test-postgresql
|
||||
|
||||
|
@ -8,13 +8,14 @@
|
||||
"@check-format",
|
||||
"@lint",
|
||||
"@test-fixup",
|
||||
"@psalm",
|
||||
"@test"
|
||||
"@psalm"
|
||||
],
|
||||
"check-format": "php-cs-fixer fix --ansi --dry-run --diff",
|
||||
"format": "php-cs-fixer fix --ansi",
|
||||
"lint": "@php ./vendor/bin/parallel-lint --exclude vendor/ --exclude lib/block_random_int.php --exclude lib/array_column.php .",
|
||||
"test": "@php ./vendor/bin/phpunit tests/",
|
||||
"test-sqlite": "DATABASE=sqlite ./vendor/bin/phpunit tests/",
|
||||
"test-mysql": "DATABASE=mysql ./vendor/bin/phpunit tests/",
|
||||
"test-postgresql": "DATABASE=postgresql ./vendor/bin/phpunit tests/",
|
||||
"test-fixup": "mkdir -p templates_c ; test -f config.local.php || touch config.local.php",
|
||||
"psalm": "@php ./vendor/bin/psalm --no-cache --show-info=false "
|
||||
},
|
||||
|
@ -10,21 +10,65 @@ require_once(dirname(__FILE__) . '/../common.php');
|
||||
$CONF['default_language'] = 'en';
|
||||
$CONF['language_hook'] = '';
|
||||
|
||||
$db_file = dirname(__FILE__) . '/postfixadmin.sqlite.test';
|
||||
if (getenv('DATABASE') == 'sqlite' || getenv('DATABASE') == false) {
|
||||
$db_file = dirname(__FILE__) . '/postfixadmin.sqlite.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);
|
||||
var_dump('sqlite');
|
||||
}
|
||||
if (getenv('DATABASE') == 'postgresql') {
|
||||
|
||||
$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);
|
||||
$user = getenv('PGUSER') ?: 'postgres';
|
||||
$pass = getenv('PGPASSWORD') ?: '';
|
||||
$host = getenv('PGHOST') ?: 'localhost';
|
||||
|
||||
$CONF['database_type'] = 'pgsql';
|
||||
$CONF['database_user'] = $user;
|
||||
$CONF['database_pass'] = $pass;
|
||||
$CONF['database_host'] = $host;
|
||||
$CONF['database_name'] = 'postfixadmin';
|
||||
Config::write('database_type', 'pgsql');
|
||||
Config::write('database_user', $user);
|
||||
Config::write('database_pass', $pass);
|
||||
Config::write('database_name', 'postfixadmin');
|
||||
Config::write('database_host', $host);
|
||||
var_dump('postgresql');
|
||||
}
|
||||
|
||||
if (getenv('DATABASE') == 'mysql') {
|
||||
|
||||
$expand_tilde = function($path) {
|
||||
if (function_exists('posix_getuid') && strpos($path, '~') !== false) {
|
||||
$info = posix_getpwuid(posix_getuid());
|
||||
$path = str_replace('~', $info['dir'], $path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
};
|
||||
|
||||
$config = parse_ini_file($expand_tilde('~/.my.cnf'));
|
||||
|
||||
if(empty($config)) {
|
||||
$config = ['user'=>'root', 'host' => 'localhost', 'password' => ''];
|
||||
}
|
||||
$CONF['database_type'] = 'mysql';
|
||||
$CONF['database_user'] = $config['user'];
|
||||
$CONF['database_pass'] = $config['password'];
|
||||
$CONF['database_name'] = 'postfixadmin';
|
||||
Config::write('database_type', 'mysql');
|
||||
Config::write('database_user', $config['user']);
|
||||
Config::write('database_pass', $config['password']);
|
||||
Config::write('database_name', 'postfixadmin');
|
||||
var_dump('mysql');
|
||||
}
|
||||
|
||||
touch($db_file);
|
||||
|
||||
list($db, $error_text) = db_connect_with_errors();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user