Do not insert page titles into querycache.qc_value
[lhc/web/wiklou.git] / tests / phpunit / MediaWikiPHPUnitTestListener.php
1 <?php
2
3 class MediaWikiPHPUnitTestListener extends PHPUnit_Framework_BaseTestListener {
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 wfDebugLog(
36 $this->logChannel,
37 'ERROR in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
38 );
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,
49 PHPUnit_Framework_AssertionFailedError $e, $time
50 ) {
51 wfDebugLog(
52 $this->logChannel,
53 'FAILURE in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
54 );
55 }
56
57 /**
58 * Incomplete test.
59 *
60 * @param PHPUnit_Framework_Test $test
61 * @param Exception $e
62 * @param float $time
63 */
64 public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
65 wfDebugLog(
66 $this->logChannel,
67 'Incomplete test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
68 );
69 }
70
71 /**
72 * Skipped test.
73 *
74 * @param PHPUnit_Framework_Test $test
75 * @param Exception $e
76 * @param float $time
77 */
78 public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
79 wfDebugLog(
80 $this->logChannel,
81 'Skipped test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
82 );
83 }
84
85 /**
86 * A test suite started.
87 *
88 * @param PHPUnit_Framework_TestSuite $suite
89 */
90 public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
91 wfDebugLog( $this->logChannel, 'START suite ' . $suite->getName() );
92 }
93
94 /**
95 * A test suite ended.
96 *
97 * @param PHPUnit_Framework_TestSuite $suite
98 */
99 public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
100 wfDebugLog( $this->logChannel, 'END suite ' . $suite->getName() );
101 }
102
103 /**
104 * A test started.
105 *
106 * @param PHPUnit_Framework_Test $test
107 */
108 public function startTest( PHPUnit_Framework_Test $test ) {
109 Hooks::run( 'MediaWikiPHPUnitTest::startTest', [ $test ] );
110 wfDebugLog( $this->logChannel, 'Start test ' . $this->getTestName( $test ) );
111 }
112
113 /**
114 * A test ended.
115 *
116 * @param PHPUnit_Framework_Test $test
117 * @param float $time
118 */
119 public function endTest( PHPUnit_Framework_Test $test, $time ) {
120 Hooks::run( 'MediaWikiPHPUnitTest::endTest', [ $test, $time ] );
121 wfDebugLog( $this->logChannel, 'End test ' . $this->getTestName( $test ) );
122 }
123 }