3 class PHPUnitParserTest
extends ParserTest
{
4 function showTesting( $desc ) {
5 /* Do nothing since we don't want to show info during PHPUnit testing. */
8 public function showSuccess( $desc ) {
9 PHPUnit_Framework_Assert
::assertTrue( true, $desc );
13 public function showFailure( $desc, $expected, $got ) {
14 PHPUnit_Framework_Assert
::assertEquals( $expected, $got, $desc );
18 public function setupRecorder( $options ) {
19 $this->recorder
= new PHPUnitTestRecorder( $this );
23 class ParserUnitTest
extends MediaWikiTestCase
{
26 public function __construct( $suite, $test = null ) {
27 parent
::__construct();
29 $this->suite
= $suite;
32 function count() { return 1; }
34 public function run( PHPUnit_Framework_TestResult
$result = null ) {
35 PHPUnit_Framework_Assert
::resetCount();
36 if ( $result === NULL ) {
37 $result = new PHPUnit_Framework_TestResult
;
40 $this->suite
->publishTestArticles(); // Add articles needed by the tests.
41 $backend = new ParserTestSuiteBackend
;
42 $result->startTest( $this );
44 // Support the transition to PHPUnit 3.5 where PHPUnit_Util_Timer is replaced with PHP_Timer
45 if ( class_exists( 'PHP_Timer' ) ) {
48 PHPUnit_Util_Timer
::start();
54 # On failure, the subclassed backend will throw an exception with
56 $pt = new PHPUnitParserTest
;
57 $r = $pt->runTest( $this->test
['test'], $this->test
['input'],
58 $this->test
['result'], $this->test
['options'], $this->test
['config']
61 catch ( PHPUnit_Framework_AssertionFailedError
$e ) {
63 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
64 if ( class_exists( 'PHP_Timer' ) ) {
65 $result->addFailure( $this, $e, PHP_Timer
::stop() );
67 $result->addFailure( $this, $e, PHPUnit_Util_Timer
::stop() );
70 catch ( Exception
$e ) {
71 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
72 if ( class_exists( 'PHP_Timer' ) ) {
73 $result->addFailure( $this, $e, PHP_Timer
::stop() );
75 $result->addFailure( $this, $e, PHPUnit_Util_Timer
::stop() );
79 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
80 if ( class_exists( 'PHP_Timer' ) ) {
81 $result->endTest( $this, PHP_Timer
::stop() );
83 $result->endTest( $this, PHPUnit_Util_Timer
::stop() );
86 $backend->recorder
->record( $this->test
['test'], $r );
87 $this->addToAssertionCount( PHPUnit_Framework_Assert
::getCount() );
92 public function toString() {
93 return $this->test
['test'];
98 class ParserTestSuiteBackend
extends PHPUnit_FrameWork_TestSuite
{
101 static $usePHPUnit = false;
103 function __construct() {
104 parent
::__construct();
105 $this->setupRecorder(null);
106 self
::$usePHPUnit = method_exists('PHPUnit_Framework_Assert', 'assertEquals');
109 function showTesting( $desc ) {
112 function showRunFile( $path ) {
115 function showTestResult( $desc, $result, $out ) {
116 if ( $result === $out ) {
117 return self
::showSuccess( $desc, $result, $out );
119 return self
::showFailure( $desc, $result, $out );
123 public function setupRecorder( $options ) {
124 $this->recorder
= new PHPUnitTestRecorder( $this );
128 class PHPUnitTestRecorder
extends TestRecorder
{
129 function record( $test, $result ) {
131 $this->success +
= $result;
135 function reportPercentage( $success, $total ) { }