From: X! Date: Wed, 29 Dec 2010 02:23:51 +0000 (+0000) Subject: Make MediaWikiParserTest work now in PHPUnit. There are still a few bugs, such as... X-Git-Tag: 1.31.0-rc.0~33017 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=edbf743aeb37572416d91e81c6a30f560454d4a7;p=lhc%2Fweb%2Fwiklou.git 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. --- diff --git a/tests/phpunit/MediaWikiPHPUnitCommand.php b/tests/phpunit/MediaWikiPHPUnitCommand.php new file mode 100644 index 0000000000..b46c880d47 --- /dev/null +++ b/tests/phpunit/MediaWikiPHPUnitCommand.php @@ -0,0 +1,19 @@ +longOptions['verbose'] = 'verboseHandler'; + } + + public static function main( $exit = true ) { + $command = new self; + $command->run($_SERVER['argv'], $exit); + } + + protected function verboseHandler($value) { + global $additionalMWCLIArgs; + $additionalMWCLIArgs['verbose'] = true; + } + +} diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index e3a525b127..480954ae04 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -43,7 +43,7 @@ $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache', /* Classes */ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { - protected $suite; + public $suite; public $regex = ''; public $runDisabled = false; @@ -53,11 +53,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected $oldTablePrefix; protected $useTemporaryTables = true; - function __construct( PHPUnit_Framework_TestSuite $suite = null ) { - if ( null !== $suite ) { - $this->suite = $suite; - } - parent::__construct(); + function __construct( $name = null, array $data = array(), $dataName = '' ) { + if ($name !== null) { + $this->setName($name); + } + + $this->data = $data; + $this->dataName = $dataName; if( $this->needsDB() && !is_object( $this->dbClone ) ) { $this->initDB(); @@ -80,6 +82,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { //Make sysop user $user = User::newFromName( 'UTSysop' ); + if ( $user->idForName() == 0 ) { $user->addToDatabase(); $user->setPassword( 'UTSysopPassword' ); @@ -140,7 +143,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { if ( $dbType == 'oracle' ) { # Insert 0 user to prevent FK violations - + # Anonymous user $this->db->insert( 'user', array( 'user_id' => 0, @@ -149,7 +152,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } - private function destroyDB() { + protected function destroyDB() { if ( !self::$databaseSetupDone ) { return; } diff --git a/tests/phpunit/includes/parser/MediaWikiParserTest.php b/tests/phpunit/includes/parser/MediaWikiParserTest.php index d1e45c8a5a..fcc10a89f3 100644 --- a/tests/phpunit/includes/parser/MediaWikiParserTest.php +++ b/tests/phpunit/includes/parser/MediaWikiParserTest.php @@ -3,71 +3,62 @@ require_once( dirname( __FILE__ ) . '/ParserHelpers.php' ); require_once( dirname(dirname(dirname( __FILE__ ))) . '/bootstrap.php' ); +/** + * @group Parser + * @group Destructive + * @group Database + */ class MediaWikiParserTest extends MediaWikiTestCase { public $count; // Number of tests in the suite. - public $backend; // ParserTestSuiteBackend instance public $articles = array(); // Array of test articles defined by the tests - - public function __construct() { - $suite = new PHPUnit_Framework_TestSuite('Parser Tests'); - parent::__construct($suite); - $this->backend = new ParserTestSuiteBackend; - $this->setName( 'Parser tests' ); + protected $pt; + + function setUp() { + global $wgContLang; + $wgContLang = Language::factory( 'en' ); + + $this->pt = new PHPUnitParserTest; + $this->pt->setupDatabase(); + } - - public static function suite() { - global $IP; - - $tester = new self; - - $iter = new TestFileIterator( "$IP/tests/parser/parserTests.txt", $tester ); - $tester->count = 0; - - foreach ( $iter as $test ) { - $tester->suite->addTest( new ParserUnitTest( $tester, $test ), array( 'Parser', 'Destructive', 'Database', 'Broken' ) ); - $tester->count++; + + function tearDown() { + if( is_object( $this->pt ) && $this->pt instanceof PHPUnitParserTest ) { + $this->pt->teardownDatabase(); + $this->pt = null; } - - return $tester->suite; - } - - public function count() { - return $this->count; - } - - public function toString() { - return "MediaWiki Parser Tests"; } - public function getBackend() { - return $this->backend; - } - - public function getIterator() { - return $this->iterator; - } - - public function publishTestArticles() { - if ( empty( $this->articles ) ) { - return; - } - - foreach ( $this->articles as $name => $text ) { - $title = Title::newFromText( $name ); - - if ( $title->getArticleID( Title::GAID_FOR_UPDATE ) == 0 ) { - ParserTest::addArticle( $name, $text ); + + public function testParserTests() { + //global $IP; + //$wgParserTestFiles = array( "$IP/tests/parser/testparserTests.txt" ); + + global $wgParserTestFiles; + + foreach( $wgParserTestFiles as $file ) { + + $iter = new TestFileIterator( $file, $this->pt ); + + try { + foreach( $iter as $test ) { + $r = $this->pt->runTest( $test['test'], $test['input'], + $test['result'], $test['options'], $test['config'] + ); + + $this->assertTrue( $r, 'Parser test ' . $test['test'] ); + + } + } + catch( DBQueryError $e ) { + $this->assertTrue( false, 'Parser test ' . $test['test'] . ' (error: "' . $e->getMessage() . '")' ); + //This is annoying... it always stops on error and doesn't go to the next one. + continue; } + } - $this->articles = array(); + } - public function addArticle( $name, $text, $line ) { - $this->articles[$name] = $text; - } - - public function showRunFile( $path ) { - /* Nothing shown when run from phpunit */ - } } diff --git a/tests/phpunit/includes/parser/ParserHelpers.php b/tests/phpunit/includes/parser/ParserHelpers.php index f490a9ce7b..ad0bfd15ea 100644 --- a/tests/phpunit/includes/parser/ParserHelpers.php +++ b/tests/phpunit/includes/parser/ParserHelpers.php @@ -2,18 +2,29 @@ class PHPUnitParserTest extends ParserTest { function showTesting( $desc ) { + global $additionalMWCLIArgs; + if( $additionalMWCLIArgs['verbose'] ) parent::showTesting( $desc ); + //var_dump($options); /* Do nothing since we don't want to show info during PHPUnit testing. */ } public function showSuccess( $desc ) { - PHPUnit_Framework_Assert::assertTrue( true, $desc ); + global $additionalMWCLIArgs; + + if( $additionalMWCLIArgs['verbose'] ) parent::showSuccess( $desc ); return true; } public function showFailure( $desc, $expected, $got ) { - PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc ); + global $additionalMWCLIArgs; + + if( $additionalMWCLIArgs['verbose'] ) parent::showFailure( $desc, $expected, $got ); return false; } + + public function setupRecorder( $options ) { + $this->recorder = new PHPUnitTestRecorder( $this ); + } } class ParserUnitTest extends MediaWikiTestCase { diff --git a/tests/phpunit/phpunit.php b/tests/phpunit/phpunit.php index ddba247518..2b3069dd9e 100755 --- a/tests/phpunit/phpunit.php +++ b/tests/phpunit/phpunit.php @@ -14,6 +14,8 @@ $IP = dirname( dirname( dirname( __FILE__ ) ) ); // Set a flag which can be used to detect when other scripts have been entered through this entry point or not define( 'MW_PHPUNIT_TEST', true ); +$options = array( 'quiet' ); + // Start up MediaWiki in command-line mode require_once( "$IP/maintenance/commandLine.inc" ); @@ -28,4 +30,11 @@ if( version_compare( PHPUnit_Runner_Version::id(), '3.5.0', '>=' ) ) { # Keep the old pre PHPUnit 3.5.0 behaviour for compatibility require_once( 'PHPUnit/TextUI/Command.php' ); } -PHPUnit_TextUI_Command::main(); + +$additionalMWCLIArgs = array( + 'verbose' => false, +); + +require_once( "$IP/tests/phpunit/MediaWikiPHPUnitCommand.php" ); +MediaWikiPHPUnitCommand::main(); + diff --git a/tests/phpunit/suite.xml b/tests/phpunit/suite.xml index f384d84991..7efbe86ed0 100644 --- a/tests/phpunit/suite.xml +++ b/tests/phpunit/suite.xml @@ -6,7 +6,7 @@ convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" - stopOnFailure="true" + stopOnFailure="false" strict="true" verbose="true">