r79154 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79153‎ | r79154 | r79155 >
Date:02:23, 29 December 2010
Author:soxred93
Status:resolved (Comments)
Tags:
Comment:
Make MediaWikiParserTest work now in PHPUnit. There are still a few bugs, such as stopping tests if one fails,
lack of fuzz testing and other parser test options, and the DB creation is still a little flaky.
A MediaWikiPHPUnitCommand class had to be created to allow for custom CLI parameters.
Modified paths:
  • /trunk/phase3/tests/phpunit/MediaWikiPHPUnitCommand.php (added) (history)
  • /trunk/phase3/tests/phpunit/bootstrap.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/MediaWikiParserTest.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/parser/ParserHelpers.php (modified) (history)
  • /trunk/phase3/tests/phpunit/phpunit.php (modified) (history)
  • /trunk/phase3/tests/phpunit/suite.xml (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/MediaWikiPHPUnitCommand.php
@@ -0,0 +1,19 @@
 2+<?php
 3+
 4+class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
 5+
 6+ public function __construct() {
 7+ $this->longOptions['verbose'] = 'verboseHandler';
 8+ }
 9+
 10+ public static function main( $exit = true ) {
 11+ $command = new self;
 12+ $command->run($_SERVER['argv'], $exit);
 13+ }
 14+
 15+ protected function verboseHandler($value) {
 16+ global $additionalMWCLIArgs;
 17+ $additionalMWCLIArgs['verbose'] = true;
 18+ }
 19+
 20+}
Index: trunk/phase3/tests/phpunit/bootstrap.php
@@ -43,7 +43,7 @@
4444 /* Classes */
4545
4646 abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
47 - protected $suite;
 47+ public $suite;
