Reset the TitleParser service without messing up the database

Calling MediaWikiTestCase::setService() appears to mess up the database,
so just reset it directly with MediaWikiServices, and tear it down to
avoid leaking any state.

Change-Id: Ibfd0a7f98f50506cd8402f966682f320bf715c8a
This commit is contained in:
Kunal Mehta 2016-05-11 10:13:01 -07:00
parent 1baa72cf08
commit 1a189964bc

View file

@ -323,14 +323,20 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
// Since we reset the $wgContLang global, reset the TitleParser service // Since we reset the $wgContLang global, reset the TitleParser service
$services = MediaWikiServices::getInstance(); $services = MediaWikiServices::getInstance();
if ( is_callable( [ $services, 'getTitleParser' ] ) ) { if ( is_callable( [ $services, 'getTitleParser' ] ) ) {
$this->setService( // TODO: All of this should use $this->setService()
'TitleParser', $services->resetServiceForTesting( 'TitleParser' );
new MediaWikiTitleCodec( $services->redefineService( 'TitleParser', function () use ( $langObj ) {
global $wgLocalInterwikis;
return new MediaWikiTitleCodec(
$langObj, $langObj,
new GenderCache(), new GenderCache(),
$services->getMainConfig()->get( 'LocalInterwikis' ) $wgLocalInterwikis
) );
); } );
// Cleanup
$lock = new ScopedCallback( function() use ( $services ) {
$services->resetServiceForTesting( 'TitleParser' );
} );
} }
// pages to be created: templates may be used to ping users (e.g. // pages to be created: templates may be used to ping users (e.g.