r92239 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r92238‎ | r92239 | r92240 >
Date:12:13, 15 July 2011
Author:hashar
Status:ok (Comments)
Tags:
Comment:
MFT PHPUnit testing related revisions:

r87839 : PHPPunit 3.5 at least
r88769 : Tests use MediaWikiTestCase
r88755 : stop drop/create tables on every single test
\ r89301 : additional test cleanup
r89182 : mark ApiWatchTest tests as broken

This commit let us enable Database group on the continuous integration
system which will suddenly expose all tests that requires an access tothe database.

Thus, this commit *BREAKS the REL1_18 unit tests* since the huge block rewrite
is still broken. Fixing it requires backporting a lot of 'fixme' revisions
form trunk.


Test plan:

$ time make destructive
php phpunit.php -c REL1.18/tests/phpunit/suite.xml PHPUnit 3.5.14 by Sebastian Bergmann. <snip output of 1618 tests>
FAILURES! Tests: 1528, Assertions: 74953, Failures: 1, Errors: 2, Incomplete: 41, Skipped
: 9.
real 3m2.012s
user 2m50.534s
sys 0m7.273s
$

Lets fix the blocking system :-)
Modified paths:
  • /branches/REL1_18/phase3/tests/phpunit (modified) (history)
  • /branches/REL1_18/phase3/tests/phpunit/MediaWikiTestCase.php (modified) (history)
  • /branches/REL1_18/phase3/tests/phpunit/includes/MWNamespaceTest.php (modified) (history)
  • /branches/REL1_18/phase3/tests/phpunit/includes/XmlJsTest.php (modified) (history)
  • /branches/REL1_18/phase3/tests/phpunit/includes/api/ApiBlockTest.php (modified) (history)
  • /branches/REL1_18/phase3/tests/phpunit/includes/api/ApiWatchTest.php (modified) (history)
  • /branches/REL1_18/phase3/tests/phpunit/includes/parser/MagicVariableTest.php (modified) (history)
  • /branches/REL1_18/phase3/tests/phpunit/phpunit.php (modified) (history)
  • /branches/REL1_18/phase3/tests/phpunit/suites/ExtensionsTestSuite.php (modified) (history)

Diff [purge]

Index: branches/REL1_18/phase3/tests/phpunit/MediaWikiTestCase.php
@@ -4,11 +4,14 @@
55 public $suite;
66 public $regex = '';
77 public $runDisabled = false;
8 -
 8+
 9+ /**
 10+ * @var DatabaseBase
 11+ */
912 protected $db;
10 - protected $dbClone;
1113 protected $oldTablePrefix;
1214 protected $useTemporaryTables = true;
 15+ private static $dbSetup = false;
