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.
--- /dev/null
+<?php
+
+class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command {
+
+ public function __construct() {
+ $this->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;
+ }
+
+}
/* Classes */
abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
- protected $suite;
+ public $suite;
public $regex = '';
public $runDisabled = false;
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();
//Make sysop user
$user = User::newFromName( 'UTSysop' );
+
if ( $user->idForName() == 0 ) {
$user->addToDatabase();
$user->setPassword( 'UTSysopPassword' );
if ( $dbType == 'oracle' ) {
# Insert 0 user to prevent FK violations
-
+
# Anonymous user
$this->db->insert( 'user', array(
'user_id' => 0,
}
- private function destroyDB() {
+ protected function destroyDB() {
if ( !self::$databaseSetupDone ) {
return;
}
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 */
- }
}
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 {
// 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" );
# 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();
+
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
- stopOnFailure="true"
+ stopOnFailure="false"
strict="true"
verbose="true">
<testsuites>