* upgrade patches for oracle 1.17->1.19
[mediawiki.git] / tests / phpunit / includes / parser / ParserHelpers.php
blob4a6ce7c47e56b1fa6a1854b7a5b06596732dca20
1 <?php
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 );
10 return true;
13 public function showFailure( $desc, $expected, $got ) {
14 PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc );
15 return false;
18 public function setupRecorder( $options ) {
19 $this->recorder = new PHPUnitTestRecorder( $this );
23 class ParserUnitTest extends MediaWikiTestCase {
24 private $test = "";
26 public function __construct( $suite, $test = null ) {
27 parent::__construct();
28 $this->test = $test;
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' ) ) {
46 PHP_Timer::start();
47 } else {
48 PHPUnit_Util_Timer::start();
51 $r = false;
52 try {
53 # Run the test.
54 # On failure, the subclassed backend will throw an exception with
55 # the details.
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() );
66 } else {
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() );
74 } else {
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() );
82 } else {
83 $result->endTest( $this, PHPUnit_Util_Timer::stop() );
86 $backend->recorder->record( $this->test['test'], $r );
87 $this->addToAssertionCount( PHPUnit_Framework_Assert::getCount() );
89 return $result;
92 public function toString() {
93 return $this->test['test'];
98 class ParserTestSuiteBackend extends PHPUnit_FrameWork_TestSuite {
99 public $recorder;
100 public $term;
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 );
118 } else {
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 ) {
130 $this->total++;
131 $this->success += $result;
135 function reportPercentage( $success, $total ) { }