Merge "Unsetting the email address for a user when the email address is invalidated."
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiPHPUnitTestListener.php
1 <?php
2
3 class MediaWikiPHPUnitTestListener implements PHPUnit_Framework_TestListener {
4 /**
5 * @var string
6 */
7 protected $logChannel;
8
9 public function __construct( $logChannel ) {
10 $this->logChannel = $logChannel;
11 }
12
13 protected function getTestName( PHPUnit_Framework_Test $test ) {
14 $name = get_class( $test );
15
16 if ( $test instanceof PHPUnit_Framework_TestCase ) {
17 $name .= '::' . $test->getName( true );
18 }
19
20 return $name;
21 }
22
23 protected function getErrorName( Exception $exception ) {
24 $name = get_class( $exception );
25 $name = "[$name] " . $exception->getMessage();
26
27 return $name;
28 }
29
30 /**
31 * An error occurred.
32 *
33 * @param PHPUnit_Framework_Test $test
34 * @param Exception $e
35 * @param float $time
36 */
37 public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
38 wfDebugLog(
39 $this->logChannel,
40 'ERROR in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
41 );
42 }
43
44 /**
45 * A failure occurred.
46 *
47 * @param PHPUnit_Framework_Test $test
48 * @param PHPUnit_Framework_AssertionFailedError $e
49 * @param float $time
50 */
51 public function addFailure( PHPUnit_Framework_Test $test,
52 PHPUnit_Framework_AssertionFailedError $e, $time
53 ) {
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 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 wfDebugLog(
83 $this->logChannel,
84 'Skipped test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
85 );
86 }
87
88 /**
89 * A test suite started.
90 *
91 * @param PHPUnit_Framework_TestSuite $suite
92 */
93 public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
94 wfDebugLog( $this->logChannel, 'START suite ' . $suite->getName() );
95 }
96
97 /**
98 * A test suite ended.
99 *
100 * @param PHPUnit_Framework_TestSuite $suite
101 */
102 public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
103 wfDebugLog( $this->logChannel, 'END suite ' . $suite->getName() );
104 }
105
106 /**
107 * A test started.
108 *
109 * @param PHPUnit_Framework_Test $test
110 */
111 public function startTest( PHPUnit_Framework_Test $test ) {
112 wfDebugLog( $this->logChannel, 'Start test ' . $this->getTestName( $test ) );
113 }
114
115 /**
116 * A test ended.
117 *
118 * @param PHPUnit_Framework_Test $test
119 * @param float $time
120 */
121 public function endTest( PHPUnit_Framework_Test $test, $time ) {
122 wfDebugLog( $this->logChannel, 'End test ' . $this->getTestName( $test ) );
123 }
124 }