Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / tests / phpunit / MediaWikiPHPUnitTestListener.php
blob08463f1259d0d897c4dccb36df91ac1263c6375e
1 <?php
3 class MediaWikiPHPUnitTestListener extends PHPUnit_TextUI_ResultPrinter implements PHPUnit_Framework_TestListener {
5 /**
6 * @var string
7 */
8 protected $logChannel = 'PHPUnitCommand';
10 protected function getTestName( PHPUnit_Framework_Test $test ) {
11 $name = get_class( $test );
13 if ( $test instanceof PHPUnit_Framework_TestCase ) {
14 $name .= '::' . $test->getName( true );
17 return $name;
20 protected function getErrorName( Exception $exception ) {
21 $name = get_class( $exception );
22 $name = "[$name] " . $exception->getMessage();
24 return $name;
27 /**
28 * An error occurred.
30 * @param PHPUnit_Framework_Test $test
31 * @param Exception $e
32 * @param float $time
34 public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
35 parent::addError( $test, $e, $time );
36 wfDebugLog(
37 $this->logChannel,
38 'ERROR in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
42 /**
43 * A failure occurred.
45 * @param PHPUnit_Framework_Test $test
46 * @param PHPUnit_Framework_AssertionFailedError $e
47 * @param float $time
49 public function addFailure( PHPUnit_Framework_Test $test,
50 PHPUnit_Framework_AssertionFailedError $e, $time
51 ) {
52 parent::addFailure( $test, $e, $time );
53 wfDebugLog(
54 $this->logChannel,
55 'FAILURE in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
59 /**
60 * Incomplete test.
62 * @param PHPUnit_Framework_Test $test
63 * @param Exception $e
64 * @param float $time
66 public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
67 parent::addIncompleteTest( $test, $e, $time );
68 wfDebugLog(
69 $this->logChannel,
70 'Incomplete test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
74 /**
75 * Skipped test.
77 * @param PHPUnit_Framework_Test $test
78 * @param Exception $e
79 * @param float $time
81 public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
82 parent::addSkippedTest( $test, $e, $time );
83 wfDebugLog(
84 $this->logChannel,
85 'Skipped test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
89 /**
90 * A test suite started.
92 * @param PHPUnit_Framework_TestSuite $suite
94 public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
95 parent::startTestSuite( $suite );
96 wfDebugLog( $this->logChannel, 'START suite ' . $suite->getName() );
99 /**
100 * A test suite ended.
102 * @param PHPUnit_Framework_TestSuite $suite
104 public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
105 parent::endTestSuite( $suite );
106 wfDebugLog( $this->logChannel, 'END suite ' . $suite->getName() );
110 * A test started.
112 * @param PHPUnit_Framework_Test $test
114 public function startTest( PHPUnit_Framework_Test $test ) {
115 parent::startTest( $test );
116 wfDebugLog( $this->logChannel, 'Start test ' . $this->getTestName( $test ) );
120 * A test ended.
122 * @param PHPUnit_Framework_Test $test
123 * @param float $time
125 public function endTest( PHPUnit_Framework_Test $test, $time ) {
126 parent::endTest( $test, $time );
127 wfDebugLog( $this->logChannel, 'End test ' . $this->getTestName( $test ) );