ec73402d31603fd8abbba7d1ffe20dd94eac11fe
[lhc/web/wiklou.git] / maintenance / tests / ParserHelpers.php
1 <?php
2
3 class ParserUnitTest extends PHPUnit_Framework_TestCase {
4 private $test = "";
5 private $suite;
6
7 public function __construct( $suite, $test = null ) {
8 $this->suite = $suite;
9 $this->test = $test;
10 }
11
12 function count() { return 1; }
13
14 public function run( PHPUnit_Framework_TestResult $result = null ) {
15 PHPUnit_Framework_Assert::resetCount();
16 if ( $result === NULL ) {
17 $result = new PHPUnit_Framework_TestResult;
18 }
19
20 $backend = $this->suite->getBackend();
21 $result->startTest( $this );
22 PHPUnit_Util_Timer::start();
23
24 $r = false;
25 try {
26 # Run the test.
27 # On failure, the subclassed backend will throw an exception with
28 # the details.
29 $r = $backend->runTest(
30 $this->test['test'],
31 $this->test['input'],
32 $this->test['result'],
33 $this->test['options'],
34 $this->test['config']
35 );
36 }
37 catch ( PHPUnit_Framework_AssertionFailedError $e ) {
38 $result->addFailure( $this, $e, PHPUnit_Util_Timer::stop() );
39 }
40 catch ( Exception $e ) {
41 $result->addError( $this, $e, PHPUnit_Util_Timer::stop() );
42 }
43
44 $result->endTest( $this, PHPUnit_Util_Timer::stop() );
45
46 $backend->recorder->record( $this->test['test'], $r );
47 $this->addToAssertionCount( PHPUnit_Framework_Assert::getCount() );
48
49 return $result;
50 }
51
52 public function toString() {
53 return $this->test['test'];
54 }
55
56 }
57
58 class ParserTestSuiteBackend extends ParserTest {
59 function showTesting( $desc ) {
60 }
61
62 function showRunFile( $path ) {
63 }
64
65 function showSuccess( $desc ) {
66 PHPUnit_Framework_Assert::assertTrue( true, $desc );
67 return true;
68 }
69
70 function showFailure( $desc, $expected, $got ) {
71 PHPUnit_Framework_Assert::assertEquals( $expected, $got, $desc );
72 }
73
74 public function setupRecorder() {
75 $this->recorder = new PHPUnitTestRecorder( $this );
76 }
77 }
78
79 class PHPUnitTestRecorder extends TestRecorder {
80 function record( $test, $result ) {
81 $this->total++;
82 $this->success += $result;
83
84 }
85
86 function reportPercentage( $success, $total ) { }
87 }
88