Permalink
Browse files

MINOR Make test database name all lowercase in case some databases li…

…ke PostgreSQL have issues trying to detect temp database in use

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@115251 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 6db82a8 commit b3bb0a721aeb63432b14427dfea1ac9f714a1e89 @halkyon halkyon committed Dec 21, 2010
Showing with 8 additions and 14 deletions.
  1. +8 −14 dev/SapphireTest.php
View
@@ -145,11 +145,11 @@ function setUp() {
$className = get_class($this);
$fixtureFile = eval("return {$className}::\$fixture_file;");
- $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'SS_';
+ $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, strlen($prefix) + 5) != sprintf('%stmpdb', $prefix)) {
+ if(substr(DB::getConn()->currentDatabase(), 0, strlen($prefix) + 5) != strtolower(sprintf('%stmpdb', $prefix))) {
//echo "Re-creating temp database... ";
self::create_temp_db();
//echo "done.\n";
@@ -609,13 +609,10 @@ private function DOSSummaryForMatch($dataObjectSet, $match) {
*/
static function using_temp_db() {
$dbConn = DB::getConn();
- $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'SS_';
- return $dbConn && (substr($dbConn->currentDatabase(), 0, strlen($prefix) + 5) == sprintf('%stmpdb', $prefix));
+ $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
+ return $dbConn && (substr($dbConn->currentDatabase(), 0, strlen($prefix) + 5) == strtolower(sprintf('%stmpdb', $prefix)));
}
- /**
- * @todo Make this db agnostic
- */
static function kill_temp_db() {
// Delete our temporary database
if(self::using_temp_db()) {
@@ -652,19 +649,16 @@ static function empty_temp_db() {
}
}
- /**
- * @todo Make this db agnostic
- */
static function create_temp_db() {
// Disable PHPUnit error handling
restore_error_handler();
// Create a temporary database
$dbConn = DB::getConn();
- $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'SS_';
- $dbname = sprintf('%stmpdb', $prefix) . rand(1000000,9999999);
+ $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
+ $dbname = strtolower(sprintf('%stmpdb', $prefix)) . rand(1000000,9999999);
while(!$dbname || $dbConn->databaseExists($dbname)) {
- $dbname = sprintf('%stmpdb', $prefix) . rand(1000000,9999999);
+ $dbname = strtolower(sprintf('%stmpdb', $prefix)) . rand(1000000,9999999);
}
$dbConn->selectDatabase($dbname);
@@ -680,7 +674,7 @@ static function create_temp_db() {
}
static function delete_all_temp_dbs() {
- $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'SS_';
+ $prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
foreach(DB::getConn()->allDatabaseNames() as $dbName) {
if(preg_match(sprintf('/^%stmpdb[0-9]+$/', $prefix), $dbName)) {
DB::getConn()->dropDatabaseByName($dbName);

0 comments on commit b3bb0a7

Please sign in to comment.