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 );
19 class ParserUnitTest
extends PHPUnit_Framework_TestCase
{
23 public function __construct( $suite, $test = null ) {
24 $this->suite
= $suite;
28 function count() { return 1; }
30 public function run( PHPUnit_Framework_TestResult
$result = null ) {
31 PHPUnit_Framework_Assert
::resetCount();
32 if ( $result === NULL ) {
33 $result = new PHPUnit_Framework_TestResult
;
36 $backend = new ParserTestSuiteBackend
;
37 $result->startTest( $this );
39 // Support the transition to PHPUnit 3.5 where PHPUnit_Util_Timer is replaced with PHP_Timer
40 if ( class_exists( 'PHP_Timer' ) ) {
43 PHPUnit_Util_Timer
::start();
49 # On failure, the subclassed backend will throw an exception with
51 $pt = new PHPUnitParserTest
;
52 $r = $pt->runTest( $this->test
['test'], $this->test
['input'],
53 $this->test
['result'], $this->test
['options'], $this->test
['config']
56 catch ( PHPUnit_Framework_AssertionFailedError
$e ) {
58 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
59 if ( class_exists( 'PHP_Timer' ) ) {
60 $result->addFailure( $this, $e, PHP_Timer
::stop() );
62 $result->addFailure( $this, $e, PHPUnit_Util_Timer
::stop() );
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() );
70 $result->addFailure( $this, $e, PHPUnit_Util_Timer
::stop() );
74 // PHPUnit_Util_Timer -> PHP_Timer support (see above)
75 if ( class_exists( 'PHP_Timer' ) ) {
76 $result->endTest( $this, PHP_Timer
::stop() );
78 $result->endTest( $this, PHPUnit_Util_Timer
::stop() );
81 $backend->recorder
->record( $this->test
['test'], $r );
82 $this->addToAssertionCount( PHPUnit_Framework_Assert
::getCount() );
87 public function toString() {
88 return $this->test
['test'];
93 class ParserTestSuiteBackend
extends PHPUnit_FrameWork_TestSuite
{
96 static $usePHPUnit = false;
98 function __construct() {
99 parent
::__construct();
100 $this->setupRecorder(null);
101 self
::$usePHPUnit = method_exists('PHPUnit_Framework_Assert', 'assertEquals');
104 function showTesting( $desc ) {
107 function showRunFile( $path ) {
110 function showTestResult( $desc, $result, $out ) {
111 if ( $result === $out ) {
112 return self
::showSuccess( $desc, $result, $out );
114 return self
::showFailure( $desc, $result, $out );
118 public function setupRecorder( $options ) {
119 $this->recorder
= new PHPUnitTestRecorder( $this );
123 class PHPUnitTestRecorder
extends TestRecorder
{
124 function record( $test, $result ) {
126 $this->success +
= $result;
130 function reportPercentage( $success, $total ) { }