update a few tests to use PHP 7.4 syntax

Bug: T261872
Change-Id: Ia573136f0ab90025a1588e9dfd5add081d9ffdae
This commit is contained in:
Ariel T. Glenn 2024-01-09 10:19:00 +02:00
parent db5f7689d4
commit 325ec96492
5 changed files with 11 additions and 23 deletions

View file

@ -37,9 +37,7 @@ class TestUserRegistry {
public static function getMutableTestUser( $testName, $groups = [], $userPrefix = null ) {
$id = self::getNextId();
$testUserName = "$testName $id";
if ( $userPrefix === null ) {
$userPrefix = "TestUser";
}
$userPrefix ??= "TestUser";
$testUser = new TestUser(
"$userPrefix $testName $id",
"Name $id",

View file

@ -103,10 +103,8 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
) {
global $wgRequest;
if ( $session === null ) {
// re-use existing global session by default
$session = $wgRequest->getSessionArray();
}
// re-use existing global session by default
$session ??= $wgRequest->getSessionArray();
$sessionObj = SessionManager::singleton()->getEmptySession();
@ -210,13 +208,11 @@ abstract class ApiTestCase extends MediaWikiLangTestCase {
}
protected static function getErrorFormatter() {
if ( self::$errorFormatter === null ) {
self::$errorFormatter = new ApiErrorFormatter(
new ApiResult( false ),
MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ),
'none'
);
}
self::$errorFormatter ??= new ApiErrorFormatter(
new ApiResult( false ),
MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ),
'none'
);
return self::$errorFormatter;
}

View file

@ -138,9 +138,7 @@ class RandomImageGenerator {
* @return string[]
*/
private function getRandomFilenames( $number, $extension = 'jpg', $dir = null ) {
if ( $dir === null ) {
$dir = getcwd();
}
$dir ??= getcwd();
$filenames = [];
$prefix = wfRandomString( 3 ) . '_' . gmdate( 'YmdHis' ) . '_';
foreach ( range( 1, $number ) as $offset ) {

View file

@ -64,9 +64,7 @@ class MessageCacheTest extends MediaWikiLangTestCase {
* @return RevisionRecord
*/
private function makePage( $title, $lang, $content = null ) {
if ( $content === null ) {
$content = $lang;
}
$content ??= $lang;
if ( $lang !== $this->getServiceContainer()->getContentLanguage()->getCode() ) {
$title = "$title/$lang";
}

View file

@ -142,9 +142,7 @@ class MediaWikiTitleCodecTest extends MediaWikiIntegrationTestCase {
public function testFormat( $namespace, $text, $fragment, $interwiki, $lang, $expected,
$normalized = null
) {
if ( $normalized === null ) {
$normalized = $expected;
}
$normalized ??= $expected;
$codec = $this->makeCodec( $lang );
$actual = $codec->formatTitle( $namespace, $text, $fragment, $interwiki );