Merge "Split up testHelpers.inc, break off fuzz testing"
[lhc/web/wiklou.git] / tests / parser / TestRecorder.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 * @ingroup Testing
20 */
21
22 class TestRecorder implements ITestRecorder {
23 public $parent;
24 public $term;
25
26 function __construct( $parent ) {
27 $this->parent = $parent;
28 $this->term = $parent->term;
29 }
30
31 function start() {
32 $this->total = 0;
33 $this->success = 0;
34 }
35
36 function record( $test, $subtest, $result ) {
37 $this->total++;
38 $this->success += ( $result ? 1 : 0 );
39 }
40
41 function end() {
42 // dummy
43 }
44
45 function report() {
46 if ( $this->total > 0 ) {
47 $this->reportPercentage( $this->success, $this->total );
48 } else {
49 throw new MWException( "No tests found.\n" );
50 }
51 }
52
53 function reportPercentage( $success, $total ) {
54 $ratio = wfPercent( 100 * $success / $total );
55 print $this->term->color( 1 ) . "Passed $success of $total tests ($ratio)... ";
56
57 if ( $success == $total ) {
58 print $this->term->color( 32 ) . "ALL TESTS PASSED!";
59 } else {
60 $failed = $total - $success;
61 print $this->term->color( 31 ) . "$failed tests failed!";
62 }
63
64 print $this->term->reset() . "\n";
65
66 return ( $success == $total );
67 }
68 }
69