X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FMediaWikiIntegrationTestCase.php;h=82d359fb826c0ea8891864d052a40199e1077410;hb=72fa557f45ce6640bd13e82c7130ad7934d8c384;hp=e0418a8df0cd60a6800353b9baaea8708f3a96e0;hpb=7dd780846cf378c17a4d8a40e80b9e3f42818e44;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/MediaWikiIntegrationTestCase.php b/tests/phpunit/MediaWikiIntegrationTestCase.php index e0418a8df0..82d359fb82 100644 --- a/tests/phpunit/MediaWikiIntegrationTestCase.php +++ b/tests/phpunit/MediaWikiIntegrationTestCase.php @@ -586,6 +586,17 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $this->tmpFiles = array_merge( $this->tmpFiles, (array)$files ); } + private static function formatErrorLevel( $errorLevel ) { + switch ( gettype( $errorLevel ) ) { + case 'integer': + return '0x' . strtoupper( dechex( $errorLevel ) ); + case 'NULL': + return 'null'; + default: + throw new MWException( 'Unexpected error level type ' . gettype( $errorLevel ) ); + } + } + protected function tearDown() { global $wgRequest, $wgSQLMode; @@ -651,10 +662,10 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { if ( $phpErrorLevel !== $this->phpErrorLevel ) { ini_set( 'error_reporting', $this->phpErrorLevel ); - $oldHex = strtoupper( dechex( $this->phpErrorLevel ) ); - $newHex = strtoupper( dechex( $phpErrorLevel ) ); + $oldVal = self::formatErrorLevel( $this->phpErrorLevel ); + $newVal = self::formatErrorLevel( $phpErrorLevel ); $message = "PHP error_reporting setting was left dirty: " - . "was 0x$oldHex before test, 0x$newHex after test!"; + . "was $oldVal before test, $newVal after test!"; $this->fail( $message ); } @@ -719,7 +730,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $instantiator ); - self::resetLegacyGlobals(); + if ( $name === 'ContentLanguage' ) { + $this->setMwGlobals( [ 'wgContLang' => $this->localServices->getContentLanguage() ] ); + } } /** @@ -932,7 +945,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $this->localServices->resetServiceForTesting( $name, true ); } - self::resetLegacyGlobals(); + self::resetGlobalParser(); Language::clearCaches(); } @@ -986,7 +999,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $newInstance->redefineService( $name, $callback ); } - self::resetLegacyGlobals(); + self::resetGlobalParser(); return $newInstance; } @@ -1053,7 +1066,7 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { MediaWikiServices::forceGlobalInstance( $newServices ); - self::resetLegacyGlobals(); + self::resetGlobalParser(); return $newServices; } @@ -1083,29 +1096,24 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { MediaWikiServices::forceGlobalInstance( self::$originalServices ); $currentServices->destroy(); - self::resetLegacyGlobals(); + self::resetGlobalParser(); return true; } /** - * If legacy globals such as $wgParser or $wgContLang have been unstubbed, replace them with - * fresh ones so they pick up any config changes. They're deprecated, but we still support them - * for now. + * If $wgParser has been unstubbed, replace it with a fresh one so it picks up any config + * changes. $wgParser is deprecated, but we still support it for now. */ - private static function resetLegacyGlobals() { + private static function resetGlobalParser() { // phpcs:ignore MediaWiki.Usage.DeprecatedGlobalVariables.Deprecated$wgParser - global $wgParser, $wgContLang; - if ( !( $wgParser instanceof StubObject ) ) { - $wgParser = new StubObject( 'wgParser', function () { - return MediaWikiServices::getInstance()->getParser(); - } ); - } - if ( !( $wgContLang instanceof StubObject ) ) { - $wgContlang = new StubObject( 'wgContLang', function () { - return MediaWikiServices::getInstance()->getContLang(); - } ); + global $wgParser; + if ( $wgParser instanceof StubObject ) { + return; } + $wgParser = new StubObject( 'wgParser', function () { + return MediaWikiServices::getInstance()->getParser(); + } ); } /** @@ -1118,8 +1126,6 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { } /** - * @deprecated since 1.34, use setMwGlobals( 'wgLanguageCode' ) to set the code or - * setService( 'ContentLanguage' ) to set an object * @since 1.27 * @param string|Language $lang */ @@ -1129,7 +1135,10 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase { $this->setService( 'ContentLanguage', $lang ); $this->setMwGlobals( 'wgLanguageCode', $lang->getCode() ); } else { - $this->setMwGlobals( 'wgLanguageCode', $lang ); + $this->setMwGlobals( [ + 'wgLanguageCode' => $lang, + 'wgContLang' => Language::factory( $lang ), + ] ); } }