Merge "Using ULS in Special:PageLanguage"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiPHPUnitTestListener.php
1 <?php
2
3 class MediaWikiPHPUnitTestListener extends PHPUnit_TextUI_ResultPrinter implements PHPUnit_Framework_TestListener {
4
5 /**
6 * @var string
7 */
8 protected $logChannel = 'PHPUnitCommand';
9
10 protected function getTestName( PHPUnit_Framework_Test $test ) {
11 $name = get_class( $test );
12
13 if ( $test instanceof PHPUnit_Framework_TestCase ) {
14 $name .= '::' . $test->getName( true );
15 }
16
17 return $name;
18 }
19
20 protected function getErrorName( Exception $exception ) {
21 $name = get_class( $exception );
22 $name = "[$name] " . $exception->getMessage();
23
24 return $name;
25 }
26
27 /**
28 * An error occurred.
29 *
30 * @param PHPUnit_Framework_Test $test
31 * @param Exception $e
32 * @param float $time
33 */
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 )
39 );
40 }
41
42 /**
43 * A failure occurred.
44 *
45 * @param PHPUnit_Framework_Test $test
46 * @param PHPUnit_Framework_AssertionFailedError $e
47 * @param float $time
48 */
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 )
56 );
57 }
58
59 /**
60 * Incomplete test.
61 *
62 * @param PHPUnit_Framework_Test $test
63 * @param Exception $e
64 * @param float $time
65 */
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 )
71 );
72 }
73
74 /**
75 * Skipped test.
76 *
77 * @param PHPUnit_Framework_Test $test
78 * @param Exception $e
79 * @param float $time
80 */
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 )
86 );
87 }
88
89 /**
90 * A test suite started.
91 *
92 * @param PHPUnit_Framework_TestSuite $suite
93 */
94 public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
95 parent::startTestSuite( $suite );
96 wfDebugLog( $this->logChannel, 'START suite ' . $suite->getName() );
97 }
98
99 /**
100 * A test suite ended.
101 *
102 * @param PHPUnit_Framework_TestSuite $suite
103 */
104 public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
105 parent::endTestSuite( $suite );
106 wfDebugLog( $this->logChannel, 'END suite ' . $suite->getName() );
107 }
108
109 /**
110 * A test started.
111 *
112 * @param PHPUnit_Framework_Test $test
113 */
114 public function startTest( PHPUnit_Framework_Test $test ) {
115 parent::startTest( $test );
116 wfDebugLog( $this->logChannel, 'Start test ' . $this->getTestName( $test ) );
117 }
118
119 /**
120 * A test ended.
121 *
122 * @param PHPUnit_Framework_Test $test
123 * @param float $time
124 */
125 public function endTest( PHPUnit_Framework_Test $test, $time ) {
126 parent::endTest( $test, $time );
127 wfDebugLog( $this->logChannel, 'End test ' . $this->getTestName( $test ) );
128 }
129 }