mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE Allow for tests that don't use the database - don't define a static SapphireTest::
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@51143 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
0d49845a73
commit
20e2391224
@ -55,29 +55,34 @@ require_once 'PHPUnit/Framework.php';
|
||||
* @subpackage testing
|
||||
*/
|
||||
class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
static $fixture_file = null;
|
||||
|
||||
function setUp() {
|
||||
|
||||
// Create a temporary database
|
||||
$dbConn = DB::getConn();
|
||||
$dbname = 'tmpdb' . rand(1000000,9999999);
|
||||
while(!$dbname || $dbConn->databaseExists($dbname)) {
|
||||
$dbname = 'tmpdb' . rand(1000000,9999999);
|
||||
}
|
||||
$dbConn->selectDatabase($dbname);
|
||||
|
||||
// This code is a bit misplaced; we want some way of the whole session being reinitialised...
|
||||
Versioned::reading_stage(null);
|
||||
|
||||
$dbConn->createDatabase();
|
||||
singleton('DataObject')->flushCache();
|
||||
|
||||
$dbadmin = new DatabaseAdmin();
|
||||
$dbadmin->doBuild(true, false);
|
||||
|
||||
// Load the fixture into the database
|
||||
$className = get_class($this);
|
||||
$fixtureFile = eval("return {$className}::\$fixture_file;");
|
||||
$this->loadFixture($fixtureFile);
|
||||
|
||||
if($fixureFile) {
|
||||
// Create a temporary database
|
||||
$dbConn = DB::getConn();
|
||||
$dbname = 'tmpdb' . rand(1000000,9999999);
|
||||
while(!$dbname || $dbConn->databaseExists($dbname)) {
|
||||
$dbname = 'tmpdb' . rand(1000000,9999999);
|
||||
}
|
||||
$dbConn->selectDatabase($dbname);
|
||||
|
||||
// This code is a bit misplaced; we want some way of the whole session being reinitialised...
|
||||
Versioned::reading_stage(null);
|
||||
|
||||
$dbConn->createDatabase();
|
||||
singleton('DataObject')->flushCache();
|
||||
|
||||
$dbadmin = new DatabaseAdmin();
|
||||
$dbadmin->doBuild(true, false);
|
||||
|
||||
// Load the fixture into the database
|
||||
$className = get_class($this);
|
||||
$this->loadFixture($fixtureFile);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,7 +171,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
function tearDown() {
|
||||
// Delete our temporary database
|
||||
$dbConn = DB::getConn();
|
||||
if(substr($dbConn->currentDatabase(),0,5) == 'tmpdb') {
|
||||
if($dbConn && substr($dbConn->currentDatabase(),0,5) == 'tmpdb') {
|
||||
// echo "Deleted temp database " . $dbConn->currentDatabase() . "\n";
|
||||
$dbConn->dropDatabase();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user