A terminating line break has not been required in wfDebug() since 2014, however no migration was done. Some of these line breaks found their way into LoggerInterface::debug() calls, where they mess up the formatting of the debug log. So, remove terminating line breaks from wfDebug() and LoggerInterface::debug() calls. Also: * Fix the stripping of leading line breaks from the log header emitted by Setup.php. This feature, accidentally broken in 2014, allows requests to be distinguished in the log file. * Avoid using the global variable $self. * Move the logging of the client IP back to Setup.php. It was moved to WebRequest in the hopes that it would not always be needed, however $wgRequest->getIP() is now called unconditionally a few lines up in Setup.php. This means that it is put in its proper place after the "start request" message. * Wrap the log header code in a closure so that variables like $name do not leak into global scope. * In Linker.php, remove a few instances of an unnecessary second parameter to wfDebug(). Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
78 lines
2 KiB
PHP
78 lines
2 KiB
PHP
<?php
|
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
/**
|
|
* Helping class to run tests using a clean language instance.
|
|
*
|
|
* This is intended for the MediaWiki language class tests under
|
|
* tests/phpunit/languages.
|
|
*
|
|
* Before each tests, a new language object is build which you
|
|
* can retrieve in your test using the $this->getLang() method:
|
|
*
|
|
* @par Using the crafted language object:
|
|
* @code
|
|
* function testHasLanguageObject() {
|
|
* $langObject = $this->getLang();
|
|
* $this->assertInstanceOf( 'LanguageFoo',
|
|
* $langObject
|
|
* );
|
|
* }
|
|
* @endcode
|
|
*/
|
|
abstract class LanguageClassesTestCase extends MediaWikiTestCase {
|
|
/**
|
|
* Internal language object
|
|
*
|
|
* A new object is created before each tests thanks to PHPUnit
|
|
* setUp() method, it is deleted after each test too. To get
|
|
* this object you simply use the getLang method.
|
|
*
|
|
* You must have setup a language code first. See $LanguageClassCode
|
|
* @code
|
|
* function testWeAreTheChampions() {
|
|
* $this->getLang(); # language object
|
|
* }
|
|
* @endcode
|
|
*/
|
|
private $languageObject;
|
|
|
|
/**
|
|
* @return Language
|
|
*/
|
|
protected function getLang() {
|
|
return $this->languageObject;
|
|
}
|
|
|
|
/**
|
|
* Create a new language object before each test.
|
|
*/
|
|
protected function setUp() : void {
|
|
parent::setUp();
|
|
$found = preg_match( '/Language(.+)Test/', static::class, $m );
|
|
if ( $found ) {
|
|
# Normalize language code since classes uses underscores
|
|
$m[1] = strtolower( str_replace( '_', '-', $m[1] ) );
|
|
} else {
|
|
# Fallback to english language
|
|
$m[1] = 'en';
|
|
wfDebug(
|
|
__METHOD__ . ' could not extract a language name '
|
|
. 'out of ' . static::class . " failling back to 'en'"
|
|
);
|
|
}
|
|
// @todo validate $m[1] which should be a valid language code
|
|
$this->languageObject = MediaWikiServices::getInstance()->getLanguageFactory()
|
|
->getLanguage( $m[1] );
|
|
}
|
|
|
|
/**
|
|
* Delete the internal language object so each test start
|
|
* out with a fresh language instance.
|
|
*/
|
|
protected function tearDown() : void {
|
|
unset( $this->languageObject );
|
|
parent::tearDown();
|
|
}
|
|
}
|