mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT #5442 SapphireTest now creates a "tmpdb" database name with a prefix, changed by defining SS_DATABASE_PREFIX. Defaults to "SS_" to namespace SilverStripe temporary database names
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@114819 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
441bf4d910
commit
ec2ce32245
@ -145,10 +145,11 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$className = get_class($this);
|
||||
$fixtureFile = eval("return {$className}::\$fixture_file;");
|
||||
|
||||
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'SS_';
|
||||
|
||||
// Set up fixture
|
||||
if($fixtureFile || $this->usesDatabase || !self::using_temp_db()) {
|
||||
if(substr(DB::getConn()->currentDatabase(),0,5) != 'tmpdb') {
|
||||
if(substr(DB::getConn()->currentDatabase(), 0, strlen($prefix) + 5) != sprintf('%stmpdb', $prefix)) {
|
||||
//echo "Re-creating temp database... ";
|
||||
self::create_temp_db();
|
||||
//echo "done.\n";
|
||||
@ -608,7 +609,8 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
*/
|
||||
static function using_temp_db() {
|
||||
$dbConn = DB::getConn();
|
||||
return $dbConn && (substr($dbConn->currentDatabase(),0,5) == 'tmpdb');
|
||||
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'SS_';
|
||||
return $dbConn && (substr($dbConn->currentDatabase(), 0, strlen($prefix) + 5) == sprintf('%stmpdb', $prefix));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -659,9 +661,10 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
// Create a temporary database
|
||||
$dbConn = DB::getConn();
|
||||
$dbname = 'tmpdb' . rand(1000000,9999999);
|
||||
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'SS_';
|
||||
$dbname = sprintf('%stmpdb', $prefix) . rand(1000000,9999999);
|
||||
while(!$dbname || $dbConn->databaseExists($dbname)) {
|
||||
$dbname = 'tmpdb' . rand(1000000,9999999);
|
||||
$dbname = sprintf('%stmpdb', $prefix) . rand(1000000,9999999);
|
||||
}
|
||||
|
||||
$dbConn->selectDatabase($dbname);
|
||||
@ -677,8 +680,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
|
||||
static function delete_all_temp_dbs() {
|
||||
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'SS_';
|
||||
foreach(DB::getConn()->allDatabaseNames() as $dbName) {
|
||||
if(preg_match('/^tmpdb[0-9]+$/', $dbName)) {
|
||||
if(preg_match(sprintf('/^%stmpdb[0-9]+$/', $prefix), $dbName)) {
|
||||
DB::getConn()->dropDatabaseByName($dbName);
|
||||
if(Director::is_cli()) {
|
||||
echo "Dropped database \"$dbName\"" . PHP_EOL;
|
||||
|
Loading…
Reference in New Issue
Block a user