r62071 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62070‎ | r62071 | r62072 >
Date:15:57, 6 February 2010
Author:avar
Status:ok
Tags:
Comment:
Add a `make tap' target which runs the tests with `prove' and `phpunit --tap'

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.
Modified paths:
  • /trunk/phase3/maintenance/tests/Makefile (modified) (history)
  • /trunk/phase3/maintenance/tests/MediaWikiAPITest.php (modified) (history)
  • /trunk/phase3/maintenance/tests/MediaWikiAPI_Setup.php (added) (history)
  • /trunk/phase3/maintenance/tests/MediaWikiAPI_TestCase.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/MediaWiki_Setup.php (added) (history)
  • /trunk/phase3/maintenance/tests/MediaWiki_TestCase.php (deleted) (history)
  • /trunk/phase3/maintenance/tests/SearchEngineTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/MediaWiki_TestCase.php
@@ -1,53 +0,0 @@
2 -<?php
3 -
4 -abstract class MediaWiki_TestCase extends PHPUnit_Framework_TestCase {
5 - /**
6 - * @param string $serverType
7 - * @param array $tables
8 - */
9 - protected function buildTestDatabase( $tables ) {
10 - global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
11 - $this->markTestIncomplete("This test requires DB admin user credentials.");
12 - $wgDBprefix = 'parsertest_';
13 -
14 - $db = new DatabaseMysql(
15 - $wgDBserver,
16 - $wgDBadminuser,
17 - $wgDBadminpassword,
18 - $wgDBname );
19 - if( $db->isOpen() ) {
20 - if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
21 - # Database that supports CREATE TABLE ... LIKE
22 - foreach ($tables as $tbl) {
23 - $newTableName = $db->tableName( $tbl );
24 - #$tableName = $this->oldTableNames[$tbl];
25 - $tableName = $tbl;
26 - $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
27 - }
28 - } else {
29 - # Hack for MySQL versions < 4.1, which don't support
30 - # "CREATE TABLE ... LIKE". Note that
31 - # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
32 - # would not create the indexes we need....
33 - foreach ($tables as $tbl) {
34 - $res = $db->query("SHOW CREATE TABLE $tbl");
35 - $row = $db->fetchRow($res);
36 - $create = $row[1];
37 - $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
38 - . $wgDBprefix . '\\1`', $create);
39 - if ($create === $create_tmp) {
40 - # Couldn't do replacement
41 - wfDie( "could not create temporary table $tbl" );
42 - }
43 - $db->query($create_tmp);
44 - }
45 -
46 - }
47 - return $db;
48 - } else {
49 - // Something amiss
50 - return null;
51 - }
52 - }
53 -}
54 -
Index: trunk/phase3/maintenance/tests/MediaWikiAPI_TestCase.php
@@ -1,42 +0,0 @@
2 -<?php
3 -
4 -abstract class MediaWikiAPI_TestCase extends PHPUnit_Framework_TestCase {
5 - protected static $userName;
6 - protected static $passWord;
7 - protected static $user;
8 - protected static $apiUrl;
9 -
10 - function setup() {
11 - global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
12 - $wgScriptExtension, $wgMemc;
13 -
14 - if($wgServerName == "localhost" || $wgServer == "http://localhost") {
15 - $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
16 - 'be set in LocalSettings.php');
17 - }
18 - self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension;
19 -
20 - $wgMemc = new FakeMemCachedClient;
21 - $wgContLang = Language::factory( 'en' );
22 - $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
23 - self::setupUser();
24 - }
25 -
26 - static function setupUser() {
27 - if ( self::$user == NULL ) {
28 - self::$userName = "Useruser";
29 - self::$passWord = User::randomPassword();
30 -
31 - self::$user = User::newFromName(self::$userName);
32 - if ( !self::$user->getID() ) {
33 - self::$user = User::createNew(self::$userName, array(
34 - "password" => self::$passWord,
35 - "email" => "test@example.com",
36 - "real_name" => "Test User"));
37 - } else {
38 - self::$user->setPassword(self::$passWord);
39 - }
40 - self::$user->saveSettings();
41 - }
42 - }
43 -}
Index: trunk/phase3/maintenance/tests/SearchEngineTest.php
@@ -1,11 +1,11 @@
22 <?php
33
4 -require_once( 'MediaWiki_TestCase.php' );
 4+require_once( 'MediaWiki_Setup.php' );
