From 028d2f7e8c6d76dc03c00a33ed9cbfd541ff66c7 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Tue, 28 Sep 2010 18:13:42 +0000 Subject: [PATCH] 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) --- .../tests/phpunit/includes/api/ApiSetup.php | 9 +++-- .../phpunit/includes/api/ApiWatchTest.php | 36 ++++++++----------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/maintenance/tests/phpunit/includes/api/ApiSetup.php b/maintenance/tests/phpunit/includes/api/ApiSetup.php index 51d2ff67b5..23014378d0 100644 --- a/maintenance/tests/phpunit/includes/api/ApiSetup.php +++ b/maintenance/tests/phpunit/includes/api/ApiSetup.php @@ -6,11 +6,11 @@ abstract class ApiTestSetup extends PHPUnit_Framework_TestCase { protected static $user; protected static $apiUrl; - function setup() { + function setUp() { global $wgServer, $wgContLang, $wgAuth, $wgScriptPath, $wgScriptExtension, $wgMemc, $wgRequest; - self::$apiUrl = $wgServer . $wgScriptPath . "/api" . $wgScriptExtension; + self::$apiUrl = $wgServer . wfScript( 'api' ); $wgMemc = new FakeMemCachedClient; $wgContLang = Language::factory( 'en' ); @@ -36,4 +36,9 @@ abstract class ApiTestSetup extends PHPUnit_Framework_TestCase { $GLOBALS['wgUser'] = self::$user; } + + function tearDown() { + global $wgMemc; + $wgMemc = null; + } } diff --git a/maintenance/tests/phpunit/includes/api/ApiWatchTest.php b/maintenance/tests/phpunit/includes/api/ApiWatchTest.php index 397046f6d2..ad6824e434 100644 --- a/maintenance/tests/phpunit/includes/api/ApiWatchTest.php +++ b/maintenance/tests/phpunit/includes/api/ApiWatchTest.php @@ -5,21 +5,9 @@ require_once dirname( __FILE__ ) . '/ApiSetup.php'; class ApiWatchTest extends ApiTestSetup { function setUp() { - ini_set( 'log_errors', 1 ); - ini_set( 'error_reporting', 1 ); - ini_set( 'display_errors', 1 ); - - global $wgMemc; - $wgMemc = new FakeMemCachedClient; + parent::setUp(); } - function tearDown() { - global $wgMemc; - - $wgMemc = null; - } - - function doApiRequest( $params, $data = null ) { $_SESSION = isset( $data[2] ) ? $data[2] : array(); @@ -38,7 +26,7 @@ class ApiWatchTest extends ApiTestSetup { $data = $this->doApiRequest( array( 'action' => 'login', 'lgname' => self::$userName, - 'lgpassword' => self::$passWord ), $data ); + 'lgpassword' => self::$passWord ) ); $this->assertArrayHasKey( "login", $data[0] ); $this->assertArrayHasKey( "result", $data[0]['login'] ); @@ -65,11 +53,12 @@ class ApiWatchTest extends ApiTestSetup { 'action' => 'query', 'titles' => 'Main Page', 'intoken' => 'edit|delete|protect|move|block|unblock', - 'prop' => 'info' ), $data ); + 'prop' => 'info' ) ); $this->assertArrayHasKey( 'query', $data[0] ); $this->assertArrayHasKey( 'pages', $data[0]['query'] ); - $key = array_pop( array_keys( $data[0]['query']['pages'] ) ); + $keys = array_keys( $data[0]['query']['pages'] ); + $key = array_pop( $keys ); $this->assertArrayHasKey( $key, $data[0]['query']['pages'] ); $this->assertArrayHasKey( 'edittoken', $data[0]['query']['pages'][$key] ); @@ -86,7 +75,8 @@ class ApiWatchTest extends ApiTestSetup { * @depends testGetToken */ function testWatchEdit( $data ) { - $key = array_pop( array_keys( $data[0]['query']['pages'] ) ); + $keys = array_keys( $data[0]['query']['pages'] ); + $key = array_pop( $keys ); $pageinfo = $data[0]['query']['pages'][$key]; $data = $this->doApiRequest( array( @@ -135,7 +125,8 @@ class ApiWatchTest extends ApiTestSetup { * @depends testGetToken */ function testWatchProtect( $data ) { - $key = array_pop( array_keys( $data[0]['query']['pages'] ) ); + $keys = array_keys( $data[0]['query']['pages'] ); + $key = array_pop( $keys ); $pageinfo = $data[0]['query']['pages'][$key]; $data = $this->doApiRequest( array( @@ -163,7 +154,8 @@ class ApiWatchTest extends ApiTestSetup { $this->assertArrayHasKey( 'query', $data[0] ); $this->assertArrayHasKey( 'pages', $data[0]['query'] ); - $key = array_pop( array_keys( $data[0]['query']['pages'] ) ); + $keys = array_keys( $data[0]['query']['pages'] ); + $key = array_pop( $keys ); $this->assertArrayHasKey( 'pageid', $data[0]['query']['pages'][$key] ); $this->assertArrayHasKey( 'revisions', $data[0]['query']['pages'][$key] ); @@ -177,7 +169,8 @@ class ApiWatchTest extends ApiTestSetup { * @depends testGetRollbackToken */ function testWatchRollback( $data ) { - $key = array_pop( array_keys( $data[0]['query']['pages'] ) ); + $keys = array_keys( $data[0]['query']['pages'] ); + $key = array_pop( $keys ); $pageinfo = $data[0]['query']['pages'][$key]['revisions'][0]; $data = $this->doApiRequest( array( @@ -195,7 +188,8 @@ class ApiWatchTest extends ApiTestSetup { * @depends testGetToken */ function testWatchDelete( $data ) { - $key = array_pop( array_keys( $data[0]['query']['pages'] ) ); + $keys = array_keys( $data[0]['query']['pages'] ); + $key = array_pop( $keys ); $pageinfo = $data[0]['query']['pages'][$key]; $data = $this->doApiRequest( array( -- 2.20.1