MediaWiki REL1_31
MediaWikiPHPUnitTestListener.php
Go to the documentation of this file.
1<?php
2
4 extends PHPUnit_TextUI_ResultPrinter implements PHPUnit_Framework_TestListener {
5
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
35 public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) {
36 parent::addError( $test, $e, $time );
38 $this->logChannel,
39 'ERROR in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
40 );
41 }
42
50 public function addFailure( PHPUnit_Framework_Test $test,
51 PHPUnit_Framework_AssertionFailedError $e, $time
52 ) {
53 parent::addFailure( $test, $e, $time );
55 $this->logChannel,
56 'FAILURE in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
57 );
58 }
59
67 public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
68 parent::addIncompleteTest( $test, $e, $time );
70 $this->logChannel,
71 'Incomplete test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
72 );
73 }
74
82 public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) {
83 parent::addSkippedTest( $test, $e, $time );
85 $this->logChannel,
86 'Skipped test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e )
87 );
88 }
89
95 public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
96 parent::startTestSuite( $suite );
97 wfDebugLog( $this->logChannel, 'START suite ' . $suite->getName() );
98 }
99
105 public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
106 parent::endTestSuite( $suite );
107 wfDebugLog( $this->logChannel, 'END suite ' . $suite->getName() );
108 }
109
115 public function startTest( PHPUnit_Framework_Test $test ) {
116 parent::startTest( $test );
117 wfDebugLog( $this->logChannel, 'Start test ' . $this->getTestName( $test ) );
118 }
119
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}
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
endTest(PHPUnit_Framework_Test $test, $time)
A test ended.
addError(PHPUnit_Framework_Test $test, Exception $e, $time)
An error occurred.
getTestName(PHPUnit_Framework_Test $test)
addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
Skipped test.
startTest(PHPUnit_Framework_Test $test)
A test started.
startTestSuite(PHPUnit_Framework_TestSuite $suite)
A test suite started.
endTestSuite(PHPUnit_Framework_TestSuite $suite)
A test suite ended.
addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
A failure occurred.
addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
Incomplete test.
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition hooks.txt:1795
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:302
returning false will NOT prevent logging $e
Definition hooks.txt:2176