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 @@ |
44 | 44 | /* Classes */ |
45 | 45 | |
46 | 46 | abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { |
47 | | - protected $suite; |
| 47 | + public $suite; |
48 | 48 | public $regex = ''; |
49 | 49 | public $runDisabled = false; |
50 | 50 | |
— | — | @@ -53,11 +53,13 @@ |
54 | 54 | protected $oldTablePrefix; |
55 | 55 | protected $useTemporaryTables = true; |
56 | 56 | |
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; |
62 | 64 | |
63 | 65 | if( $this->needsDB() && !is_object( $this->dbClone ) ) { |
64 | 66 | $this->initDB(); |
— | — | @@ -80,6 +82,7 @@ |
81 | 83 | |
82 | 84 | //Make sysop user |
83 | 85 | $user = User::newFromName( 'UTSysop' ); |
| 86 | + |
84 | 87 | if ( $user->idForName() == 0 ) { |
85 | 88 | $user->addToDatabase(); |
86 | 89 | $user->setPassword( 'UTSysopPassword' ); |
— | — | @@ -140,7 +143,7 @@ |
141 | 144 | |
142 | 145 | if ( $dbType == 'oracle' ) { |
143 | 146 | # Insert 0 user to prevent FK violations |
144 | | - |
| 147 | + |
145 | 148 | # Anonymous user |
146 | 149 | $this->db->insert( 'user', array( |
147 | 150 | 'user_id' => 0, |
— | — | @@ -149,7 +152,7 @@ |
150 | 153 | |
151 | 154 | } |
152 | 155 | |
153 | | - private function destroyDB() { |
| 156 | + protected function destroyDB() { |
154 | 157 | if ( !self::$databaseSetupDone ) { |
155 | 158 | return; |
156 | 159 | } |
Index: trunk/phase3/tests/phpunit/includes/parser/ParserHelpers.php |
— | — | @@ -2,18 +2,29 @@ |
3 | 3 | |
4 | 4 | class PHPUnitParserTest extends ParserTest { |
5 | 5 | function showTesting( $desc ) { |
| 6 | + global $additionalMWCLIArgs; |
| 7 | + if( $additionalMWCLIArgs['verbose'] ) parent::showTesting( $desc ); |
| 8 | + //var_dump($options); |
6 | 9 | /* Do nothing since we don't want to show info during PHPUnit testing. */ |
7 | 10 | } |
8 | 11 | |
9 | 12 | public function showSuccess( $desc ) { |
10 | | - PHPUnit_Framework_Assert::assertTrue( true, $desc ); |
| 13 | + global $additionalMWCLIArgs; |
| 14 | + |
| 15 | + if( $additionalMWCLIArgs['verbose'] ) parent::showSuccess( $desc ); |
11 | 16 | return true; |
12 | 17 | } |
13 | 18 | |
14 | 19 | 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 ); |
16 | 23 | return false; |
17 | 24 | } |
| 25 | + |
| 26 | + public function setupRecorder( $options ) { |
| 27 | + $this->recorder = new PHPUnitTestRecorder( $this ); |
| 28 | + } |
18 | 29 | } |
19 | 30 | |
20 | 31 | class ParserUnitTest extends MediaWikiTestCase { |
Index: trunk/phase3/tests/phpunit/includes/parser/MediaWikiParserTest.php |
— | — | @@ -3,71 +3,62 @@ |
4 | 4 | require_once( dirname( __FILE__ ) . '/ParserHelpers.php' ); |
5 | 5 | require_once( dirname(dirname(dirname( __FILE__ ))) . '/bootstrap.php' ); |
6 | 6 | |
| 7 | +/** |
| 8 | + * @group Parser |
| 9 | + * @group Destructive |
| 10 | + * @group Database |
| 11 | + */ |
7 | 12 | class MediaWikiParserTest extends MediaWikiTestCase { |
8 | 13 | public $count; // Number of tests in the suite. |
9 | | - public $backend; // ParserTestSuiteBackend instance |
10 | 14 | 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 | + |
17 | 24 | } |
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; |
30 | 30 | } |
31 | | - |
32 | | - return $tester->suite; |
33 | 31 | } |
34 | 32 | |
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; |
61 | 58 | } |
| 59 | + |
62 | 60 | } |
63 | | - $this->articles = array(); |
| 61 | + |
64 | 62 | } |
65 | 63 | |
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 | | - } |
73 | 64 | } |
74 | 65 | |
Index: trunk/phase3/tests/phpunit/suite.xml |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | convertErrorsToExceptions="true" |
8 | 8 | convertNoticesToExceptions="true" |
9 | 9 | convertWarningsToExceptions="true" |
10 | | - stopOnFailure="true" |
| 10 | + stopOnFailure="false" |
11 | 11 | strict="true" |
12 | 12 | verbose="true"> |
13 | 13 | <testsuites> |
Index: trunk/phase3/tests/phpunit/phpunit.php |
— | — | @@ -14,6 +14,8 @@ |
15 | 15 | // Set a flag which can be used to detect when other scripts have been entered through this entry point or not |
16 | 16 | define( 'MW_PHPUNIT_TEST', true ); |
17 | 17 | |
| 18 | +$options = array( 'quiet' ); |
| 19 | + |
18 | 20 | // Start up MediaWiki in command-line mode |
19 | 21 | require_once( "$IP/maintenance/commandLine.inc" ); |
20 | 22 | |
— | — | @@ -28,4 +30,11 @@ |
29 | 31 | # Keep the old pre PHPUnit 3.5.0 behaviour for compatibility |
30 | 32 | require_once( 'PHPUnit/TextUI/Command.php' ); |
31 | 33 | } |
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 | + |