more follow-up to r65715: coding style tweaks, etc.
[lhc/web/wiklou.git] / maintenance / tests / selenium / SeleniumTestListener.php
1 <?php
2 if ( !defined( 'MEDIAWIKI' ) || !defined( 'SELENIUMTEST' ) ) {
3 echo "This script cannot be run standalone";
4 exit( 1 );
5 }
6
7 class SeleniumTestListener implements PHPUnit_Framework_TestListener {
8 private $logger;
9 private $tests_ok = 0;
10 private $tests_failed = 0;
11
12 public function __construct( $loggerInstance ) {
13 $this->logger = $loggerInstance;
14 }
15
16 public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
17 $this->logger->write( 'Error: ' . $e->getMessage() );
18 $this->tests_failed++;
19 }
20
21 public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time )
22 {
23 $this->logger->write( 'Failed: ' . $e->getMessage() );
24 $this->tests_failed++;
25 }
26
27 public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time )
28 {
29 $this->logger->write( 'Incomplete.' );
30 $this->tests_failed++;
31 }
32
33 public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time )
34 {
35 $this->logger->write( 'Skipped.' );
36 $this->tests_failed++;
37 }
38
39 public function startTest( PHPUnit_Framework_Test $test ) {
40 $this->logger->write(
41 'Testing ' . $test->getName() . ' ... ',
42 MW_TESTLOGGER_CONTINUE_LINE
43 );
44 }
45
46 public function endTest( PHPUnit_Framework_Test $test, $time ) {
47 if ( !$test->hasFailed() ) {
48 $this->logger->write( 'OK', MW_TESTLOGGER_RESULT_OK );
49 $this->tests_ok++;
50 }
51 }
52
53 public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
54 $this->logger->write( 'Testsuite ' . $suite->getName() . ' started.' );
55 $this->tests_ok = 0;
56 }
57
58 public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
59 $this->logger->write(
60 'Testsuite ' . $suite->getName() . ' ended. OK: ' .
61 $this->tests_ok . ' Failed: ' . $this->tests_failed
62 );
63 }
64
65 public function statusMessage( $message ) {
66 $this->logger->write( $message );
67 }
68 }
69