Merge "Add missing return types to User::getOption()"
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiPHPUnitTestListener.php
1 <?php
2
3 class MediaWikiPHPUnitTestListener
4 extends PHPUnit_TextUI_ResultPrinter implements PHPUnit_Framework_TestListener {
5
6 /**
7 * @var string
8 */
9 protected $logChannel = 'PHPUnitCommand';
10
11 protected function getTestName( PHPUnit_Framework_Test $test ) {
12 $name = get_class( $test );
13
14 if ( $test instanceof PHPUnit\Framework\TestCase ) {
15 $name .= '::' . $test->getName( true );
16 }
17
18 return $name;
19 }
20
21 protected function getErrorName( Exception $exception ) {
22 $name = get_class( $exception );
23 $name = "[$name] " . $exception->getMessage();
24
25 return $name;
26 }
27
28 /**
29 * An error occurred.
30 *
31 * @param PHPUnit_Framework_Test $test
32 * @param Exception $e
33 * @param float $time
34 */
35 public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
36 parent::addError( $test, $e, $time );
37 wfDebugLog(
38 $this->logChannel,
39 'ERROR in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
40 );
41 }
42
43 /**
44 * A failure occurred.
45 *
46 * @param PHPUnit_Framework_Test $test
47 * @param PHPUnit_Framework_AssertionFailedError $e
48 * @param float $time
49 */
50 public function addFailure( PHPUnit_Framework_Test $test,
51 PHPUnit_Framework_AssertionFailedError $e, $time
52 ) {
53 parent::addFailure( $test, $e, $time );
54 wfDebugLog(
55 $this->logChannel,
56 'FAILURE in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
57 );
58 }
59
60 /**
61 * Incomplete test.
62 *
63 * @param PHPUnit_Framework_Test $test
64 * @param Exception $e
65 * @param float $time
66 */
67 public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
68 parent::addIncompleteTest( $test, $e, $time );
69 wfDebugLog(
70 $this->logChannel,
71 'Incomplete test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
72 );
73 }
74
75 /**
76 * Skipped test.
77 *
78 * @param PHPUnit_Framework_Test $test
79 * @param Exception $e
80 * @param float $time
81 */
82 public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
83 parent::addSkippedTest( $test, $e, $time );
84 wfDebugLog(
85 $this->logChannel,
86 'Skipped test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
87 );
88 }
89
90 /**
91 * A test suite started.
92 *
93 * @param PHPUnit_Framework_TestSuite $suite
94 */
95 public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
96 parent::startTestSuite( $suite );
97 wfDebugLog( $this->logChannel, 'START suite ' . $suite->getName() );
98 }
99
100 /**
101 * A test suite ended.
102 *
103 * @param PHPUnit_Framework_TestSuite $suite
104 */
105 public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
106 parent::endTestSuite( $suite );
107 wfDebugLog( $this->logChannel, 'END suite ' . $suite->getName() );
108 }
109
110 /**
111 * A test started.
112 *
113 * @param PHPUnit_Framework_Test $test
114 */
115 public function startTest( PHPUnit_Framework_Test $test ) {
116 parent::startTest( $test );
117 wfDebugLog( $this->logChannel, 'Start test ' . $this->getTestName( $test ) );
118 }
119
120 /**
121 * A test ended.
122 *
123 * @param PHPUnit_Framework_Test $test
124 * @param float $time
125 */
126 public function endTest( PHPUnit_Framework_Test $test, $time ) {
127 parent::endTest( $test, $time );
128 wfDebugLog( $this->logChannel, 'End test ' . $this->getTestName( $test ) );
129 }
130 }