r73921 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73920‎ | r73921 | r73922 >
Date:18:13, 28 September 2010
Author:demon
Status:ok (Comments)
Tags:
Comment:
Unify setUp/tearDown in ApiSetup, rather than duplicating in ApiWatchTest. Also fix some errors with not passing an array reference that were being suppressed (but silently work, yay PHP)
Modified paths:
  • /trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiSetup.php
@@ -6,11 +6,11 @@
77 protected static $user;
88 protected static $apiUrl;
99
10 - function setup() {
 10+ function setUp() {
1111 global $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
1212 $wgScriptExtension, $wgMemc, $wgRequest;
1313
14 - self::$apiUrl = $wgServer . $wgScriptPath . "/api" . $wgScriptExtension;
 14+ self::$apiUrl = $wgServer . wfScript( 'api' );
1515
1616 $wgMemc = new FakeMemCachedClient;
1717 $wgContLang = Language::factory( 'en' );
@@ -36,4 +36,9 @@
3737
3838 $GLOBALS['wgUser'] = self::$user;
3939 }
 40+
 41+ function tearDown() {
 42+ global $wgMemc;
 43+ $wgMemc = null;
 44+ }
4045 }
Index: trunk/phase3/maintenance/tests/phpunit/includes/api/ApiWatchTest.php
@@ -5,21 +5,9 @@
66 class ApiWatchTest extends ApiTestSetup {
77
88 function setUp() {
9 - ini_set( 'log_errors', 1 );
10 - ini_set( 'error_reporting', 1 );
11 - ini_set( 'display_errors', 1 );
12 -
13 - global $wgMemc;
14 - $wgMemc = new FakeMemCachedClient;
 9+ parent::setUp();
1510 }
1611
17 - function tearDown() {
18 - global $wgMemc;
19 -
20 - $wgMemc = null;
21 - }
22 -
23 -
2412 function doApiRequest( $params, $data = null ) {
2513 $_SESSION = isset( $data[2] ) ? $data[2] : array();
2614
@@ -38,7 +26,7 @@
3927 $data = $this->doApiRequest( array(
4028 'action' => 'login',
4129 'lgname' => self::$userName,
42 - 'lgpassword' => self::$passWord ), $data );
 30+ 'lgpassword' => self::$passWord ) );
4331
4432 $this->assertArrayHasKey( "login", $data[0] );
4533 $this->assertArrayHasKey( "result", $data[0]['login'] );
@@ -65,11 +53,12 @@
6654 'action' => 'query',
6755 'titles' => 'Main Page',
6856 'intoken' => 'edit|delete|protect|move|block|unblock',
69 - 'prop' => 'info' ), $data );
 57+ 'prop' => 'info' ) );
7058
7159 $this->assertArrayHasKey( 'query', $data[0] );
7260 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
73 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 61+ $keys = array_keys( $data[0]['query']['pages'] );
 62+ $key = array_pop( $keys );
7463
7564 $this->assertArrayHasKey( $key, $data[0]['query']['pages'] );
7665 $this->assertArrayHasKey( 'edittoken', $data[0]['query']['pages'][$key] );
@@ -86,7 +75,8 @@
8776 * @depends testGetToken
8877 */
8978 function testWatchEdit( $data ) {
90 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 79+ $keys = array_keys( $data[0]['query']['pages'] );
 80+ $key = array_pop( $keys );
9181 $pageinfo = $data[0]['query']['pages'][$key];
9282
9383 $data = $this->doApiRequest( array(
@@ -135,7 +125,8 @@
136126 * @depends testGetToken
137127 */
138128 function testWatchProtect( $data ) {
139 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 129+ $keys = array_keys( $data[0]['query']['pages'] );
 130+ $key = array_pop( $keys );
140131 $pageinfo = $data[0]['query']['pages'][$key];
141132
142133 $data = $this->doApiRequest( array(
@@ -163,7 +154,8 @@
164155
165156 $this->assertArrayHasKey( 'query', $data[0] );
166157 $this->assertArrayHasKey( 'pages', $data[0]['query'] );
167 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 158+ $keys = array_keys( $data[0]['query']['pages'] );
 159+ $key = array_pop( $keys );
168160
169161 $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] );
170162 $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] );
@@ -177,7 +169,8 @@
178170 * @depends testGetRollbackToken
179171 */
180172 function testWatchRollback( $data ) {
181 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 173+ $keys = array_keys( $data[0]['query']['pages'] );
 174+ $key = array_pop( $keys );
182175 $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0];
183176
184177 $data = $this->doApiRequest( array(
@@ -195,7 +188,8 @@
196189 * @depends testGetToken
197190 */
198191 function testWatchDelete( $data ) {
199 - $key = array_pop( array_keys( $data[0]['query']['pages'] ) );
 192+ $keys = array_keys( $data[0]['query']['pages'] );
 193+ $key = array_pop( $keys );
200194 $pageinfo = $data[0]['query']['pages'][$key];
201195
202196 $data = $this->doApiRequest( array(

Comments

#Comment by Catrope (talk | contribs)   16:04, 12 December 2010
 	function setUp() {
-		ini_set( 'log_errors', 1 );
-		ini_set( 'error_reporting', 1 );
-		ini_set( 'display_errors', 1 );
-
-		global $wgMemc;
-		$wgMemc = new FakeMemCachedClient;
+		parent::setUp();
 	}

Just remove the subclass's implementation completely then.

Status & tagging log