Skip to content

Instantly share code, notes, and snippets.

@sminnee
Created February 9, 2010 05:46
Show Gist options
  • Select an option

  • Save sminnee/298949 to your computer and use it in GitHub Desktop.

Select an option

Save sminnee/298949 to your computer and use it in GitHub Desktop.
Index: sapphire/dev/TestRunner.php
===================================================================
--- sapphire/dev/TestRunner.php (revision 98430)
+++ sapphire/dev/TestRunner.php (working copy)
@@ -206,6 +206,18 @@
* @param boolean $coverage
*/
function runTests($classList, $coverage = false) {
+ if(!empty($_GET['testdb'])) {
+ if(class_exists($_GET['testdb']) && is_subclass_of($_GET['testdb'], 'SS_Database')) {
+ $dbClass = $_GET['testdb'];
+ DB::setConn(new $dbClass(array(
+ 'memory' => true
+ )), 'test');
+
+ } else {
+ throw new SS_HTTPResponse_Exception("Bad database class '{$_GET['testdb']}'", 400);
+ }
+ }
+
$startTime = microtime(true);
// XDEBUG seem to cause problems with test execution :-(
Index: sapphire/dev/SapphireTest.php
===================================================================
--- sapphire/dev/SapphireTest.php (revision 98430)
+++ sapphire/dev/SapphireTest.php (working copy)
@@ -578,8 +578,11 @@
* @todo Make this db agnostic
*/
static function create_temp_db() {
- // Create a temporary database
- $dbConn = DB::getConn();
+ // Switch the 'test' db conn if it's available
+ $dbConn = DB::getConn('test');
+ if($dbConn) DB::setConn($dbConn);
+ else $dbConn = DB::getConn();
+
$dbname = 'tmpdb' . rand(1000000,9999999);
while(!$dbname || $dbConn->databaseExists($dbname)) {
$dbname = 'tmpdb' . rand(1000000,9999999);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment