MediaWiki  1.33.0
MediaWikiPHPUnitTestListener.php
Go to the documentation of this file.
1 <?php
2 
3 class MediaWikiPHPUnitTestListener extends PHPUnit_Framework_BaseTestListener {
4 
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 
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 
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 
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 
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 
90  public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) {
91  wfDebugLog( $this->logChannel, 'START suite ' . $suite->getName() );
92  }
93 
99  public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) {
100  wfDebugLog( $this->logChannel, 'END suite ' . $suite->getName() );
101  }
102 
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 
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 }
MediaWikiPHPUnitTestListener\startTest
startTest(PHPUnit_Framework_Test $test)
A test started.
Definition: MediaWikiPHPUnitTestListener.php:108
MediaWikiPHPUnitTestListener\addSkippedTest
addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
Skipped test.
Definition: MediaWikiPHPUnitTestListener.php:78
MediaWikiPHPUnitTestListener\$logChannel
string $logChannel
Definition: MediaWikiPHPUnitTestListener.php:8
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:1043
MediaWikiPHPUnitTestListener\addError
addError(PHPUnit_Framework_Test $test, Exception $e, $time)
An error occurred.
Definition: MediaWikiPHPUnitTestListener.php:34
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:35
MediaWikiPHPUnitTestListener\endTestSuite
endTestSuite(PHPUnit_Framework_TestSuite $suite)
A test suite ended.
Definition: MediaWikiPHPUnitTestListener.php:99
MediaWikiPHPUnitTestListener\addFailure
addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
A failure occurred.
Definition: MediaWikiPHPUnitTestListener.php:48
MediaWikiPHPUnitTestListener
Definition: MediaWikiPHPUnitTestListener.php:3
MediaWikiPHPUnitTestListener\startTestSuite
startTestSuite(PHPUnit_Framework_TestSuite $suite)
A test suite started.
Definition: MediaWikiPHPUnitTestListener.php:90
MediaWikiPHPUnitTestListener\addIncompleteTest
addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
Incomplete test.
Definition: MediaWikiPHPUnitTestListener.php:64
MediaWikiPHPUnitTestListener\getTestName
getTestName(PHPUnit_Framework_Test $test)
Definition: MediaWikiPHPUnitTestListener.php:10
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:271
$e
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2162
$time
see documentation in includes Linker php for Linker::makeImageLink & $time
Definition: hooks.txt:1802
MediaWikiPHPUnitTestListener\endTest
endTest(PHPUnit_Framework_Test $test, $time)
A test ended.
Definition: MediaWikiPHPUnitTestListener.php:119
Hooks\run
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
MediaWikiPHPUnitTestListener\getErrorName
getErrorName(Exception $exception)
Definition: MediaWikiPHPUnitTestListener.php:20