55
66 /** @todo document
77 */
88
9 -class SearchEngineTest extends MediaWiki_TestCase {
 9+class SearchEngineTest extends MediaWiki_Setup {
1010 var $db, $search;
1111
1212 function insertSearchData() {
Index: trunk/phase3/maintenance/tests/MediaWikiAPITest.php
@@ -1,8 +1,8 @@
22 <?php
33
4 -require_once( "MediaWikiAPI_TestCase.php" );
 4+require_once( "MediaWikiAPI_Setup.php" );
55
6 -class MediaWikiAPITest extends MediaWikiAPI_TestCase {
 6+class MediaWikiAPITest extends MediaWikiAPI_Setup {
77
88 function setup() {
99 parent::setup();
Index: trunk/phase3/maintenance/tests/MediaWikiAPI_Setup.php
@@ -0,0 +1,42 @@
 2+<?php
 3+
 4+abstract class MediaWikiAPI_Setup extends PHPUnit_Framework_TestCase {
 5+ protected static $userName;
 6+ protected static $passWord;
 7+ protected static $user;
 8+ protected static $apiUrl;
 9+
 10+ function setup() {
 11+ global $wgServerName, $wgServer, $wgContLang, $wgAuth, $wgScriptPath,
 12+ $wgScriptExtension, $wgMemc;
 13+
 14+ if($wgServerName == "localhost" || $wgServer == "http://localhost") {
 15+ $this->markTestIncomplete('This test needs $wgServerName and $wgServer to '.
 16+ 'be set in LocalSettings.php');
 17+ }
 18+ self::$apiUrl = $wgServer.$wgScriptPath."/api".$wgScriptExtension;
 19+
 20+ $wgMemc = new FakeMemCachedClient;
 21+ $wgContLang = Language::factory( 'en' );
 22+ $wgAuth = new StubObject( 'wgAuth', 'AuthPlugin' );
 23+ self::setupUser();
 24+ }
 25+
 26+ static function setupUser() {
 27+ if ( self::$user == NULL ) {
 28+ self::$userName = "Useruser";
 29+ self::$passWord = User::randomPassword();
 30+
 31+ self::$user = User::newFromName(self::$userName);
 32+ if ( !self::$user->getID() ) {
 33+ self::$user = User::createNew(self::$userName, array(
 34+ "password" => self::$passWord,
 35+ "email" => "test@example.com",
 36+ "real_name" => "Test User"));
 37+ } else {
 38+ self::$user->setPassword(self::$passWord);
 39+ }
 40+ self::$user->saveSettings();
 41+ }
 42+ }
 43+}
Property changes on: trunk/phase3/maintenance/tests/MediaWikiAPI_Setup.php
___________________________________________________________________
Name: svn:eol-style
144 + native
Name: svn:eol-syle
245 + native
Index: trunk/phase3/maintenance/tests/MediaWiki_Setup.php
@@ -0,0 +1,53 @@
 2+<?php
 3+
 4+abstract class MediaWiki_Setup extends PHPUnit_Framework_TestCase {
 5+ /**
 6+ * @param string $serverType
 7+ * @param array $tables
 8+ */
 9+ protected function buildTestDatabase( $tables ) {
 10+ global $testOptions, $wgDBprefix, $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname;
 11+ $this->markTestIncomplete("This test requires DB admin user credentials.");
 12+ $wgDBprefix = 'parsertest_';
 13+
 14+ $db = new DatabaseMysql(
 15+ $wgDBserver,
 16+ $wgDBadminuser,
 17+ $wgDBadminpassword,
 18+ $wgDBname );
 19+ if( $db->isOpen() ) {
 20+ if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
 21+ # Database that supports CREATE TABLE ... LIKE
 22+ foreach ($tables as $tbl) {
 23+ $newTableName = $db->tableName( $tbl );
 24+ #$tableName = $this->oldTableNames[$tbl];
 25+ $tableName = $tbl;
 26+ $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName)");
 27+ }
 28+ } else {
 29+ # Hack for MySQL versions < 4.1, which don't support
 30+ # "CREATE TABLE ... LIKE". Note that
 31+ # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
 32+ # would not create the indexes we need....
 33+ foreach ($tables as $tbl) {
 34+ $res = $db->query("SHOW CREATE TABLE $tbl");
 35+ $row = $db->fetchRow($res);
 36+ $create = $row[1];
 37+ $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
 38+ . $wgDBprefix . '\\1`', $create);
 39+ if ($create === $create_tmp) {
 40+ # Couldn't do replacement
 41+ wfDie( "could not create temporary table $tbl" );
 42+ }
 43+ $db->query($create_tmp);
 44+ }
 45+
 46+ }
 47+ return $db;
 48+ } else {
 49+ // Something amiss
 50+ return null;
 51+ }
 52+ }
 53+}
 54+
Property changes on: trunk/phase3/maintenance/tests/MediaWiki_Setup.php
___________________________________________________________________
Name: svn:eol-style
155 + native
Index: trunk/phase3/maintenance/tests/Makefile
@@ -1,11 +1,17 @@
22 .PHONY: help test
33 all test:
44 phpunit
 5+
 6+tap:
 7+ prove -e 'phpunit --tap' *Test*.php
 8+
59 install:
610 pear channel-discover pear.phpunit.de
711 pear install phpunit/PHPUnit
 12+
813 help:
914 # Options:
1015 # test (default) Run the unit tests
 16+ # tap Run the tests individually through Test::Harness's prove(1)
1117 # install Install PHPUnit from phpunit.de
1218 # help You're looking at it!

Status & tagging log