1316
1417 /**
1518 * Table name prefixes. Oracle likes it shorter.
@@ -43,28 +46,24 @@
4447 $this->db = wfGetDB( DB_MASTER );
4548
4649 $this->checkDbIsSupported();
47 -
 50+
4851 $this->oldTablePrefix = $wgDBprefix;
49 -
50 - $this->destroyDB();
51 -
52 - $this->initDB();
 52+
 53+ if( !self::$dbSetup ) {
 54+ $this->initDB();
 55+ self::$dbSetup = true;
 56+ }
 57+
5358 $this->addCoreDBData();
5459 $this->addDBData();
5560
5661 parent::run( $result );
57 -
58 - $this->destroyDB();
 62+
 63+ $this->resetDB();
5964 } else {
6065 parent::run( $result );
6166 }
6267 }
63 -
64 - function __destruct() {
65 - if( $this->needsDB() ) {
66 - $this->destroyDB();
67 - }
68 - }
6968
7069 function dbPrefix() {
7170 return $this->db->getType() == 'oracle' ? self::ORA_DB_PREFIX : self::DB_PREFIX;
@@ -109,61 +108,59 @@
110109
111110 private function initDB() {
112111 global $wgDBprefix;
113 -
114 - $dbType = $this->db->getType();
115 -
116112 if ( $wgDBprefix === $this->dbPrefix() ) {
117113 throw new MWException( 'Cannot run unit tests, the database prefix is already "unittest_"' );
118114 }
119115
120 - $tables = $this->listTables();
121 -
122 - $this->dbClone = new CloneDatabase( $this->db, $tables, $this->dbPrefix() );
123 - $this->dbClone->useTemporaryTables( $this->useTemporaryTables );
124 - $this->dbClone->cloneTableStructure();
125 -
126 - if ( $dbType == 'oracle' )
 116+ $dbClone = new CloneDatabase( $this->db, $this->listTables(), $this->dbPrefix() );
 117+ $dbClone->useTemporaryTables( $this->useTemporaryTables );
 118+ $dbClone->cloneTableStructure();
 119+
 120+ if ( $this->db->getType() == 'oracle' ) {
127121 $this->db->query( 'BEGIN FILL_WIKI_INFO; END;' );
128122
129 - if ( $dbType == 'oracle' ) {
130123 # Insert 0 user to prevent FK violations
131 -
132124 # Anonymous user
133125 $this->db->insert( 'user', array(
134126 'user_id' => 0,
135127 'user_name' => 'Anonymous' ) );
136128 }
137 -
138129 }
139 -
 130+
 131+ /**
 132+ * Empty all tables so they can be repopulated for tests
 133+ */
 134+ private function resetDB() {
 135+ if( $this->db ) {
 136+ foreach( $this->listTables() as $tbl ) {
 137+ if( $tbl == 'interwiki' || $tbl == 'user' ) continue;
 138+ $this->db->delete( $tbl, '*', __METHOD__ );
 139+ }
 140+ }
 141+ }
 142+
140143 protected function destroyDB() {
141 -
142 - if ( $this->useTemporaryTables ) {
 144+ if ( $this->useTemporaryTables || is_null( $this->db ) ) {
143145 # Don't need to do anything
144 - //return;
145 - //Temporary tables seem to be broken ATM, delete anyway
146 - }
147 -
148 - if( is_null( $this->db ) ) {
149146 return;
150147 }
151 -
 148+
152149 $tables = $this->db->listTables( $this->dbPrefix(), __METHOD__ );
153 -
 150+
154151 foreach ( $tables as $table ) {
155152 try {
156153 $sql = $this->db->getType() == 'oracle' ? "DROP TABLE $table CASCADE CONSTRAINTS PURGE" : "DROP TABLE `$table`";
157154 $this->db->query( $sql, __METHOD__ );
158 - } catch( Exception $e ) {
159 - }
 155+ } catch( MWException $mwe ) {}
160156 }
161 -
 157+
162158 if ( $this->db->getType() == 'oracle' )
163159 $this->db->query( 'BEGIN FILL_WIKI_INFO; END;', __METHOD__ );
164 -
 160+
165161 CloneDatabase::changePrefix( $this->oldTablePrefix );
166162 }
167163
 164+
