Index: trunk/phase3/tests/phpunit/MediaWikiTestCase.php |
— | — | @@ -13,6 +13,7 @@ |
14 | 14 | protected $useTemporaryTables = true; |
15 | 15 | protected $reuseDB = false; |
16 | 16 | private static $dbSetup = false; |
| 17 | + private static $tablesCloned = array(); |
17 | 18 | |
18 | 19 | /** |
19 | 20 | * Table name prefixes. Oracle likes it shorter. |
— | — | @@ -54,7 +55,7 @@ |
55 | 56 | $this->oldTablePrefix = $wgDBprefix; |
56 | 57 | |
57 | 58 | if( !self::$dbSetup ) { |
58 | | - $this->initDB(); |
| 59 | + self::$tablesCloned = $this->initDB(); |
59 | 60 | self::$dbSetup = true; |
60 | 61 | } |
61 | 62 | |
— | — | @@ -140,7 +141,8 @@ |
141 | 142 | throw new MWException( 'Cannot run unit tests, the database prefix is already "unittest_"' ); |
142 | 143 | } |
143 | 144 | |
144 | | - $dbClone = new CloneDatabase( $this->db, $this->listTables(), $this->dbPrefix() ); |
| 145 | + $tablesCloned = $this->listTables(); |
| 146 | + $dbClone = new CloneDatabase( $this->db, $tablesCloned, $this->dbPrefix() ); |
145 | 147 | $dbClone->useTemporaryTables( $this->useTemporaryTables ); |
146 | 148 | |
147 | 149 | if ( ( $this->db->getType() == 'oracle' || !$this->useTemporaryTables ) && $this->reuseDB ) { |
— | — | @@ -154,6 +156,8 @@ |
155 | 157 | if ( $this->db->getType() == 'oracle' ) { |
156 | 158 | $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' ); |
157 | 159 | } |
| 160 | + |
| 161 | + return $tablesCloned; |
158 | 162 | } |
159 | 163 | |
160 | 164 | /** |
— | — | @@ -166,44 +170,20 @@ |
167 | 171 | wfGetLB()->closeAll(); |
168 | 172 | $this->db = wfGetDB( DB_MASTER ); |
169 | 173 | } else { |
170 | | - foreach( $this->listTables() as $tbl ) { |
| 174 | + foreach( self::$tablesCloned as $tbl ) { |
171 | 175 | if( $tbl == 'interwiki') continue; |
172 | 176 | $this->db->query( 'TRUNCATE TABLE '.$this->db->tableName($tbl), __METHOD__ ); |
173 | 177 | } |
174 | 178 | } |
175 | 179 | } else { |
176 | | - foreach( $this->listTables() as $tbl ) { |
| 180 | + foreach( self::$tablesCloned as $tbl ) { |
177 | 181 | if( $tbl == 'interwiki' || $tbl == 'user' ) continue; |
178 | | - $this->db->delete( $tbl, '*', __METHOD__ ); |
| 182 | + $this->db->delete( $tbl, '*', __METHOD__ ); |
179 | 183 | } |
180 | 184 | } |
181 | 185 | } |
182 | 186 | } |
183 | 187 | |
184 | | - protected function destroyDB() { |
185 | | - if ( is_null( $this->db ) || |
186 | | - ( $this->useTemporaryTables && $this->db->getType() != 'oracle' ) || |
187 | | - ( $this->reuseDB ) ) { |
188 | | - # Don't need to do anything |
189 | | - return; |
190 | | - } |
191 | | - |
192 | | - $tables = $this->db->listTables( $this->dbPrefix(), __METHOD__ ); |
193 | | - |
194 | | - foreach ( $tables as $table ) { |
195 | | - try { |
196 | | - $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table CASCADE CONSTRAINTS PURGE" : "DROP TABLE `$table`"; |
197 | | - $this->db->query( $sql, __METHOD__ ); |
198 | | - } catch( MWException $mwe ) {} |
199 | | - } |
200 | | - |
201 | | - if ( $this->db->getType() == 'oracle' ) |
202 | | - $this->db->query( 'BEGIN FILL_WIKI_INFO; END;', __METHOD__ ); |
203 | | - |
204 | | - CloneDatabase::changePrefix( $this->oldTablePrefix ); |
205 | | - } |
206 | | - |
207 | | - |
208 | 188 | function __call( $func, $args ) { |
209 | 189 | static $compatibility = array( |
210 | 190 | 'assertInternalType' => 'assertType', |