3 class PHPUnitParserTest
extends ParserTest
{
4 function showTesting( $desc ) {
5 global $additionalMWCLIArgs;
6 if( $additionalMWCLIArgs['verbose'] ) parent
::showTesting( $desc );
7 /* Do nothing since we don't want to show info during PHPUnit testing. */
10 public function showSuccess( $desc ) {
11 global $additionalMWCLIArgs;
12 PHPUnit_Framework_Assert
::assertTrue( true, $desc );
13 if( $additionalMWCLIArgs['verbose'] ) parent
::showSuccess( $desc );
17 public function showFailure( $desc, $expected, $got ) {
18 global $additionalMWCLIArgs;
19 PHPUnit_Framework_Assert
::assertEquals( $expected, $got, $desc );
20 if( $additionalMWCLIArgs['verbose'] ) parent
::showFailure( $desc, $expected, $got );
24 public function setupRecorder( $options ) {
25 $this->recorder
= new PHPUnitTestRecorder( $this );
29 class ParserUnitTest
extends MediaWikiTestCase
{
32 public function __construct( $suite, $test = null ) {
33 parent
::__construct();
35 $this->suite
= $suite;
38 function count() { return 1; }
40 public function run( PHPUnit_Framework_TestResult
$result = null ) {
41 PHPUnit_Framework_Assert
::resetCount();
42 if ( $result === NULL ) {
43 $result = new PHPUnit_Framework_TestResult
;
46 $this->suite
->publishTestArticles(); // Add articles needed by the tests.
47 $backend = new ParserTestSuiteBackend
;
48 $result->startTest( $this );
50 // Support the transition to PHPUnit 3.5 where PHPUnit_Util_Timer is replaced with PHP_Timer
51 if ( class_exists( 'PHP_Timer' ) ) {
54 PHPUnit_Util_Timer
::start();
60 # On failure, the subclassed backend will throw an exception with
62 $pt = new PHPUnitParserTest
;
63 $r = $pt->runTest( $this->test
['test'], $this->test
['input'],
64 $this->test
['result'], $this->test
['options'], $this->test
['config']
67 catch ( PHPUnit_Framework_AssertionFailedError
$e ) {
69 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
70 if ( class_exists( 'PHP_Timer' ) ) {
71 $result->addFailure( $this, $e, PHP_Timer
::stop() );
73 $result->addFailure( $this, $e, PHPUnit_Util_Timer
::stop() );
76 catch ( Exception
$e ) {
77 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
78 if ( class_exists( 'PHP_Timer' ) ) {
79 $result->addFailure( $this, $e, PHP_Timer
::stop() );
81 $result->addFailure( $this, $e, PHPUnit_Util_Timer
::stop() );
85 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
86 if ( class_exists( 'PHP_Timer' ) ) {
87 $result->endTest( $this, PHP_Timer
::stop() );
89 $result->endTest( $this, PHPUnit_Util_Timer
::stop() );
92 $backend->recorder
->record( $this->test
['test'], $r );
93 $this->addToAssertionCount( PHPUnit_Framework_Assert
::getCount() );
98 public function toString() {
99 return $this->test
['test'];
104 class ParserTestSuiteBackend
extends PHPUnit_FrameWork_TestSuite
{
107 static $usePHPUnit = false;
109 function __construct() {
110 parent
::__construct();
111 $this->setupRecorder(null);
112 self
::$usePHPUnit = method_exists('PHPUnit_Framework_Assert', 'assertEquals');
115 function showTesting( $desc ) {
118 function showRunFile( $path ) {
121 function showTestResult( $desc, $result, $out ) {
122 if ( $result === $out ) {
123 return self
::showSuccess( $desc, $result, $out );
125 return self
::showFailure( $desc, $result, $out );
129 public function setupRecorder( $options ) {
130 $this->recorder
= new PHPUnitTestRecorder( $this );
134 class PHPUnitTestRecorder
extends TestRecorder
{
135 function record( $test, $result ) {
137 $this->success +
= $result;
141 function reportPercentage( $success, $total ) { }