http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88755
Revision: 88755
Author: demon
Date: 2011-05-24 21:22:36 +0000 (Tue, 24 May 2011)
Log Message:
-----------
Fixup phpunit tests so we don't drop/create tables on EVERY SINGLE TEST.
Now just create them on the first test that needsDB() and skip creation on the
rest.
Leaves you with a bunch of useless tables at the end of a run, but oh well at
least its faster :)
Modified Paths:
--------------
trunk/phase3/tests/phpunit/MediaWikiTestCase.php
Modified: trunk/phase3/tests/phpunit/MediaWikiTestCase.php
===================================================================
--- trunk/phase3/tests/phpunit/MediaWikiTestCase.php 2011-05-24 21:20:57 UTC
(rev 88754)
+++ trunk/phase3/tests/phpunit/MediaWikiTestCase.php 2011-05-24 21:22:36 UTC
(rev 88755)
@@ -4,11 +4,14 @@
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.
@@ -45,16 +48,17 @@
$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 );
}
@@ -109,31 +113,34 @@
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() {
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs