Add a `make tap' target which runs the tests with `prove' and `phpunit --tap'
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sat, 6 Feb 2010 15:57:51 +0000 (15:57 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sat, 6 Feb 2010 15:57:51 +0000 (15:57 +0000)
Also rename files so that all *Test*.php files are real test cases and
not just skeletons used for setup, those are now called *Setup*.php.

maintenance/tests/Makefile
maintenance/tests/MediaWikiAPITest.php
maintenance/tests/MediaWikiAPI_Setup.php [new file with mode: 0644]
maintenance/tests/MediaWikiAPI_TestCase.php [deleted file]
maintenance/tests/MediaWiki_Setup.php [new file with mode: 0644]
maintenance/tests/MediaWiki_TestCase.php [deleted file]
maintenance/tests/SearchEngineTest.php

index 545a8b1..5c81394 100644 (file)
@@ -1,11 +1,17 @@
 .PHONY: help test
 all test:
        phpunit
+
+tap:
+       prove -e 'phpunit --tap' *Test*.php
+
 install:
        pear channel-discover pear.phpunit.de
        pear install phpunit/PHPUnit
+
 help:
        # Options:
        #       test (default)          Run the unit tests
+       #       tap                     Run the tests individually through Test::Harness's prove(1)
        #       install                 Install PHPUnit from phpunit.de
        #       help                    You're looking at it!
index a08a9c9..045ec41 100644 (file)
@@ -1,8 +1,8 @@
 <?php
 
-require_once( "MediaWikiAPI_TestCase.php" );
+require_once( "MediaWikiAPI_Setup.php" );
 
-class MediaWikiAPITest extends MediaWikiAPI_TestCase {
+class MediaWikiAPITest extends MediaWikiAPI_Setup {
 
        function setup() {
                parent::setup();
diff --git a/maintenance/tests/MediaWikiAPI_Setup.php b/maintenance/tests/MediaWikiAPI_Setup.php
new file mode 100644 (file)
index 0000000..67807ac
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+abstract class MediaWikiAPI_Setup extends PHPUnit_Framework_TestCase {
+       protected static $userName;
+       protected static $passWord;
+       protected static $user;
+       protected static $apiUrl;
+
+       function setup() {
+               global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
+                       $wgScriptExtension, $wgMemc;
+
+               if($wgServerName == "localhost" || $wgServer == "http://localhost") {
+                       $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
+                                                                         'be set in LocalSettings.php');
+               }
+               self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension;
+
+               $wgMemc = new FakeMemCachedClient;
+               $wgContLang = Language::factory( 'en' );
+               $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
+               self::setupUser();
+       }
+
+       static function setupUser() {
+               if ( self::$user == NULL ) {
+                       self::$userName = "Useruser";
+                       self::$passWord = User::randomPassword();
+
+                       self::$user = User::newFromName(self::$userName);
+                       if ( !self::$user->getID() ) {
+                               self::$user = User::createNew(self::$userName, array(
+                                       "password" => self::$passWord,
+                                       "email" => "test@example.com",
+                                       "real_name" => "Test User"));
+                       } else {
+                               self::$user->setPassword(self::$passWord);
+                       }
+                       self::$user->saveSettings();
+               }
+       }
+}
diff --git a/maintenance/tests/MediaWikiAPI_TestCase.php b/maintenance/tests/MediaWikiAPI_TestCase.php
deleted file mode 100644 (file)
index e00e79b..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-<?php
-
-abstract class MediaWikiAPI_TestCase extends PHPUnit_Framework_TestCase {
-       protected static $userName;
-       protected static $passWord;
-       protected static $user;
-       protected static $apiUrl;
-
-       function setup() {
-               global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
-                       $wgScriptExtension, $wgMemc;
-
-               if($wgServerName == "localhost" || $wgServer == "http://localhost") {
-                       $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
-                                                                         'be set in LocalSettings.php');
-               }
-               self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension;
-
-               $wgMemc = new FakeMemCachedClient;
-               $wgContLang = Language::factory( 'en' );
-               $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
-               self::setupUser();
-       }
-
-       static function setupUser() {
-               if ( self::$user == NULL ) {
-                       self::$userName = "Useruser";
-                       self::$passWord = User::randomPassword();
-
-                       self::$user = User::newFromName(self::$userName);
-                       if ( !self::$user->getID() ) {
-                               self::$user = User::createNew(self::$userName, array(
-                                       "password" => self::$passWord,
-                                       "email" => "test@example.com",
-                                       "real_name" => "Test User"));
-                       } else {
-                               self::$user->setPassword(self::$passWord);
-                       }
-                       self::$user->saveSettings();
-               }
-       }
-}
diff --git a/maintenance/tests/MediaWiki_Setup.php b/maintenance/tests/MediaWiki_Setup.php
new file mode 100644 (file)
index 0000000..da42893
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+
+abstract class MediaWiki_Setup extends PHPUnit_Framework_TestCase {
+       /**
+        * @param string $serverType
+        * @param array $tables
+        */
+       protected function buildTestDatabase( $tables ) {
+               global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
+               $this->markTestIncomplete("This test requires DB admin user credentials.");
+               $wgDBprefix = 'parsertest_';
+
+               $db = new DatabaseMysql(
+                       $wgDBserver,
+                       $wgDBadminuser,
+                       $wgDBadminpassword,
+                       $wgDBname );
+               if( $db->isOpen() ) {
+                       if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
+                               # Database that supports CREATE TABLE ... LIKE
+                               foreach ($tables as $tbl) {
+                                       $newTableName = $db->tableName( $tbl );
+                                       #$tableName = $this->oldTableNames[$tbl];
+                                       $tableName = $tbl;
+                                       $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
+                               }
+                       } else {
+                               # Hack for MySQL versions < 4.1, which don't support
+                               # "CREATE TABLE ... LIKE". Note that
+                               # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
+                               # would not create the indexes we need....
+                               foreach ($tables as $tbl) {
+                                       $res = $db->query("SHOW CREATE TABLE $tbl");
+                                       $row = $db->fetchRow($res);
+                                       $create = $row[1];
+                                       $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
+                                               . $wgDBprefix . '\\1`', $create);
+                                       if ($create === $create_tmp) {
+                                               # Couldn't do replacement
+                                               wfDie( "could not create temporary table $tbl" );
+                                       }
+                                       $db->query($create_tmp);
+                               }
+
+                       }
+                       return $db;
+               } else {
+                       // Something amiss
+                       return null;
+               }
+       }
+}
+
diff --git a/maintenance/tests/MediaWiki_TestCase.php b/maintenance/tests/MediaWiki_TestCase.php
deleted file mode 100644 (file)
index 3e6b40a..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-
-abstract class MediaWiki_TestCase extends PHPUnit_Framework_TestCase {
-       /**
-        * @param string $serverType
-        * @param array $tables
-        */
-       protected function buildTestDatabase( $tables ) {
-               global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
-               $this->markTestIncomplete("This test requires DB admin user credentials.");
-               $wgDBprefix = 'parsertest_';
-
-               $db = new DatabaseMysql(
-                       $wgDBserver,
-                       $wgDBadminuser,
-                       $wgDBadminpassword,
-                       $wgDBname );
-               if( $db->isOpen() ) {
-                       if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
-                               # Database that supports CREATE TABLE ... LIKE
-                               foreach ($tables as $tbl) {
-                                       $newTableName = $db->tableName( $tbl );
-                                       #$tableName = $this->oldTableNames[$tbl];
-                                       $tableName = $tbl;
-                                       $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
-                               }
-                       } else {
-                               # Hack for MySQL versions < 4.1, which don't support
-                               # "CREATE TABLE ... LIKE". Note that
-                               # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
-                               # would not create the indexes we need....
-                               foreach ($tables as $tbl) {
-                                       $res = $db->query("SHOW CREATE TABLE $tbl");
-                                       $row = $db->fetchRow($res);
-                                       $create = $row[1];
-                                       $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
-                                               . $wgDBprefix . '\\1`', $create);
-                                       if ($create === $create_tmp) {
-                                               # Couldn't do replacement
-                                               wfDie( "could not create temporary table $tbl" );
-                                       }
-                                       $db->query($create_tmp);
-                               }
-
-                       }
-                       return $db;
-               } else {
-                       // Something amiss
-                       return null;
-               }
-       }
-}
-
index dc5023f..dd3367a 100644 (file)
@@ -1,11 +1,11 @@
 <?php
 
-require_once( 'MediaWiki_TestCase.php' );
+require_once( 'MediaWiki_Setup.php' );
 
 /** @todo document
  */
 
-class SearchEngineTest extends MediaWiki_TestCase {
+class SearchEngineTest extends MediaWiki_Setup {
        var $db, $search;
 
        function insertSearchData() {