Merge "Handle conflicting image format options in predictable way."
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiPHPUnitTestListener.php
1 <?php
2 class MediaWikiPHPUnitTestListener implements PHPUnit_Framework_TestListener {
3
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( $this->logChannel, 'ERROR in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) );
39 }
40
41 /**
42 * A failure occurred.
43 *
44 * @param PHPUnit_Framework_Test $test
45 * @param PHPUnit_Framework_AssertionFailedError $e
46 * @param float $time
47 */
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 ) );
50 }
51
52 /**
53 * Incomplete test.
54 *
55 * @param PHPUnit_Framework_Test $test
56 * @param Exception $e
57 * @param float $time
58 */
59 public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
60 wfDebugLog( $this->logChannel, 'Incomplete test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) );
61 }
62
63 /**
64 * Skipped test.
65 *
66 * @param PHPUnit_Framework_Test $test
67 * @param Exception $e
68 * @param float $time
69 *
70 * @since Method available since Release 3.0.0
71 */
72 public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
73 wfDebugLog( $this->logChannel, 'Skipped test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) );
74 }
75
76 /**
77 * A test suite started.
78 *
79 * @param PHPUnit_Framework_TestSuite $suite
80 * @since Method available since Release 2.2.0
81 */
82 public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
83 wfDebugLog( $this->logChannel, 'START suite ' . $suite->getName() );
84 }
85
86 /**
87 * A test suite ended.
88 *
89 * @param PHPUnit_Framework_TestSuite $suite
90 * @since Method available since Release 2.2.0
91 */
92 public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
93 wfDebugLog( $this->logChannel, 'END suite ' . $suite->getName() );
94 }
95
96 /**
97 * A test started.
98 *
99 * @param PHPUnit_Framework_Test $test
100 */
101 public function startTest( PHPUnit_Framework_Test $test ) {
102 wfDebugLog( $this->logChannel, 'Start test ' . $this->getTestName( $test ) );
103 }
104
105 /**
106 * A test ended.
107 *
108 * @param PHPUnit_Framework_Test $test
109 * @param float $time
110 */
111 public function endTest( PHPUnit_Framework_Test $test, $time ) {
112 wfDebugLog( $this->logChannel, 'End test ' . $this->getTestName( $test ) );
113 }
114 }