NOTE THAT THIS COMMIT REVEALS FAILING PARSER TESTS WHEN THEY ARE RUN IN PHPUnit....
[lhc/web/wiklou.git] / maintenance / tests / phpunit / includes / parser / ParserHelpers.php
1 <?php
2
3 class PHPUnitParserTest extends ParserTest {
4 function showTesting( $desc ) {
5 /* Do nothing since we don't want to show info during PHPUnit testing. */
6 }
7
8 public function showSuccess( $desc ) {
9 PHPUnit_Framework_Assert::assertTrue( true, $desc );
10 return true;
11 }
12
13 public function showFailure( $desc, $expected, $got ) {
14 PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc );
15 return false;
16 }
17 }
18
19 class ParserUnitTest extends PHPUnit_Framework_TestCase {
20 private $test = "";
21 private $suite;
22
23 public function __construct( $suite, $test = null ) {
24 $this->suite = $suite;
25 $this->test = $test;
26 }
27
28 function count() { return 1; }
29
30 public function run( PHPUnit_Framework_TestResult $result = null ) {
31 PHPUnit_Framework_Assert::resetCount();
32 if ( $result === NULL ) {
33 $result = new PHPUnit_Framework_TestResult;
34 }
35
36 $backend = new ParserTestSuiteBackend;
37 $result->startTest( $this );
38
39 // Support the transition to PHPUnit 3.5 where PHPUnit_Util_Timer is replaced with PHP_Timer
40 if ( class_exists( 'PHP_Timer' ) ) {
41 PHP_Timer::start();
42 } else {
43 PHPUnit_Util_Timer::start();
44 }
45
46 $r = false;
47 try {
48 # Run the test.
49 # On failure, the subclassed backend will throw an exception with
50 # the details.
51 $pt = new PHPUnitParserTest;
52 $r = $pt->runTest( $this->test['test'], $this->test['input'],
53 $this->test['result'], $this->test['options'], $this->test['config']
54 );
55 }
56 catch ( PHPUnit_Framework_AssertionFailedError $e ) {
57
58 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
59 if ( class_exists( 'PHP_Timer' ) ) {
60 $result->addFailure( $this, $e, PHP_Timer::stop() );
61 } else {
62 $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() );
63 }
64 }
65 catch ( Exception $e ) {
66 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
67 if ( class_exists( 'PHP_Timer' ) ) {
68 $result->addFailure( $this, $e, PHP_Timer::stop() );
69 } else {
70 $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() );
71 }
72 }
73
74 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
75 if ( class_exists( 'PHP_Timer' ) ) {
76 $result->endTest( $this, PHP_Timer::stop() );
77 } else {
78 $result->endTest( $this, PHPUnit_Util_Timer::stop() );
79 }
80
81 $backend->recorder->record( $this->test['test'], $r );
82 $this->addToAssertionCount( PHPUnit_Framework_Assert::getCount() );
83
84 return $result;
85 }
86
87 public function toString() {
88 return $this->test['test'];
89 }
90
91 }
92
93 class ParserTestSuiteBackend extends PHPUnit_FrameWork_TestSuite {
94 public $recorder;
95 public $term;
96 static $usePHPUnit = false;
97
98 function __construct() {
99 parent::__construct();
100 $this->setupRecorder(null);
101 self::$usePHPUnit = method_exists('PHPUnit_Framework_Assert', 'assertEquals');
102 }
103
104 function showTesting( $desc ) {
105 }
106
107 function showRunFile( $path ) {
108 }
109
110 function showTestResult( $desc, $result, $out ) {
111 if ( $result === $out ) {
112 return self::showSuccess( $desc, $result, $out );
113 } else {
114 return self::showFailure( $desc, $result, $out );
115 }
116 }
117
118 public function setupRecorder( $options ) {
119 $this->recorder = new PHPUnitTestRecorder( $this );
120 }
121 }
122
123 class PHPUnitTestRecorder extends TestRecorder {
124 function record( $test, $result ) {
125 $this->total++;
126 $this->success += $result;
127
128 }
129
130 function reportPercentage( $success, $total ) { }
131 }