From d71167fa606a7b642879580cc8e47e91a9e65f04 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Mon, 10 Jan 2011 18:34:59 +0000 Subject: [PATCH] Move table prefixes to constants, add doc to addDBData() --- tests/phpunit/MediaWikiTestCase.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 7ace401f1d..d15117886e 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -9,6 +9,12 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected $dbClone; protected $oldTablePrefix; protected $useTemporaryTables = true; + + /** + * Table name prefixes. Oracle likes it shorter. + */ + const DB_PREFIX = 'unittest_'; + const ORA_DB_PREFIX = 'ut_'; protected $supportedDBs = array( 'mysql', @@ -66,7 +72,11 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $rc = new ReflectionClass( $this ); return strpos( $rc->getDocComment(), '@group Database' ) !== false; } - + + /** + * Stub. If a test needs to add additional data to the database, it should + * implement this method and do so + */ function addDBData() {} private function addCoreDBData() { @@ -98,13 +108,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $dbType = $this->db->getType(); - if ( $wgDBprefix === 'unittest_' || ( $dbType == 'oracle' && $wgDBprefix === 'ut_' ) ) { + if ( $wgDBprefix === self::DB_PREFIX || ( $dbType == 'oracle' && $wgDBprefix === self::ORA_DB_PREFIX ) ) { throw new MWException( 'Cannot run unit tests, the database prefix is already "unittest_"' ); } $tables = $this->listTables(); - $prefix = $dbType != 'oracle' ? 'unittest_' : 'ut_'; + $prefix = $dbType != 'oracle' ? self::DB_PREFIX : self::ORA_DB_PREFIX; $this->dbClone = new CloneDatabase( $this->db, $tables, $prefix ); $this->dbClone->useTemporaryTables( false ); //reported problems with temp tables, disabling until fixed @@ -137,10 +147,10 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } if( $this->db->getType() == 'oracle' ) { - $tables = $this->db->listTables( 'ut_', __METHOD__ ); + $tables = $this->db->listTables( self::ORA_DB_PREFIX, __METHOD__ ); } else { - $tables = $this->db->listTables( 'unittest_', __METHOD__ ); + $tables = $this->db->listTables( self::DB_PREFIX, __METHOD__ ); } foreach ( $tables as $table ) { -- 2.20.1