* Removed require/require_once from maintenance scripts where possible, replaced...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 25 Jun 2010 02:55:51 +0000 (02:55 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 25 Jun 2010 02:55:51 +0000 (02:55 +0000)
* Rearranged PHPUnit startup so that MediaWiki can be started from the file scope, as required by Setup.php and other core MediaWiki startup files. The custom entry point maintenance/tests/phpunit starts MediaWiki and then passes its arguments through to PHPUnit.
* Moved the parser test tag hooks into classes and moved their registration to parserTests.inc, to allow autoloading.
* Renamed ApiSetup to ApiTestSetup, MediaWiki_Setup to MediaWikiTestSetup, PTShell to ParserTestSuiteBackend.
* Moved command-line initialisation code from the file scope of parserTests.inc to parserTests.php to allow autoloading
* Rewrote the interface between PHPUnit and the parser tests. Removed all the hacks designed to make the rest of the PHPUnit tests work without proper teardown of the parser test environment. Moved the PHPUnit_Framework_TestSuite subclass to a file that's not scanned by PHPUnit, to avoid "no tests found" warnings".
* Removed the {{NUMBEROFARTICLES}} parser test, too hard to make it work consistently.

21 files changed:
includes/AutoLoader.php
maintenance/language/diffLanguage.php
maintenance/parserTests.inc
maintenance/parserTests.php
maintenance/parserTests.txt
maintenance/parserTestsParserHook.php
maintenance/parserTestsStaticParserHook.php
maintenance/tests/ApiSetup.php
maintenance/tests/ApiTest.php
maintenance/tests/ApiWatchTest.php
maintenance/tests/Makefile
maintenance/tests/MediaWikiParserTest.php
maintenance/tests/MediaWiki_Setup.php
maintenance/tests/ParserHelpers.php [new file with mode: 0644]
maintenance/tests/SearchDbTest.php
maintenance/tests/SearchEngineTest.php
maintenance/tests/UploadFromUrlTest.php
maintenance/tests/UploadFromUrlTestSuite.php
maintenance/tests/bootstrap.php
maintenance/tests/phpunit [new file with mode: 0755]
maintenance/tests/phpunit.xml

index 4732d77..186dc21 100644 (file)
@@ -636,13 +636,31 @@ $wgAutoloadLocalClasses = array(
        'FakeConverter' => 'languages/Language.php',
        'LanguageConverter' => 'languages/LanguageConverter.php',
 
-       # maintenance/language
+       # maintenance
+       'AnsiTermColorer' => 'maintenance/parserTests.inc',
+       'ApiTestSetup' => 'maintenance/tests/ApiSetup.php',
+       'DbTestPreviewer' => 'maintenance/parserTests.inc',
+       'DbTestRecorder' => 'maintenance/parserTests.inc',
+       'DeleteArchivedFilesImplementation' => 'maintenance/deleteArchivedFiles.inc',
+       'DeleteArchivedRevisionsImplementation' => 'maintenance/deleteArchivedRevisions.inc',
+       'DummyTermColorer' => 'maintenance/parserTests.inc',
+       'MediaWikiTestSetup' => 'maintenance/tests/MediaWiki_Setup.php',
+       'PHPUnitTestRecorder' => 'maintenance/tests/ParserHelpers.php',
+       'ParserTest' => 'maintenance/parserTests.inc',
+       'ParserTestParserHook' => 'maintenance/parserTestsParserHook.php',
+       'ParserTestStaticParserHook' => 'maintenance/parserTestsStaticParserHook.php',
+       'ParserTestSuiteBackend' => 'maintenance/tests/ParserHelpers.php',
+       'ParserUnitTest' => 'maintenance/tests/ParserHelpers.php',
+       'RemoteTestRecorder' => 'maintenance/parserTests.inc',
+       'SearchEngineTest' => 'maintenance/tests/SearchEngineTest.php',
+       'SevenZipStream' => 'maintenance/7zip.inc',
+       'TestFileIterator' => 'maintenance/parserTests.inc',
+       'TestRecorder' => 'maintenance/parserTests.inc',
+       'UploadFromUrlTest' => 'maintenance/tests/UploadFromUrlTest.php',
+       'csvStatsOutput' => 'maintenance/language/StatOutputs.php',
        'statsOutput' => 'maintenance/language/StatOutputs.php',
-       'wikiStatsOutput' => 'maintenance/language/StatOutputs.php',
        'textStatsOutput' => 'maintenance/language/StatOutputs.php',
-       'csvStatsOutput' => 'maintenance/language/StatOutputs.php',
-       'SevenZipStream' => 'maintenance/7zip.inc',
-
+       'wikiStatsOutput' => 'maintenance/language/StatOutputs.php',
 );
 
 class AutoLoader {
index 1260e5e..4ead2ce 100644 (file)
@@ -40,7 +40,6 @@
  */
 
 /** This script run from the commandline */
-require_once( dirname( __FILE__ ) . '/../parserTests.inc' );
 require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
 
 if ( isset( $options['help'] ) ) { usage(); wfDie(); }
index b76ee5e..18ffb34 100644 (file)
  * @ingroup Maintenance
  */
 
-/** */
-$options = array( 'quick', 'color', 'quiet', 'help', 'show-output', 'record', 'run-disabled' );
-$optionsWithArgs = array( 'regex', 'seed', 'setversion' );
-
-if ( !defined( "NO_COMMAND_LINE" ) ) {
-       require_once( dirname( __FILE__ ) . '/commandLine.inc' );
-}
-require_once( "$IP/maintenance/parserTestsParserHook.php" );
-require_once( "$IP/maintenance/parserTestsStaticParserHook.php" );
-require_once( "$IP/maintenance/parserTestsParserTime.php" );
-
 /**
  * @ingroup Maintenance
  */
@@ -114,17 +103,7 @@ class ParserTest {
                        $this->regex = '';
                }
 
-               if ( isset( $options['record'] ) ) {
-                       $this->recorder = new DbTestRecorder( $this );
-               } elseif ( isset( $options['compare'] ) ) {
-                       $this->recorder = new DbTestPreviewer( $this );
-               } elseif ( isset( $options['upload'] ) ) {
-                       $this->recorder = new RemoteTestRecorder( $this );
-               } elseif ( class_exists( 'PHPUnitTestRecorder' ) ) {
-                       $this->recorder = new PHPUnitTestRecorder( $this );
-               } else {
-                       $this->recorder = new TestRecorder( $this );
-               }
+               $this->setupRecorder();
                $this->keepUploads = isset( $options['keep-uploads'] );
 
                if ( isset( $options['seed'] ) ) {
@@ -137,6 +116,18 @@ class ParserTest {
                $this->functionHooks = array();
        }
 
+       public function setupRecorder() {
+               if ( isset( $options['record'] ) ) {
+                       $this->recorder = new DbTestRecorder( $this );
+               } elseif ( isset( $options['compare'] ) ) {
+                       $this->recorder = new DbTestPreviewer( $this );
+               } elseif ( isset( $options['upload'] ) ) {
+                       $this->recorder = new RemoteTestRecorder( $this );
+               } else {
+                       $this->recorder = new TestRecorder( $this );
+               }
+       }
+
        /**
         * Remove last character if it is a newline
         */
@@ -589,6 +580,11 @@ class ParserTest {
                $GLOBALS['wgMemc'] = new FakeMemCachedClient;
                $GLOBALS['wgOut'] = new OutputPage;
 
+               global $wgHooks;
+               $wgHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
+               $wgHooks['ParserTestParser'][] = 'ParserTestStaticParserHook::setup';
+               $wgHooks['ParserGetVariableValueTs'][] = 'ParserTest::getFakeTimestamp';
+
                MagicWord::clearCache();
 
                global $wgUser;
@@ -626,7 +622,7 @@ class ParserTest {
         * Currently this will only be done once per run, and any changes to
         * the db will be visible to later tests in the run.
         */
-       function setupDatabase() {
+       public function setupDatabase() {
                global $wgDBprefix, $wgDBtype;
                if ( $this->databaseSetupDone ) {
                        return;
@@ -771,7 +767,7 @@ class ParserTest {
                $db->tablePrefix( $prefix );
        }
 
-       private function teardownDatabase() {
+       public function teardownDatabase() {
                global $wgDBtype;
                if ( !$this->databaseSetupDone ) {
                        return;
@@ -1146,6 +1142,11 @@ class ParserTest {
                        $this->term->color( 0 );
                return "$display\n$caret";
        }
+
+       function getFakeTimestamp( &$parser, &$ts ) {
+               $ts = 123;
+               return true;
+       }
 }
 
 class AnsiTermColorer {
@@ -1733,3 +1734,4 @@ class TestFileIterator implements Iterator {
                return false;
        }
 }
+
index 66b3e22..e47a367 100644 (file)
  * @ingroup Maintenance
  */
 
-/** */
-require( 'parserTests.inc' );
+$options = array( 'quick', 'color', 'quiet', 'help', 'show-output', 'record', 'run-disabled' );
+$optionsWithArgs = array( 'regex', 'seed', 'setversion' );
+
+require_once( dirname( __FILE__ ) . '/commandLine.inc' );
+require_once( dirname( __FILE__ ) . '/parserTests.inc' );
 
 if ( isset( $options['help'] ) ) {
     echo <<<ENDS
index 0858eb9..908f466 100644 (file)
@@ -1994,15 +1994,6 @@ title=[[User:Ævar Arnfjörð Bjarmason]]
 </p>
 !! end
 
-!! test
-Magic Word: {{NUMBEROFARTICLES}}
-!! input
-{{NUMBEROFARTICLES}}
-!! result
-<p>2
-</p>
-!! end
-
 !! test
 Magic Word: {{NUMBEROFFILES}}
 !! input
index f55cd0e..53b7c98 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-if ( ! defined( 'MEDIAWIKI' ) )
-       die( -1 );
 /**
  * A basic extension that's used by the parser tests to test whether input and
  * arguments are passed to extensions properly.
@@ -13,22 +11,22 @@ if ( ! defined( 'MEDIAWIKI' ) )
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  */
 
-$wgHooks['ParserTestParser'][] = 'wfParserTestParserHookSetup';
+class ParserTestParserHook {
 
-function wfParserTestParserHookSetup( &$parser ) {
-       $parser->setHook( 'tag', 'wfParserTestParserHookHook' );
+       static function setup( &$parser ) {
+               $parser->setHook( 'tag', array( __CLASS__, 'hook' ) );
 
-       return true;
-}
+               return true;
+       }
 
-function wfParserTestParserHookHook( $in, $argv ) {
-       ob_start();
-       var_dump(
-               $in,
-               $argv
-       );
-       $ret = ob_get_clean();
+       function hook( $in, $argv ) {
+               ob_start();
+               var_dump(
+                       $in,
+                       $argv
+               );
+               $ret = ob_get_clean();
 
-       return "<pre>\n$ret</pre>";
+               return "<pre>\n$ret</pre>";
+       }
 }
-
index 59964c6..63230fa 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-if ( ! defined( 'MEDIAWIKI' ) )
-       die( -1 );
 /**
  * A basic extension that's used by the parser tests to test whether the parser
  * calls extensions when they're called inside comments, it shouldn't do that
@@ -13,35 +11,34 @@ if ( ! defined( 'MEDIAWIKI' ) )
  * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
  */
 
-$wgHooks['ParserTestParser'][] = 'wfParserTestStaticParserHookSetup';
+class ParserTestStaticParserHook {
+       static function setup( &$parser ) {
+               $parser->setHook( 'statictag', array( __CLASS__, 'hook' ) );
 
-function wfParserTestStaticParserHookSetup( &$parser ) {
-       $parser->setHook( 'statictag', 'wfParserTestStaticParserHookHook' );
+               return true;
+       }
 
-       return true;
+       static function hook( $in, $argv, $parser ) {
+               if ( ! count( $argv ) ) {
+                       $parser->static_tag_buf = $in;
+                       return '';
+               } else if ( count( $argv ) === 1 && isset( $argv['action'] )
+                       && $argv['action'] === 'flush' && $in === null )
+               {
+                       // Clear the buffer, we probably don't need to
+                       if ( isset( $parser->static_tag_buf ) ) {
+                               $tmp = $parser->static_tag_buf;
+                       } else {
+                               $tmp = '';
+                       }
+                       $parser->static_tag_buf = null;
+                       return $tmp;
+               } else
+                       // wtf?
+                       return
+                               "\nCall this extension as <statictag>string</statictag> or as" .
+                               " <statictag action=flush/>, not in any other way.\n" .
+                               "text: " . var_export( $in, true ) . "\n" .
+                               "argv: " . var_export( $argv, true ) . "\n";
+       }
 }
-
-function wfParserTestStaticParserHookHook( $in, $argv, $parser ) {
-       if ( ! count( $argv ) ) {
-               $parser->static_tag_buf = $in;
-               return '';
-       } else if ( count( $argv ) === 1 && isset( $argv['action'] )
-               && $argv['action'] === 'flush' && $in === null )
-       {
-               // Clear the buffer, we probably don't need to
-               if ( isset( $parser->static_tag_buf ) ) {
-                       $tmp = $parser->static_tag_buf;
-               } else {
-                       $tmp = '';
-               }
-               $parser->static_tag_buf = null;
-               return $tmp;
-       } else
-               // wtf?
-               return
-                       "\nCall this extension as <statictag>string</statictag> or as" .
-                       " <statictag action=flush/>, not in any other way.\n" .
-                       "text: " . var_export( $in, true ) . "\n" .
-                       "argv: " . var_export( $argv, true ) . "\n";
-}
-
index 9bc88ea..e4c1765 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-abstract class ApiSetup extends PHPUnit_Framework_TestCase {
+abstract class ApiTestSetup extends PHPUnit_Framework_TestCase {
        protected static $userName;
        protected static $passWord;
        protected static $user;
index 5733528..fa48f5e 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-require_once( "ApiSetup.php" );
-
 class MockApi extends ApiBase {
        public function execute() { }
        public function getVersion() { }
@@ -20,7 +18,7 @@ class MockApi extends ApiBase {
 }
 
 
-class ApiTest extends ApiSetup {
+class ApiTest extends ApiTestSetup {
 
        function setup() {
                parent::setup();
index 34b2823..d1130d9 100644 (file)
@@ -1,9 +1,6 @@
 <?php
 
-global $IP;
-require_once( "$IP/maintenance/tests/ApiSetup.php" );
-
-class ApiWatchTest extends ApiSetup {
+class ApiWatchTest extends ApiTestSetup {
 
        function setUp() {
                ini_set( 'log_errors', 1 );
index b2c0fb7..e35ecc6 100644 (file)
@@ -6,7 +6,7 @@
 all test: tap
 
 tap:
-       prove -e 'phpunit --tap' *Test*.php
+       prove -e 'php phpunit.php --tap' *Test*.php
 
 phpunit:
        phpunit
index 4d027b7..ebeffd6 100644 (file)
 <?php
 
-global $IP;
-define( "NO_COMMAND_LINE", 1 );
-define( "PARSER_TESTS", "$IP/maintenance/parserTests.txt" );
-
-require_once( "$IP/maintenance/parserTests.inc" );
-
-class PHPUnitTestRecorder extends TestRecorder {
-
-       function record( $test, $result ) {
-               $this->total++;
-               $this->success += $result;
-
-       }
-
-       function reportPercentage( $success, $total ) { }
-}
-
 class MediaWikiParserTestSuite extends PHPUnit_Framework_TestSuite {
-       static private $count;
-       static public $parser;
-       static public $iter;
-
-       public static function addTables( &$tables ) {
-               $tables[] = 'user_properties';
-               $tables[] = 'filearchive';
-               $tables[] = 'logging';
-               $tables[] = 'updatelog';
-               $tables[] = 'iwlinks';
-               $tables[] = 'searchindex';
-               return true;
-       }
+       private $count;
+       public $backend;
 
        public static function suite() {
-        $suite = new PHPUnit_Framework_TestSuite();
-
-               global $wgHooks;
-               $wgHooks['ParserTestTables'][] = "MediaWikiParserTestSuite::addTables";
-
-               self::$iter = new TestFileIterator( PARSER_TESTS );
-
-               foreach ( self::$iter as $i => $test ) {
-                       $suite->addTest( new ParserUnitTest( $i, $test['test'] ) );
-                       self::$count++;
-               }
-               unset( $tests );
-
-               self::$parser = new PTShell;
-               self::$iter->setParser( self::$parser );
-               self::$parser->recorder->start();
-               self::$parser->setupDatabase();
-               self::$iter->rewind();
-       /* } */
-       /* function setUp() { */
-               global $wgParser,  $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
-                  $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
-                  $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
-                  $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
-                  $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath,
-                  $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
-
-               $wgScript = '/index.php';
-               $wgScriptPath = '/';
-               $wgArticlePath = '/wiki/$1';
-               $wgStyleSheetPath = '/skins';
-               $wgStylePath = '/skins';
-               $wgThumbnailScriptPath = false;
-               $wgLocalFileRepo = array(
-                       'class' => 'LocalRepo',
-                       'name' => 'local',
-                       'directory' => 'test-repo',
-                       'url' => 'http://example.com/images',
-                       'hashLevels' => 2,
-                       'transformVia404' => false,
-               );
-               $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
-               $wgNamespaceAliases['Image'] = NS_FILE;
-               $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
-
-
-               $wgEnableParserCache = false;
-               $wgDeferredUpdateList = array();
-               $wgMemc =& wfGetMainCache();
-               $messageMemc =& wfGetMessageCacheStorage();
-               $parserMemc =& wfGetParserCacheStorage();
-
-               $wgContLang = new StubContLang;
-               $wgUser = new StubUser;
-               $wgLang = new StubUserLang;
-               $wgOut = new StubObject( 'wgOut', 'OutputPage' );
-               $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
-               $wgRequest = new WebRequest;
-
-               $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
-                                                                                 array( $messageMemc, $wgUseDatabaseMessages,
-                                                                                                $wgMsgCacheExpiry, wfWikiID() ) );
-               if ( $wgStyleDirectory === false ) $wgStyleDirectory   = "$IP/skins";
-
-               return $suite;
+               return new self;
        }
 
-       public function tearDown() {
-               /* $this->teardownDatabase(); */
-               $this->recorder->report();
-               $this->recorder->end();
-               $this->teardownUploadDir( $this->uploadDir );
+       public function __construct() {
+               $this->backend = new ParserTestSuiteBackend;
+               parent::__construct();
        }
 
-       public function count() { return self::$count; }
-
-       public function toString() {
-               return "MediaWiki Parser Tests";
-       }
-
-
-       private $uploadDir;
-       private $keepUploads;
-
-       /**
-        * Remove the dummy uploads directory
-        */
-       private function teardownUploadDir( $dir ) {
-               if ( $this->keepUploads ) {
-                       return;
-               }
-
-               // delete the files first, then the dirs.
-               self::deleteFiles(
-                       array (
-                               "$dir/3/3a/Foobar.jpg",
-                               "$dir/thumb/3/3a/Foobar.jpg/180px-Foobar.jpg",
-                               "$dir/thumb/3/3a/Foobar.jpg/200px-Foobar.jpg",
-                               "$dir/thumb/3/3a/Foobar.jpg/640px-Foobar.jpg",
-                               "$dir/thumb/3/3a/Foobar.jpg/120px-Foobar.jpg",
-
-                               "$dir/0/09/Bad.jpg",
-                       )
-               );
-
-               self::deleteDirs(
-                       array (
-                               "$dir/3/3a",
-                               "$dir/3",
-                               "$dir/thumb/6/65",
-                               "$dir/thumb/6",
-                               "$dir/thumb/3/3a/Foobar.jpg",
-                               "$dir/thumb/3/3a",
-                               "$dir/thumb/3",
-
-                               "$dir/0/09/",
-                               "$dir/0/",
-
-                               "$dir/thumb",
-                               "$dir",
-                       )
-               );
-       }
-
-       /**
-        * Delete the specified files, if they exist.
-        *
-        * @param $files Array: full paths to files to delete.
-        */
-       private static function deleteFiles( $files ) {
-               foreach ( $files as $file ) {
-                       if ( file_exists( $file ) ) {
-                               unlink( $file );
-                       }
-               }
-       }
-
-       /**
-        * Delete the specified directories, if they exist. Must be empty.
-        *
-        * @param $dirs Array: full paths to directories to delete.
-        */
-       private static function deleteDirs( $dirs ) {
-               foreach ( $dirs as $dir ) {
-                       if ( is_dir( $dir ) ) {
-                               rmdir( $dir );
-                       }
-               }
-       }
-
-       /**
-        * Create a dummy uploads directory which will contain a couple
-        * of files in order to pass existence tests.
-        *
-        * @return String: the directory
-        */
-       private function setupUploadDir() {
+       public function run( PHPUnit_Framework_TestResult $result = null, $filter = false, 
+               array $groups = array(), array $excludeGroups = array(), $processIsolation = false
+       ) {
                global $IP;
-               if ( $this->keepUploads ) {
-                       $dir = wfTempDir() . '/mwParser-images';
-                       if ( is_dir( $dir ) ) {
-                               return $dir;
-                       }
-               } else {
-                       $dir = wfTempDir() . "/mwParser-" . mt_rand() . "-images";
-               }
-
-               wfDebug( "Creating upload directory $dir\n" );
-               if ( file_exists( $dir ) ) {
-                       wfDebug( "Already exists!\n" );
-                       return $dir;
-               }
-               wfMkdirParents( $dir . '/3/3a' );
-               copy( "$IP/skins/monobook/headbg.jpg", "$dir/3/3a/Foobar.jpg" );
-
-               wfMkdirParents( $dir . '/0/09' );
-               copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
-               return $dir;
-       }
-}
-
-/**
- * @group Stub
- */
-class ParserUnitTest extends PHPUnit_Framework_TestCase {
-       private $number = 0;
-       private $test = "";
-
-       public function testBogus() {
-               $this->markTestSkipped( "This is a stub" );
-       }
-
-       public function __construct( $number = null, $test = null ) {
-               $this->number = $number;
-               $this->test = $test;
-       }
-
-       function count() { return 1; }
-
-       public function run( PHPUnit_Framework_TestResult $result = NULL ) {
-        PHPUnit_Framework_Assert::resetCount();
-        if ( $result === NULL ) {
-            $result = new PHPUnit_Framework_TestResult;
-        }
+               $this->backend->setupDatabase();
 
-               $t = MediaWikiParserTestSuite::$iter->current();
-               $k = MediaWikiParserTestSuite::$iter->key();
-
-               if ( !MediaWikiParserTestSuite::$iter->valid() ) {
-                       return;
-               }
+               $iter = new TestFileIterator( "$IP/maintenance/parserTests.txt" );
+               $iter->setParser( $this->backend );
+               $this->count = 0;
 
-               // The only way this should happen is if the parserTest.txt
-               // file were modified while the script is running.
-               if ( $k != $this->number ) {
-                       $i = $this->number;
-                       wfDie( "I got confused!\n" );
+               foreach ( $iter as $test ) {
+                       $this->addTest( new ParserUnitTest( $this, $test ) );
+                       $this->count++;
                }
 
-               $result->startTest( $this );
-               PHPUnit_Util_Timer::start();
-
-               $r = false;
-               try {
-                       $r = MediaWikiParserTestSuite::$parser->runTest(
-                               $t['test'], $t['input'], $t['result'], $t['options'], $t['config']
-                       );
-                       PHPUnit_Framework_Assert::assertTrue( true, $t['test'] );
-               }
-               catch ( PHPUnit_Framework_AssertionFailedError $e ) {
-                       $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() );
-               }
-               catch ( Exception $e ) {
-                       $result->addError( $this, $e, PHPUnit_Util_Timer::stop() );
-               }
-               PHPUnit_Framework_Assert::assertTrue( true, $t['test'] );
+               parent::run( $result, $filter, $groups, $excludeGroups, $processIsolation );
 
-               $result->endTest( $this, PHPUnit_Util_Timer::stop() );
-
-               MediaWikiParserTestSuite::$parser->recorder->record( $t['test'], $r );
-               MediaWikiParserTestSuite::$iter->next();
-               $this->addToAssertionCount( PHPUnit_Framework_Assert::getCount() );
-
-               return $result;
+               $this->backend->teardownDatabase();
        }
 
-}
-
-class PTShell extends ParserTest {
-       function showTesting( $desc ) {
+       public function count() {
+               return $this->count;
        }
 
-       function showRunFile( $path ) {
+       public function toString() {
+               return "MediaWiki Parser Tests";
        }
 
-       function showSuccess( $desc ) {
-               PHPUnit_Framework_Assert::assertTrue( true, $desc );
-               return true;
+       public function getBackend() {
+               return $this->backend;
        }
 
-       function showFailure( $desc, $expected, $got ) {
-               PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc );
+       public function getIterator() {
+               return $this->iterator;
        }
-
 }
 
-
index 8f3b1ca..85c43d1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-abstract class MediaWiki_Setup extends PHPUnit_Framework_TestCase {
+abstract class MediaWikiTestSetup extends PHPUnit_Framework_TestCase {
 
        protected function buildTestDatabase( $tables ) {
                global $wgDBprefix;
diff --git a/maintenance/tests/ParserHelpers.php b/maintenance/tests/ParserHelpers.php
new file mode 100644 (file)
index 0000000..3288df8
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+
+class ParserUnitTest extends PHPUnit_Framework_TestCase {
+       private $test = "";
+       private $suite;
+
+       public function __construct( $suite, $test = null ) {
+               $this->suite = $suite;
+               $this->test = $test;
+       }
+
+       function count() { return 1; }
+
+       public function run( PHPUnit_Framework_TestResult $result = null ) {
+        PHPUnit_Framework_Assert::resetCount();
+        if ( $result === NULL ) {
+            $result = new PHPUnit_Framework_TestResult;
+        }
+
+               $backend = $this->suite->getBackend();
+               $result->startTest( $this );
+               PHPUnit_Util_Timer::start();
+
+               $r = false;
+               try {
+                       # Run the test.
+                       # On failure, the subclassed backend will throw an exception with 
+                       # the details.
+                       $r = $backend->runTest(
+                               $this->test['test'],
+                               $this->test['input'], 
+                               $this->test['result'], 
+                               $this->test['options'],
+                               $this->test['config']
+                       );
+               }
+               catch ( PHPUnit_Framework_AssertionFailedError $e ) {
+                       $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() );
+               }
+               catch ( Exception $e ) {
+                       $result->addError( $this, $e, PHPUnit_Util_Timer::stop() );
+               }
+
+               $result->endTest( $this, PHPUnit_Util_Timer::stop() );
+
+               $backend->recorder->record( $this->test['test'], $r );
+               $this->addToAssertionCount( PHPUnit_Framework_Assert::getCount() );
+
+               return $result;
+       }
+
+}
+
+class ParserTestSuiteBackend extends ParserTest {
+       function showTesting( $desc ) {
+       }
+
+       function showRunFile( $path ) {
+       }
+
+       function showSuccess( $desc ) {
+               PHPUnit_Framework_Assert::assertTrue( true, $desc );
+               return true;
+       }
+
+       function showFailure( $desc, $expected, $got ) {
+               PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc );
+       }
+
+       public function setupRecorder() {
+               $this->recorder = new PHPUnitTestRecorder( $this );
+       }
+}
+
+class PHPUnitTestRecorder extends TestRecorder {
+       function record( $test, $result ) {
+               $this->total++;
+               $this->success += $result;
+
+       }
+
+       function reportPercentage( $success, $total ) { }
+}
+
index 6e3e274..e9884b3 100644 (file)
@@ -1,6 +1,4 @@
 <?php
-require_once( 'SearchEngineTest.php' );
-
 class SearchDbTest extends SearchEngineTest {
        var $db;
 
index bb119d8..d155eeb 100644 (file)
@@ -1,11 +1,9 @@
 <?php
 
-require_once( 'MediaWiki_Setup.php' );
-
 /**
  * @group Stub
  */
-class SearchEngineTest extends MediaWiki_Setup {
+class SearchEngineTest extends MediaWikiTestSetup {
        var $db, $search, $pageList;
 
        function pageExists( $title ) {
index 1e18154..65879c0 100644 (file)
@@ -1,16 +1,11 @@
 <?php
 
-global $IP;
-require_once( "ApiSetup.php" );
-require_once( dirname( dirname( __FILE__ ) ) . "/deleteArchivedFiles.inc" );
-require_once( dirname( dirname( __FILE__ ) ) . "/deleteArchivedRevisions.inc" );
-
 class nullClass {
        public function handleOutput() { }
        public function purgeRedundantText() { }
 }
 
-class UploadFromUrlTest extends ApiSetup {
+class UploadFromUrlTest extends ApiTestSetup {
 
        function setUp() {
                global $wgEnableUploads, $wgLocalFileRepo, $wgAllowCopyUploads;
index 60dd67c..2de8eba 100644 (file)
@@ -1,7 +1,5 @@
 <?php
 
-require_once( 'UploadFromUrlTest.php' );
-
 class UploadFromUrlTestSuite extends PHPUnit_Framework_TestSuite
 {
        public static function addTables( &$tables ) {
index 3783191..231413c 100644 (file)
@@ -1,32 +1,6 @@
 <?php
 
-/**
- * Set up the MediaWiki environment when running tests with "phpunit" command
- *
- * Warning: this file is not included from global scope!
- * @file
- */
-
-global $wgCommandLineMode, $IP, $optionsWithArgs;
-$IP = dirname( dirname( dirname( __FILE__ ) ) );
-define( 'MW_PHPUNIT_TEST', true );
-
-require_once( "$IP/maintenance/commandLine.inc" );
-$wgLocaltimezone = 'UTC';
-
-/* Tests were failing with sqlite */
-global $wgCaches;
-$wgCaches[CACHE_DB] = false;
-
-if ( !version_compare( PHPUnit_Runner_Version::id(), "3.4.1", ">" ) ) {
-  echo <<<EOF
-************************************************************
-
-These tests run best with version PHPUnit 3.4.2 or better.
-Earlier versions may show failures because earlier versions
-of PHPUnit do not properly implement dependencies.
-
-************************************************************
-
-EOF;
-}
\ No newline at end of file
+if ( !defined( 'MW_PHPUNIT_TEST' ) ) {
+       echo "Please run PHPUnit via maintenance/tests/phpunit\n";
+       exit( 1 );
+}
diff --git a/maintenance/tests/phpunit b/maintenance/tests/phpunit
new file mode 100755 (executable)
index 0000000..55659e2
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/env php
+<?php
+
+require( dirname( __FILE__ ) . '/../commandLine.inc' );
+require 'PHPUnit/TextUI/Command.php';
+define( 'MW_PHPUNIT_TEST', 1 );
+
+$wgLocaltimezone = 'UTC';
+
+/* Tests were failing with sqlite */
+global $wgCaches;
+$wgCaches[CACHE_DB] = false;
+
+if ( !version_compare( PHPUnit_Runner_Version::id(), "3.4.1", ">" ) ) {
+       echo <<<EOF
+************************************************************
+
+These tests run best with version PHPUnit 3.4.2 or later.
+Earlier versions may show failures because earlier versions
+of PHPUnit do not properly implement dependencies.
+
+************************************************************
+
+EOF;
+}
+
+$command = new PHPUnit_TextUI_Command;
+$command->run( $argv );
+
index 1ba58c8..1cf7277 100644 (file)
@@ -14,7 +14,7 @@
     <file>DatabaseSqliteTest.php</file>
     <file>DatabaseTest.php</file>
     <file>GlobalTest.php</file>
-    <file>HttpTest.php</file>
+       <!--<file>HttpTest.php</file>-->
     <file>IPTest.php</file>
     <file>ImageFunctionsTest.php</file>
     <file>LanguageConverterTest.php</file>
@@ -41,4 +41,4 @@
       <group>Stub</group>
     </exclude>
   </groups>
-</phpunit>
\ No newline at end of file
+</phpunit>