Integration tests: create database if not exists
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user