mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: Added dev/tests/cleanupdb action to remove test databases
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@72463 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ca5825e52c
commit
a581e748d9
@ -142,7 +142,15 @@ class MySQLDatabase extends Database {
|
||||
* Use with caution.
|
||||
*/
|
||||
public function dropDatabase() {
|
||||
$this->query("DROP DATABASE $this->database");
|
||||
$this->dropDatabaseByName($this->database);
|
||||
}
|
||||
|
||||
/**
|
||||
* Drop the database that this object is currently connected to.
|
||||
* Use with caution.
|
||||
*/
|
||||
public function dropDatabaseByName($dbName) {
|
||||
$this->query("DROP DATABASE \"$dbName\"");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,6 +179,13 @@ class MySQLDatabase extends Database {
|
||||
$SQL_name = Convert::raw2sql($name);
|
||||
return $this->query("SHOW DATABASES LIKE '$SQL_name'")->value() ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a column
|
||||
*/
|
||||
public function allDatabaseNames() {
|
||||
return $this->query("SHOW DATABASES")->column();
|
||||
}
|
||||
|
||||
public function createTable($tableName, $fields = null, $indexes = null) {
|
||||
$fieldSchemas = $indexSchemas = "";
|
||||
|
@ -240,6 +240,16 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
return $dbname;
|
||||
}
|
||||
|
||||
static function delete_all_temp_dbs() {
|
||||
foreach(DB::getConn()->allDatabaseNames() as $dbName) {
|
||||
if(preg_match('/^tmpdb[0-9]+$/', $dbName)) {
|
||||
DB::getConn()->dropDatabaseByName($dbName);
|
||||
echo "<li>Dropped databse \"$dbName\"\n";
|
||||
flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -36,6 +36,7 @@ class TestRunner extends Controller {
|
||||
'coverage' => 'coverage',
|
||||
'startsession' => 'startsession',
|
||||
'endsession' => 'endsession',
|
||||
'cleanupdb' => 'cleanupdb',
|
||||
'$TestCase' => 'only',
|
||||
);
|
||||
|
||||
@ -116,6 +117,10 @@ class TestRunner extends Controller {
|
||||
echo "Please install PHPUnit using pear";
|
||||
}
|
||||
}
|
||||
|
||||
function cleanupdb() {
|
||||
SapphireTest::delete_all_temp_dbs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Run only a single test class
|
||||
|
Loading…
Reference in New Issue
Block a user