MediaWiki
master
|
00001 <?php 00002 00003 class SeleniumTestListener implements PHPUnit_Framework_TestListener { 00004 private $logger; 00005 private $tests_ok = 0; 00006 private $tests_failed = 0; 00007 00008 public function __construct( $loggerInstance ) { 00009 $this->logger = $loggerInstance; 00010 } 00011 00012 public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) { 00013 $this->logger->write( 'Error: ' . $e->getMessage() ); 00014 $this->tests_failed++; 00015 } 00016 00017 public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time ) 00018 { 00019 $this->logger->write( 'Failed: ' . $e->getMessage() ); 00020 $this->tests_failed++; 00021 } 00022 00023 public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) 00024 { 00025 $this->logger->write( 'Incomplete.' ); 00026 $this->tests_failed++; 00027 } 00028 00029 public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) 00030 { 00031 $this->logger->write( 'Skipped.' ); 00032 $this->tests_failed++; 00033 } 00034 00035 public function startTest( PHPUnit_Framework_Test $test ) { 00036 $this->logger->write( 00037 'Testing ' . $test->getName() . ' ... ', 00038 SeleniumTestSuite::CONTINUE_LINE 00039 ); 00040 } 00041 00042 public function endTest( PHPUnit_Framework_Test $test, $time ) { 00043 if ( !$test->hasFailed() ) { 00044 $this->logger->write( 'OK', SeleniumTestSuite::RESULT_OK ); 00045 $this->tests_ok++; 00046 } 00047 } 00048 00049 public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) { 00050 $this->logger->write( 'Testsuite ' . $suite->getName() . ' started.' ); 00051 $this->tests_ok = 0; 00052 $this->tests_failed = 0; 00053 } 00054 00055 public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) { 00056 $this->logger->write('Testsuite ' . $suite->getName() . ' ended.' ); 00057 if ( $this->tests_ok > 0 || $this->tests_failed > 0 ) { 00058 $this->logger->write( ' OK: ' . $this->tests_ok . ' Failed: ' . $this->tests_failed ); 00059 } 00060 $this->tests_ok = 0; 00061 $this->tests_failed = 0; 00062 } 00063 00064 public function statusMessage( $message ) { 00065 $this->logger->write( $message ); 00066 } 00067 } 00068