public $suite;
public $regex = '';
public $runDisabled = false;
-
+
+ /**
+ * @var DatabaseBase
+ */
protected $db;
- protected $dbClone;
protected $oldTablePrefix;
protected $useTemporaryTables = true;
+ private static $dbSetup = false;
/**
* Table name prefixes. Oracle likes it shorter.
$this->checkDbIsSupported();
$this->oldTablePrefix = $wgDBprefix;
-
- $this->destroyDB();
-
- $this->initDB();
+
+ if( !self::$dbSetup ) {
+ $this->initDB();
+ self::$dbSetup = true;
+ }
+
+ $this->resetDB();
$this->addCoreDBData();
$this->addDBData();
parent::run( $result );
-
- $this->destroyDB();
} else {
parent::run( $result );
}
private function initDB() {
global $wgDBprefix;
-
- $dbType = $this->db->getType();
-
if ( $wgDBprefix === $this->dbPrefix() ) {
throw new MWException( 'Cannot run unit tests, the database prefix is already "unittest_"' );
}
- $tables = $this->listTables();
-
- $this->dbClone = new CloneDatabase( $this->db, $tables, $this->dbPrefix() );
- $this->dbClone->useTemporaryTables( $this->useTemporaryTables );
- $this->dbClone->cloneTableStructure();
-
- if ( $dbType == 'oracle' )
- $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
+ $dbClone = new CloneDatabase( $this->db, $this->listTables(), $this->dbPrefix() );
+ $dbClone->useTemporaryTables( $this->useTemporaryTables );
+ $dbClone->cloneTableStructure();
+ }
- if ( $dbType == 'oracle' ) {
- # Insert 0 user to prevent FK violations
-
- # Anonymous user
- $this->db->insert( 'user', array(
- 'user_id' => 0,
- 'user_name' => 'Anonymous' ) );
+ /**
+ * Empty all tables so they can be repopulated for tests
+ */
+ private function resetDB() {
+ if( $this->db ) {
+ foreach( $this->listTables() as $tbl ) {
+ $this->db->delete( $tbl, '*', __METHOD__ );
+ }
+
+ if ( $this->db->getType() == 'oracle' ) {
+ $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
+
+ # Insert 0 user to prevent FK violations
+ # Anonymous user
+ $this->db->insert( 'user', array(
+ 'user_id' => 0,
+ 'user_name' => 'Anonymous' ) );
+ }
}
-
}
protected function destroyDB() {