Integration tests: create database if not exists

This commit is contained in:
Taras Machyshyn
2019-08-13 16:09:02 +03:00
parent ed897e9b97
commit 16c24abb55
2 changed files with 15 additions and 1 deletions
+1
View File
@@ -191,6 +191,7 @@ class Tester
}
//remove and copy Espo files
Utils::checkCreateDatabase($configData['database']);
Utils::dropTables($configData['database']);
$fileManager->removeInDir($this->installPath);
$tt = $fileManager->copy($latestEspo, $this->installPath, true);
+14 -1
View File
@@ -124,6 +124,19 @@ class Utils
} /*END: SET UNDEFINED VARIABLES*/
}
public static function checkCreateDatabase(array $options)
{
if (!isset($options['dbname'])) {
throw new \Espo\Core\Exceptions\Error('Option "dbname" is not found.');
}
$dbname = $options['dbname'];
unset($options['dbname']);
$pdo = static::createPdoConnection($options);
$pdo->query("CREATE DATABASE IF NOT EXISTS `". $dbname ."`");
}
public static function dropTables(array $options)
{
$pdo = static::createPdoConnection($options);
@@ -145,4 +158,4 @@ class Utils
return $dbh;
}
}
}