168165 function __call( $func, $args ) {
169166 static $compatibility = array(
170167 'assertInternalType' => 'assertType',
@@ -193,7 +190,7 @@
194191
195192 protected function listTables() {
196193 global $wgDBprefix;
197 -
 194+
198195 $tables = $this->db->listTables( $wgDBprefix, __METHOD__ );
199196 $tables = array_map( array( __CLASS__, 'unprefixTable' ), $tables );
200197
Property changes on: branches/REL1_18/phase3/tests/phpunit/MediaWikiTestCase.php
___________________________________________________________________
Added: svn:mergeinfo
201198 Merged /branches/REL1_17/phase3/tests/phpunit/MediaWikiTestCase.php:r81445,81448
202199 Merged /branches/sqlite/tests/phpunit/MediaWikiTestCase.php:r58211-58321
203200 Merged /trunk/phase3/tests/phpunit/MediaWikiTestCase.php:r87632,87636,87640,87644,88231-88232,88755,88769,89099,89108,89301,89479-89480,90602,90612,90618,90626,90630-90631,90637,90655,90657,90666,90812
204201 Merged /branches/new-installer/phase3/tests/phpunit/MediaWikiTestCase.php:r43664-66004
205202 Merged /branches/REL1_15/phase3/tests/phpunit/MediaWikiTestCase.php:r51646
Index: branches/REL1_18/phase3/tests/phpunit/includes/XmlJsTest.php
@@ -1,5 +1,5 @@
22 <?php
3 -class XmlJs extends PHPUnit_Framework_TestCase {
 3+class XmlJs extends MediaWikiTestCase {
44 public function testConstruction() {
55 $obj = new XmlJsCode( null );
66 $this->assertNull( $obj->value );
Index: branches/REL1_18/phase3/tests/phpunit/includes/MWNamespaceTest.php
@@ -10,7 +10,7 @@
1111 * Generated by PHPUnit on 2011-02-20 at 21:01:55.
1212 *
1313 */
14 -class MWNamespaceTest extends PHPUnit_Framework_TestCase {
 14+class MWNamespaceTest extends MediaWikiTestCase {
1515 /**
1616 * @var MWNamespace
1717 */
Index: branches/REL1_18/phase3/tests/phpunit/includes/parser/MagicVariableTest.php
@@ -12,7 +12,7 @@
1313 */
1414
1515 /** */
16 -class MagicVariableTest extends PHPUnit_Framework_TestCase {
 16+class MagicVariableTest extends MediaWikiTestCase {
1717 /** Will contains a parser object*/
1818 private $testParser = null;
1919
Index: branches/REL1_18/phase3/tests/phpunit/includes/api/ApiWatchTest.php
@@ -5,6 +5,7 @@
66 /**
77 * @group Database
88 * @group Destructive
 9+ * @todo This test suite is severly broken and need a full review
910 */
1011 class ApiWatchTest extends ApiTestSetup {
1112
@@ -17,11 +18,13 @@
1819 return $this->getTokenList( $this->sysopUser );
1920 }
2021
 22+ /**
 23+ * @group Broken
 24+ */
2125 function testWatchEdit() {
2226
2327 $data = $this->getTokens();
2428
25 - $this->markTestIncomplete( "Broken" );
2629 $keys = array_keys( $data[0]['query']['pages'] );
2730 $key = array_pop( $keys );
2831 $pageinfo = $data[0]['query']['pages'][$key];
@@ -68,12 +71,13 @@
6972 return $data;
7073 }
7174
72 -
 75+ /**
 76+ * @group Broken
 77+ */
7378 function testWatchProtect() {
7479
7580 $data = $this->getTokens();
7681
77 - $this->markTestIncomplete( "Broken" );
7882 $keys = array_keys( $data[0]['query']['pages'] );
7983 $key = array_pop( $keys );
8084 $pageinfo = $data[0]['query']['pages'][$key];
@@ -125,6 +129,7 @@
126130
127131 /**
128132 * @depends testGetRollbackToken
 133+ * @group Broken
129134 */
130135 function testWatchRollback( $data ) {
131136 $keys = array_keys( $data[0]['query']['pages'] );
@@ -142,7 +147,7 @@
143148 if( $ue->getCodeString() == 'onlyauthor' ) {
144149 $this->markTestIncomplete( "Only one author to 'UTPage', cannot test rollback" );
145150 } else {
146 - $this->fail( "Received error " . $ue->getCodeString() );
 151+ $this->fail( "Received error '" . $ue->getCodeString() . "'" );
147152 }
148153 }
149154
@@ -150,12 +155,13 @@
151156 $this->assertArrayHasKey( 'title', $data[0]['rollback'] );
152157 }
153158
154 -
 159+ /**
 160+ * @group Broken
 161+ */
155162 function testWatchDelete() {
156163
157164 $data = $this->getTokens();
158165
159 - $this->markTestIncomplete( "Broken" );
160166 $keys = array_keys( $data[0]['query']['pages'] );
161167 $key = array_pop( $keys );
162168 $pageinfo = $data[0]['query']['pages'][$key];
Property changes on: branches/REL1_18/phase3/tests/phpunit/includes/api/ApiWatchTest.php
___________________________________________________________________
Added: svn:mergeinfo
163169 Merged /branches/REL1_17/phase3/tests/phpunit/includes/api/ApiWatchTest.php:r81445,81448
164170 Merged /branches/sqlite/tests/phpunit/includes/api/ApiWatchTest.php:r58211-58321
165171 Merged /trunk/phase3/tests/phpunit/includes/api/ApiWatchTest.php:r87632,87636,87640,87644,88231-88232,88769,89099,89108,89182,89301,89479-89480,90602,90612,90618,90626,90630-90631,90637,90655,90657,90666,90812
166172 Merged /branches/new-installer/phase3/tests/phpunit/includes/api/ApiWatchTest.php:r43664-66004
167173 Merged /branches/REL1_15/phase3/tests/phpunit/includes/api/ApiWatchTest.php:r51646
Index: branches/REL1_18/phase3/tests/phpunit/includes/api/ApiBlockTest.php
@@ -27,9 +27,7 @@
2828 $user->saveSettings();
2929 }
3030 }
31 -
3231
33 -
3432 function testMakeNormalBlock() {
3533
3634 $data = $this->getTokens();
Index: branches/REL1_18/phase3/tests/phpunit/suites/ExtensionsTestSuite.php
@@ -26,7 +26,7 @@
2727 * Needed to avoid warnings like 'No tests found in class "ExtensionsTestSuite".'
2828 * when no extensions with tests are used.
2929 */
30 -class DummyExtensionsTest extends PHPUnit_Framework_TestCase {
 30+class DummyExtensionsTest extends MediaWikiTestCase {
3131 public function testNothing() {
3232
3333 }
Index: branches/REL1_18/phase3/tests/phpunit/phpunit.php
@@ -51,13 +51,10 @@
5252 }
5353
5454 require_once( 'PHPUnit/Runner/Version.php' );
55 -if( version_compare( PHPUnit_Runner_Version::id(), '3.5.0', '>=' ) ) {
56 - # PHPUnit 3.5.0 introduced a nice autoloader based on class name
57 - require_once( 'PHPUnit/Autoload.php' );
58 -} else {
59 - # Keep the old pre PHPUnit 3.5.0 behaviour for compatibility
60 - require_once( 'PHPUnit/TextUI/Command.php' );
 55+if( version_compare( PHPUnit_Runner_Version::id(), '3.5.0', '<' ) ) {
 56+ die( 'PHPUnit 3.5 or later required, you have ' . PHPUnit_Runner_Version::id() . ".\n" );
6157 }
 58+require_once( 'PHPUnit/Autoload.php' );
6259
6360 require_once( "$IP/tests/TestsAutoLoader.php" );
6461 MediaWikiPHPUnitCommand::main();
Property changes on: branches/REL1_18/phase3/tests/phpunit/phpunit.php
___________________________________________________________________
Added: svn:mergeinfo
6562 Merged /branches/new-installer/phase3/tests/phpunit/phpunit.php:r43664-66004
6663 Merged /branches/REL1_15/phase3/tests/phpunit/phpunit.php:r51646
6764 Merged /branches/REL1_17/phase3/tests/phpunit/phpunit.php:r81445,81448
6865 Merged /branches/sqlite/tests/phpunit/phpunit.php:r58211-58321
6966 Merged /trunk/phase3/tests/phpunit/phpunit.php:r87632,87636,87640,87644,87839,88231-88232,88769,89099,89108,89301,89479-89480,90602,90612,90618,90626,90630-90631,90637,90655,90657,90666,90812
Property changes on: branches/REL1_18/phase3/tests/phpunit
___________________________________________________________________
Modified: svn:mergeinfo
7067 Merged /trunk/phase3/tests/phpunit:r88769,89301

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r87839To prevent creepy errors like bug 28908, raised PHPUnit requirement to 3.5maxsem19:45, 10 May 2011
r88755Fixup phpunit tests so we don't drop/create tables on EVERY SINGLE TEST....demon21:22, 24 May 2011
r88769Extend MediaWikiTestCase in a few placesdemon00:30, 25 May 2011
r89182add broken test to broken group (not incomplete)...hashar18:58, 30 May 2011
r89301Test db cleanup...demon22:43, 1 June 2011

Comments

#Comment by Hashar (talk | contribs)   13:33, 15 July 2011

Status & tagging log