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 );
37  wfDebugLog(
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 );
54  wfDebugLog(
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 );
69  wfDebugLog(
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 );
84  wfDebugLog(
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 }
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1795
MediaWikiPHPUnitTestListener\startTest
startTest(PHPUnit_Framework_Test $test)
A test started.
Definition: MediaWikiPHPUnitTestListener.php:115
MediaWikiPHPUnitTestListener\addSkippedTest
addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
Skipped test.
Definition: MediaWikiPHPUnitTestListener.php:82
MediaWikiPHPUnitTestListener\$logChannel
string $logChannel
Definition: MediaWikiPHPUnitTestListener.php:9
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1087
MediaWikiPHPUnitTestListener\addError
addError(PHPUnit_Framework_Test $test, Exception $e, $time)
An error occurred.
Definition: MediaWikiPHPUnitTestListener.php:35
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
MediaWikiPHPUnitTestListener\endTestSuite
endTestSuite(PHPUnit_Framework_TestSuite $suite)
A test suite ended.
Definition: MediaWikiPHPUnitTestListener.php:105
MediaWikiPHPUnitTestListener\addFailure
addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
A failure occurred.
Definition: MediaWikiPHPUnitTestListener.php:50
MediaWikiPHPUnitTestListener
Definition: MediaWikiPHPUnitTestListener.php:4
MediaWikiPHPUnitTestListener\startTestSuite
startTestSuite(PHPUnit_Framework_TestSuite $suite)
A test suite started.
Definition: MediaWikiPHPUnitTestListener.php:95
MediaWikiPHPUnitTestListener\addIncompleteTest
addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
Incomplete test.
Definition: MediaWikiPHPUnitTestListener.php:67
MediaWikiPHPUnitTestListener\getTestName
getTestName(PHPUnit_Framework_Test $test)
Definition: MediaWikiPHPUnitTestListener.php:11
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:302
MediaWikiPHPUnitTestListener\endTest
endTest(PHPUnit_Framework_Test $test, $time)
A test ended.
Definition: MediaWikiPHPUnitTestListener.php:126
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2171
MediaWikiPHPUnitTestListener\getErrorName
getErrorName(Exception $exception)
Definition: MediaWikiPHPUnitTestListener.php:21