Page MenuHomePhabricator

PHPUnit dataProviders access the main DB, not the cloned database
Open, Needs TriagePublic

Description

Seen while debugging test failures for https://gerrit.wikimedia.org/r/c/mediawiki/core/+/813209.

Modify extensions/Wikibase/repo/tests/phpunit/includes/Hooks/HtmlPageLinkRendererEndHookHandlerTest.php to query user names for your wiki. You'd expect to just see UTSysop, but instead the full list of user names on your local wiki is output: php tests/phpunit/phpunit.php extensions/Wikibase/repo/tests/phpunit/includes/Hooks/HtmlPageLinkRendererEndHookHandlerTest.php --filter=testExtractForeignIdString

<?php
/**
 * @dataProvider linkTargetProvider
 */
public function testExtractForeignIdString( $linkTarget, $expectedOutput ) {
	$wrapper = TestingAccessWrapper::newFromObject( $this->newInstance() );
	$output = $wrapper->extractForeignIdString( $linkTarget );
	$this->assertSame( $expectedOutput, $output );
}

public function linkTargetProvider() {
	$db = wfGetDB( DB_PRIMARY );
	$selectQuery = new SelectQueryBuilder( $db );
	$result = $selectQuery
		->table( 'user' )
		->field( 'user_name' )
		->fetchFieldValues();
	var_dump( $result );
	return [
		'NS=MAIN, title=null' => [ Title::makeTitle( NS_MAIN, null ), null ], // T260853
		'NS=SPECIAL, title=null' => [ Title::makeTitle( NS_SPECIAL, null ), null ],
		'NS=SPECIAL, title=EntityPage/Q123' => [ Title::newFromTextThrow( 'Special:EntityPage/Q123' ), 'Q123' ],
		// One of the defaults from MediaWiki's maintenance/interwiki.list (but not Wikidata, as this might be the local test wiki name)
		'NS=MAIN, title=Special:EntityPage/Q123' => [ Title::newFromTextThrow( 'metawikimedia:Special:EntityPage/Q123' ), 'Q123' ],
	];
}

Note that with https://gerrit.wikimedia.org/r/c/mediawiki/core/+/813209, access to the main DB is prevented, and the interwiki table is empty, which is why the test fails.

Event Timeline

Change 813240 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[mediawiki/extensions/Wikibase@master] HtmlPageLinkRendererEndHookHandlerTest: Populate interwiki table

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

Change 804552 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[mediawiki/extensions/VisualEditor@master] ApiVisualEditorTest: Set Database annotation and $tablesUsed

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

Change 804552 merged by jenkins-bot:

[mediawiki/extensions/VisualEditor@master] ApiVisualEditorTest: Set Database annotation and $tablesUsed

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

Change 813240 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] HtmlPageLinkRendererEndHookHandlerTest: Populate interwiki table

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

The problem seems more that the data provider is not static and doing some expensive things, see T332865 for more about non-static data provider.