mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merged revisions 51150-51151 via svnmerge from
svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk ........ r51150 | sminnee | 2008-03-17 15:04:58 +1300 (Mon, 17 Mar 2008) | 1 line API CHANGE Allow for tests that don't use the database - don't define a static SapphireTest:: ........ r51151 | sminnee | 2008-03-17 15:09:32 +1300 (Mon, 17 Mar 2008) | 1 line Fixed typo in r51150 ........ git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.2.2@51438 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
6dac7dfee2
commit
12475f1b31
@ -55,29 +55,34 @@ require_once 'PHPUnit/Framework.php';
|
|||||||
* @subpackage testing
|
* @subpackage testing
|
||||||
*/
|
*/
|
||||||
class SapphireTest extends PHPUnit_Framework_TestCase {
|
class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||||
|
static $fixture_file = null;
|
||||||
|
|
||||||
function setUp() {
|
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);
|
$className = get_class($this);
|
||||||
$fixtureFile = eval("return {$className}::\$fixture_file;");
|
$fixtureFile = eval("return {$className}::\$fixture_file;");
|
||||||
$this->loadFixture($fixtureFile);
|
|
||||||
|
if($fixtureFile) {
|
||||||
|
// 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() {
|
function tearDown() {
|
||||||
// Delete our temporary database
|
// Delete our temporary database
|
||||||
$dbConn = DB::getConn();
|
$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";
|
// echo "Deleted temp database " . $dbConn->currentDatabase() . "\n";
|
||||||
$dbConn->dropDatabase();
|
$dbConn->dropDatabase();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user