Page MenuHomePhabricator

Using null as an array offset is deprecated, use an empty string instead in LanguageCodeTest::testReplaceDeprecatedCodes
Closed, ResolvedPublic

Description

https://integration.wikimedia.org/ci/job/quibble-for-mediawiki-core-vendor-mysql-php85/3/consoleFull

13:59:58 231) MediaWiki\Tests\Unit\Language\LanguageCodeTest::testReplaceDeprecatedCodes
13:59:58 Using null as an array offset is deprecated, use an empty string instead
13:59:58 
13:59:58 /workspace/src/includes/Language/LanguageCode.php:185
13:59:58 /workspace/src/tests/phpunit/unit/includes/Language/LanguageCodeTest.php:52

Event Timeline

I don't know if we hit this at runtime, but a test that passes null to something that is documented as needing a string...

	public function testReplaceDeprecatedCodes() {
		$this->assertEquals( 'gsw', LanguageCode::replaceDeprecatedCodes( 'als' ) );
		$this->assertEquals( 'gsw', LanguageCode::replaceDeprecatedCodes( 'gsw' ) );
		$this->assertNull( LanguageCode::replaceDeprecatedCodes( null ) );
	}
	/**
	 * Replace deprecated language codes that were used in previous
	 * versions of MediaWiki to up-to-date, current language codes.
	 * Other values will be returned unchanged.
	 *
	 * @param string $code Old language code
	 * @return string New language code
	 *
	 * @since 1.30
	 */
	public static function replaceDeprecatedCodes( $code ) {
		return self::DEPRECATED_LANGUAGE_CODE_MAPPING[$code] ?? $code;
	}

It also says "Other values will be returned unchanged.", so null could be okay as well.

Since 55ecf3e215a25e581380b00f86af21eb26fd49f1

It also says "Other values will be returned unchanged.", so null could be okay as well.

Well, 'other value' means other code (those not deprecated, hence not in the mapping). Not the value type. The function takes only strings.

Change #1222706 had a related patch set uploaded (by Ammarpad; author: Ammarpad):

[mediawiki/core@master] LanguageCodeTest: Remove unnecessary null assertion

https://gerrit.wikimedia.org/r/1222706

Change #1222706 merged by jenkins-bot:

[mediawiki/core@master] LanguageCodeTest: Remove unnecessary null assertion

https://gerrit.wikimedia.org/r/1222706

Ammarpad claimed this task.

Change #1222723 had a related patch set uploaded (by Reedy; author: Ammarpad):

[mediawiki/core@REL1_44] LanguageCodeTest: Remove unnecessary null assertion

https://gerrit.wikimedia.org/r/1222723

Change #1222724 had a related patch set uploaded (by Reedy; author: Ammarpad):

[mediawiki/core@REL1_45] LanguageCodeTest: Remove unnecessary null assertion

https://gerrit.wikimedia.org/r/1222724

Change #1222725 had a related patch set uploaded (by Reedy; author: Ammarpad):

[mediawiki/core@REL1_43] LanguageCodeTest: Remove unnecessary null assertion

https://gerrit.wikimedia.org/r/1222725

Change #1222725 merged by jenkins-bot:

[mediawiki/core@REL1_43] LanguageCodeTest: Remove unnecessary null assertion

https://gerrit.wikimedia.org/r/1222725

Change #1222723 merged by jenkins-bot:

[mediawiki/core@REL1_44] LanguageCodeTest: Remove unnecessary null assertion

https://gerrit.wikimedia.org/r/1222723

Change #1222724 merged by jenkins-bot:

[mediawiki/core@REL1_45] LanguageCodeTest: Remove unnecessary null assertion

https://gerrit.wikimedia.org/r/1222724