From 1a189964bc2bfa3f0721fe149b6d9b8b9551cba0 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Wed, 11 May 2016 10:13:01 -0700 Subject: [PATCH] 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 --- tests/phpunit/DiscussionParserTest.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/phpunit/DiscussionParserTest.php b/tests/phpunit/DiscussionParserTest.php index 7b414958b..b8a51ed95 100644 --- a/tests/phpunit/DiscussionParserTest.php +++ b/tests/phpunit/DiscussionParserTest.php @@ -323,14 +323,20 @@ class EchoDiscussionParserTest extends MediaWikiTestCase { // Since we reset the $wgContLang global, reset the TitleParser service $services = MediaWikiServices::getInstance(); if ( is_callable( [ $services, 'getTitleParser' ] ) ) { - $this->setService( - 'TitleParser', - new MediaWikiTitleCodec( + // TODO: All of this should use $this->setService() + $services->resetServiceForTesting( 'TitleParser' ); + $services->redefineService( 'TitleParser', function () use ( $langObj ) { + global $wgLocalInterwikis; + return new MediaWikiTitleCodec( $langObj, 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.