4848 public $regex = '';
4949 public $runDisabled = false;
5050
@@ -53,11 +53,13 @@
5454 protected $oldTablePrefix;
5555 protected $useTemporaryTables = true;
5656
57 - function __construct( PHPUnit_Framework_TestSuite $suite = null ) {
58 - if ( null !== $suite ) {
59 - $this->suite = $suite;
60 - }
61 - parent::__construct();
 57+ function __construct( $name = null, array $data = array(), $dataName = '' ) {
 58+ if ($name !== null) {
 59+ $this->setName($name);
 60+ }
 61+
 62+ $this->data = $data;
 63+ $this->dataName = $dataName;
6264
6365 if( $this->needsDB() && !is_object( $this->dbClone ) ) {
6466 $this->initDB();
@@ -80,6 +82,7 @@
8183
8284 //Make sysop user
8385 $user = User::newFromName( 'UTSysop' );
 86+
8487 if ( $user->idForName() == 0 ) {
8588 $user->addToDatabase();
8689 $user->setPassword( 'UTSysopPassword' );
@@ -140,7 +143,7 @@
141144
142145 if ( $dbType == 'oracle' ) {
143146 # Insert 0 user to prevent FK violations
144 -
 147+
145148 # Anonymous user
146149 $this->db->insert( 'user', array(
147150 'user_id' => 0,
@@ -149,7 +152,7 @@
150153
151154 }
152155
153 - private function destroyDB() {
 156+ protected function destroyDB() {
154157 if ( !self::$databaseSetupDone ) {
155158 return;
156159 }
Index: trunk/phase3/tests/phpunit/includes/parser/ParserHelpers.php
@@ -2,18 +2,29 @@
33
44 class PHPUnitParserTest extends ParserTest {
55 function showTesting( $desc ) {
 6+ global $additionalMWCLIArgs;
 7+ if( $additionalMWCLIArgs['verbose'] ) parent::showTesting( $desc );
 8+ //var_dump($options);
69 /* Do nothing since we don't want to show info during PHPUnit testing. */
710 }
811
912 public function showSuccess( $desc ) {
10 - PHPUnit_Framework_Assert::assertTrue( true, $desc );
 13+ global $additionalMWCLIArgs;
 14+
 15+ if( $additionalMWCLIArgs['verbose'] ) parent::showSuccess( $desc );
1116 return true;
1217 }
1318
1419 public function showFailure( $desc, $expected, $got ) {
15 - PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc );
 20+ global $additionalMWCLIArgs;
 21+
 22+ if( $additionalMWCLIArgs['verbose'] ) parent::showFailure( $desc, $expected, $got );
1623 return false;
1724 }
 25+
 26+ public function setupRecorder( $options ) {
 27+ $this->recorder = new PHPUnitTestRecorder( $this );
 28+ }
1829 }
1930
2031 class ParserUnitTest extends MediaWikiTestCase {
Index: trunk/phase3/tests/phpunit/includes/parser/MediaWikiParserTest.php
@@ -3,71 +3,62 @@
44 require_once( dirname( __FILE__ ) . '/ParserHelpers.php' );
55 require_once( dirname(dirname(dirname( __FILE__ ))) . '/bootstrap.php' );
66
 7+/**
 8+ * @group Parser
 9+ * @group Destructive
 10+ * @group Database
 11+ */
712 class MediaWikiParserTest extends MediaWikiTestCase {
813 public $count; // Number of tests in the suite.
9 - public $backend; // ParserTestSuiteBackend instance
1014 public $articles = array(); // Array of test articles defined by the tests
11 -
12 - public function __construct() {
13 - $suite = new PHPUnit_Framework_TestSuite('Parser Tests');
14 - parent::__construct($suite);
15 - $this->backend = new ParserTestSuiteBackend;
16 - $this->setName( 'Parser tests' );
 15+ protected $pt;
 16+
 17+ function setUp() {
 18+ global $wgContLang;
 19+ $wgContLang = Language::factory( 'en' );
 20+
 21+ $this->pt = new PHPUnitParserTest;
 22+ $this->pt->setupDatabase();
 23+
1724 }
18 -
19 - public static function suite() {
20 - global $IP;
21 -
22 - $tester = new self;
23 -
24 - $iter = new TestFileIterator( "$IP/tests/parser/parserTests.txt", $tester );
25 - $tester->count = 0;
26 -
27 - foreach ( $iter as $test ) {
28 - $tester->suite->addTest( new ParserUnitTest( $tester, $test ), array( 'Parser', 'Destructive', 'Database', 'Broken' ) );
29 - $tester->count++;
 25+
 26+ function tearDown() {
 27+ if( is_object( $this->pt ) && $this->pt instanceof PHPUnitParserTest ) {
 28+ $this->pt->teardownDatabase();
 29+ $this->pt = null;
3030 }
31 -
32 - return $tester->suite;
3331 }
3432
35 - public function count() {
36 - return $this->count;
37 - }
38 -
39 - public function toString() {
40 - return "MediaWiki Parser Tests";
41 - }
42 -
43 - public function getBackend() {
44 - return $this->backend;
45 - }
46 -
47 - public function getIterator() {
48 - return $this->iterator;
49 - }
50 -
51 - public function publishTestArticles() {
52 - if ( empty( $this->articles ) ) {
53 - return;
54 - }
55 -
56 - foreach ( $this->articles as $name => $text ) {
57 - $title = Title::newFromText( $name );
58 -
59 - if ( $title->getArticleID( Title::GAID_FOR_UPDATE ) == 0 ) {
60 - ParserTest::addArticle( $name, $text );
 33+
 34+ public function testParserTests() {
 35+ //global $IP;
 36+ //$wgParserTestFiles = array( "$IP/tests/parser/testparserTests.txt" );
 37+
 38+ global $wgParserTestFiles;
 39+
 40+ foreach( $wgParserTestFiles as $file ) {
 41+
 42+ $iter = new TestFileIterator( $file, $this->pt );
 43+
 44+ try {
 45+ foreach( $iter as $test ) {
 46+ $r = $this->pt->runTest( $test['test'], $test['input'],
 47+ $test['result'], $test['options'], $test['config']
 48+ );
 49+
 50+ $this->assertTrue( $r, 'Parser test ' . $test['test'] );
 51+
 52+ }
 53+ }
 54+ catch( DBQueryError $e ) {
 55+ $this->assertTrue( false, 'Parser test ' . $test['test'] . ' (error: "' . $e->getMessage() . '")' );
 56+ //This is annoying... it always stops on error and doesn't go to the next one.
 57+ continue;
6158 }
 59+
6260 }
63 - $this->articles = array();
 61+
6462 }
6563
66 - public function addArticle( $name, $text, $line ) {
67 - $this->articles[$name] = $text;
68 - }
69 -
70 - public function showRunFile( $path ) {
71 - /* Nothing shown when run from phpunit */
72 - }
7364 }
7465
Index: trunk/phase3/tests/phpunit/suite.xml
@@ -6,7 +6,7 @@
77 convertErrorsToExceptions="true"
88 convertNoticesToExceptions="true"
99 convertWarningsToExceptions="true"
10 - stopOnFailure="true"
 10+ stopOnFailure="false"
1111 strict="true"
1212 verbose="true">
1313 <testsuites>
Index: trunk/phase3/tests/phpunit/phpunit.php
@@ -14,6 +14,8 @@
1515 // Set a flag which can be used to detect when other scripts have been entered through this entry point or not
1616 define( 'MW_PHPUNIT_TEST', true );
1717
 18+$options = array( 'quiet' );
 19+
1820 // Start up MediaWiki in command-line mode
1921 require_once( "$IP/maintenance/commandLine.inc" );
2022
@@ -28,4 +30,11 @@
2931 # Keep the old pre PHPUnit 3.5.0 behaviour for compatibility
3032 require_once( 'PHPUnit/TextUI/Command.php' );
3133 }
32 -PHPUnit_TextUI_Command::main();
 34+
 35+$additionalMWCLIArgs = array(
 36+ 'verbose' => false,
 37+);
 38+
 39+require_once( "$IP/tests/phpunit/MediaWikiPHPUnitCommand.php" );
 40+MediaWikiPHPUnitCommand::main();
 41+

Follow-up revisions

RevisionCommit summaryAuthorDate
r79158Partial revert of r79154. hexmode asserts that these work, even though I keep...soxred9303:35, 29 December 2010
r79184Self-reverting my reversion of r79154 in r79158. The old version is flawed an...soxred9316:40, 29 December 2010
r79186Follow up r79183 removing global added in r79154platonides16:45, 29 December 2010

Comments

#Comment by 😂 (talk | contribs)   07:20, 29 December 2010

Ewwww, globals.

#Comment by X! (talk | contribs)   16:41, 29 December 2010

The Maintenance class uses globals anyway.

#Comment by Platonides (talk | contribs)   16:44, 29 December 2010

Removed in r79183 :)

#Comment by Bryan (talk | contribs)   18:15, 29 December 2010

Spaces instead of tabs in bootstrap.php

Status & tagging log