Made TempFSFile try to purge files on fatals too
[mediawiki.git] / tests / phpunit / MediaWikiPHPUnitTestListener.php
blobc8ec4114d0f28c42553c686d98ba8d748e36ee25
1 <?php
2 class MediaWikiPHPUnitTestListener implements PHPUnit_Framework_TestListener {
4 /**
5 * @var string
6 */
7 protected $logChannel;
9 public function __construct( $logChannel ) {
10 $this->logChannel = $logChannel;
13 protected function getTestName( PHPUnit_Framework_Test $test ) {
14 $name = get_class( $test );
16 if ( $test instanceof PHPUnit_Framework_TestCase ) {
17 $name .= '::' . $test->getName( true );
20 return $name;
23 protected function getErrorName( Exception $exception ) {
24 $name = get_class( $exception );
25 $name = "[$name] " . $exception->getMessage();
27 return $name;
30 /**
31 * An error occurred.
33 * @param PHPUnit_Framework_Test $test
34 * @param Exception $e
35 * @param float $time
37 public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
38 wfDebugLog( $this->logChannel, 'ERROR in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) );
41 /**
42 * A failure occurred.
44 * @param PHPUnit_Framework_Test $test
45 * @param PHPUnit_Framework_AssertionFailedError $e
46 * @param float $time
48 public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time ) {
49 wfDebugLog( $this->logChannel, 'FAILURE in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) );
52 /**
53 * Incomplete test.
55 * @param PHPUnit_Framework_Test $test
56 * @param Exception $e
57 * @param float $time
59 public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
60 wfDebugLog( $this->logChannel, 'Incomplete test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) );
63 /**
64 * Skipped test.
66 * @param PHPUnit_Framework_Test $test
67 * @param Exception $e
68 * @param float $time
70 * @since Method available since Release 3.0.0
72 public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
73 wfDebugLog( $this->logChannel, 'Skipped test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) );
76 /**
77 * A test suite started.
79 * @param PHPUnit_Framework_TestSuite $suite
80 * @since Method available since Release 2.2.0
82 public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
83 wfDebugLog( $this->logChannel, 'START suite ' . $suite->getName() );
86 /**
87 * A test suite ended.
89 * @param PHPUnit_Framework_TestSuite $suite
90 * @since Method available since Release 2.2.0
92 public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
93 wfDebugLog( $this->logChannel, 'END suite ' . $suite->getName() );
96 /**
97 * A test started.
99 * @param PHPUnit_Framework_Test $test
101 public function startTest( PHPUnit_Framework_Test $test ) {
102 wfDebugLog( $this->logChannel, 'Start test ' . $this->getTestName( $test ) );
106 * A test ended.
108 * @param PHPUnit_Framework_Test $test
109 * @param float $time
111 public function endTest( PHPUnit_Framework_Test $test, $time ) {
112 wfDebugLog( $this->logChannel, 'End test ' . $this->getTestName( $test ) );