57 $oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
59 $this->assertInstanceOf(
'MediaWiki\\MediaWikiServices', $oldServices );
60 $this->assertNotSame( $oldServices, $newServices );
62 $theServices = MediaWikiServices::getInstance();
63 $this->assertSame( $theServices, $newServices );
65 MediaWikiServices::forceGlobalInstance( $oldServices );
67 $theServices = MediaWikiServices::getInstance();
68 $this->assertSame( $theServices, $oldServices );
73 $oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
75 $service1 = $this->createMock( SalvageableService::class );
76 $service1->expects( $this->never() )
77 ->method(
'salvage' );
79 $newServices->defineService(
81 function () use ( $service1 ) {
87 $newServices->getService(
'Test' );
89 MediaWikiServices::resetGlobalInstance( $this->
newTestConfig() );
90 $theServices = MediaWikiServices::getInstance();
94 $theServices->getService(
'Test' ),
95 'service definition should survive reset'
98 $this->assertNotSame( $theServices, $newServices );
99 $this->assertNotSame( $theServices, $oldServices );
101 MediaWikiServices::forceGlobalInstance( $oldServices );
106 $oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
108 $service1 = $this->createMock( SalvageableService::class );
109 $service1->expects( $this->never() )
110 ->method(
'salvage' );
112 $service2 = $this->createMock( SalvageableService::class );
113 $service2->expects( $this->once() )
114 ->method(
'salvage' )
118 $instantiatorReturnValues = [
123 $newServices->defineService(
125 function () use ( &$instantiatorReturnValues ) {
126 return array_shift( $instantiatorReturnValues );
131 $newServices->getService(
'Test' );
133 MediaWikiServices::resetGlobalInstance( $this->
newTestConfig(),
'quick' );
134 $theServices = MediaWikiServices::getInstance();
136 $this->assertSame( $service2, $theServices->getService(
'Test' ) );
138 $this->assertNotSame( $theServices, $newServices );
139 $this->assertNotSame( $theServices, $oldServices );
141 MediaWikiServices::forceGlobalInstance( $oldServices );
146 $oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
148 $lbFactory = $this->getMockBuilder(
'LBFactorySimple' )
149 ->disableOriginalConstructor()
152 $newServices->redefineService(
153 'DBLoadBalancerFactory',
154 function () use ( $lbFactory ) {
160 $newServices->getService(
'DBLoadBalancerFactory' );
162 MediaWikiServices::disableStorageBackend();
165 MediaWikiServices::getInstance()->getService(
'DBLoadBalancerFactory' );
166 $this->fail(
'DBLoadBalancerFactory should have been disabled' );
170 }
catch ( Throwable $ex ) {
171 $this->fail(
'ServiceDisabledException expected, caught ' . get_class( $ex ) );
174 MediaWikiServices::forceGlobalInstance( $oldServices );
175 $newServices->destroy();
180 $oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
182 $service1 = $this->createMock( DestructibleService::class );
183 $service1->expects( $this->once() )
184 ->method(
'destroy' );
186 $service2 = $this->createMock( DestructibleService::class );
187 $service2->expects( $this->never() )
188 ->method(
'destroy' );
191 $instantiatorReturnValues = [
196 $newServices->defineService(
198 function () use ( &$instantiatorReturnValues ) {
199 return array_shift( $instantiatorReturnValues );
204 $oldTestService = $newServices->getService(
'Test' );
206 MediaWikiServices::resetChildProcessServices();
207 $finalServices = MediaWikiServices::getInstance();
209 $newTestService = $finalServices->getService(
'Test' );
210 $this->assertNotSame( $oldTestService, $newTestService );
212 MediaWikiServices::forceGlobalInstance( $oldServices );
221 function () use ( &$serviceCounter ) {
223 $service = $this->createMock(
'MediaWiki\Services\DestructibleService' );
224 $service->expects( $this->once() )->method(
'destroy' );
230 $services->resetServiceForTesting(
'Test' );
231 $this->assertEquals( 0, $serviceCounter,
'No service instance should be created yet.' );
233 $oldInstance =
$services->getService(
'Test' );
234 $this->assertEquals( 1, $serviceCounter,
'A service instance should exit now.' );
237 $services->resetServiceForTesting(
'Test' );
238 $newInstance =
$services->getService(
'Test' );
240 $this->assertNotSame( $oldInstance, $newInstance );
243 $newInstance->destroy();
302 'BootstrapConfig' => [
'BootstrapConfig', Config::class ],
303 'ConfigFactory' => [
'ConfigFactory', ConfigFactory::class ],
304 'MainConfig' => [
'MainConfig', Config::class ],
305 'SiteStore' => [
'SiteStore', SiteStore::class ],
306 'SiteLookup' => [
'SiteLookup', SiteLookup::class ],
307 'StatsdDataFactory' => [
'StatsdDataFactory', IBufferingStatsdDataFactory::class ],
308 'InterwikiLookup' => [
'InterwikiLookup', InterwikiLookup::class ],
309 'EventRelayerGroup' => [
'EventRelayerGroup', EventRelayerGroup::class ],
310 'SearchEngineFactory' => [
'SearchEngineFactory', SearchEngineFactory::class ],
311 'SearchEngineConfig' => [
'SearchEngineConfig', SearchEngineConfig::class ],
312 'SkinFactory' => [
'SkinFactory', SkinFactory::class ],
313 'DBLoadBalancerFactory' => [
'DBLoadBalancerFactory', Wikimedia\Rdbms\LBFactory::class ],
314 'DBLoadBalancer' => [
'DBLoadBalancer',
'LoadBalancer' ],
315 'WatchedItemStore' => [
'WatchedItemStore', WatchedItemStore::class ],
316 'WatchedItemQueryService' => [
'WatchedItemQueryService', WatchedItemQueryService::class ],
317 'CryptRand' => [
'CryptRand', CryptRand::class ],
318 'CryptHKDF' => [
'CryptHKDF', CryptHKDF::class ],
319 'MediaHandlerFactory' => [
'MediaHandlerFactory', MediaHandlerFactory::class ],
320 'Parser' => [
'Parser', Parser::class ],
321 'ParserCache' => [
'ParserCache', ParserCache::class ],
322 'GenderCache' => [
'GenderCache', GenderCache::class ],
323 'LinkCache' => [
'LinkCache', LinkCache::class ],
324 'LinkRenderer' => [
'LinkRenderer', LinkRenderer::class ],
325 'LinkRendererFactory' => [
'LinkRendererFactory', LinkRendererFactory::class ],
326 '_MediaWikiTitleCodec' => [
'_MediaWikiTitleCodec', MediaWikiTitleCodec::class ],
327 'MimeAnalyzer' => [
'MimeAnalyzer', MimeAnalyzer::class ],
328 'TitleFormatter' => [
'TitleFormatter', TitleFormatter::class ],
329 'TitleParser' => [
'TitleParser', TitleParser::class ],
330 'ProxyLookup' => [
'ProxyLookup', ProxyLookup::class ],
331 'MainObjectStash' => [
'MainObjectStash', BagOStuff::class ],
332 'MainWANObjectCache' => [
'MainWANObjectCache', WANObjectCache::class ],
333 'LocalServerObjectCache' => [
'LocalServerObjectCache', BagOStuff::class ],
334 'VirtualRESTServiceClient' => [
'VirtualRESTServiceClient', VirtualRESTServiceClient::class ],
335 'ShellCommandFactory' => [
'ShellCommandFactory', CommandFactory::class ],