62 $oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
64 $this->assertInstanceOf( MediaWikiServices::class, $oldServices );
65 $this->assertNotSame( $oldServices, $newServices );
67 $theServices = MediaWikiServices::getInstance();
68 $this->assertSame( $theServices, $newServices );
70 MediaWikiServices::forceGlobalInstance( $oldServices );
72 $theServices = MediaWikiServices::getInstance();
73 $this->assertSame( $theServices, $oldServices );
78 $oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
80 $service1 = $this->createMock( SalvageableService::class );
81 $service1->expects( $this->never() )
82 ->method(
'salvage' );
84 $newServices->defineService(
86 function () use ( $service1 ) {
92 $newServices->getService(
'Test' );
94 MediaWikiServices::resetGlobalInstance( $this->
newTestConfig() );
95 $theServices = MediaWikiServices::getInstance();
99 $theServices->getService(
'Test' ),
100 'service definition should survive reset'
103 $this->assertNotSame( $theServices, $newServices );
104 $this->assertNotSame( $theServices, $oldServices );
106 MediaWikiServices::forceGlobalInstance( $oldServices );
111 $oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
113 $service1 = $this->createMock( SalvageableService::class );
114 $service1->expects( $this->never() )
115 ->method(
'salvage' );
117 $service2 = $this->createMock( SalvageableService::class );
118 $service2->expects( $this->once() )
119 ->method(
'salvage' )
123 $instantiatorReturnValues = [
128 $newServices->defineService(
130 function () use ( &$instantiatorReturnValues ) {
131 return array_shift( $instantiatorReturnValues );
136 $newServices->getService(
'Test' );
138 MediaWikiServices::resetGlobalInstance( $this->
newTestConfig(),
'quick' );
139 $theServices = MediaWikiServices::getInstance();
141 $this->assertSame( $service2, $theServices->getService(
'Test' ) );
143 $this->assertNotSame( $theServices, $newServices );
144 $this->assertNotSame( $theServices, $oldServices );
146 MediaWikiServices::forceGlobalInstance( $oldServices );
151 $oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
153 $lbFactory = $this->getMockBuilder( \Wikimedia\Rdbms\LBFactorySimple::class )
154 ->disableOriginalConstructor()
157 $newServices->redefineService(
158 'DBLoadBalancerFactory',
159 function () use ( $lbFactory ) {
165 $newServices->getService(
'DBLoadBalancerFactory' );
167 MediaWikiServices::disableStorageBackend();
170 MediaWikiServices::getInstance()->getService(
'DBLoadBalancerFactory' );
171 $this->fail(
'DBLoadBalancerFactory should have been disabled' );
175 }
catch ( Throwable $ex ) {
176 $this->fail(
'ServiceDisabledException expected, caught ' . get_class( $ex ) );
179 MediaWikiServices::forceGlobalInstance( $oldServices );
180 $newServices->destroy();
183 $this->assertTrue(
true );
188 $oldServices = MediaWikiServices::forceGlobalInstance( $newServices );
190 $service1 = $this->createMock( DestructibleService::class );
191 $service1->expects( $this->once() )
192 ->method(
'destroy' );
194 $service2 = $this->createMock( DestructibleService::class );
195 $service2->expects( $this->never() )
196 ->method(
'destroy' );
199 $instantiatorReturnValues = [
204 $newServices->defineService(
206 function () use ( &$instantiatorReturnValues ) {
207 return array_shift( $instantiatorReturnValues );
212 $oldTestService = $newServices->getService(
'Test' );
214 MediaWikiServices::resetChildProcessServices();
215 $finalServices = MediaWikiServices::getInstance();
217 $newTestService = $finalServices->getService(
'Test' );
218 $this->assertNotSame( $oldTestService, $newTestService );
220 MediaWikiServices::forceGlobalInstance( $oldServices );
229 function () use ( &$serviceCounter ) {
231 $service = $this->createMock(
MediaWiki\Services\DestructibleService::class );
232 $service->expects( $this->once() )->method(
'destroy' );
238 $services->resetServiceForTesting(
'Test' );
239 $this->assertEquals( 0, $serviceCounter,
'No service instance should be created yet.' );
241 $oldInstance =
$services->getService(
'Test' );
242 $this->assertEquals( 1, $serviceCounter,
'A service instance should exit now.' );
245 $services->resetServiceForTesting(
'Test' );
246 $newInstance =
$services->getService(
'Test' );
248 $this->assertNotSame( $oldInstance, $newInstance );
251 $newInstance->destroy();
310 'BootstrapConfig' => [
'BootstrapConfig', Config::class ],
311 'ConfigFactory' => [
'ConfigFactory', ConfigFactory::class ],
312 'MainConfig' => [
'MainConfig', Config::class ],
313 'SiteStore' => [
'SiteStore', SiteStore::class ],
314 'SiteLookup' => [
'SiteLookup', SiteLookup::class ],
315 'StatsdDataFactory' => [
'StatsdDataFactory', IBufferingStatsdDataFactory::class ],
316 'InterwikiLookup' => [
'InterwikiLookup', InterwikiLookup::class ],
317 'EventRelayerGroup' => [
'EventRelayerGroup', EventRelayerGroup::class ],
318 'SearchEngineFactory' => [
'SearchEngineFactory', SearchEngineFactory::class ],
319 'SearchEngineConfig' => [
'SearchEngineConfig', SearchEngineConfig::class ],
320 'SkinFactory' => [
'SkinFactory', SkinFactory::class ],
321 'DBLoadBalancerFactory' => [
'DBLoadBalancerFactory', Wikimedia\Rdbms\LBFactory::class ],
322 'DBLoadBalancer' => [
'DBLoadBalancer', Wikimedia\Rdbms\LoadBalancer::class ],
323 'WatchedItemStore' => [
'WatchedItemStore', WatchedItemStore::class ],
324 'WatchedItemQueryService' => [
'WatchedItemQueryService', WatchedItemQueryService::class ],
325 'CryptRand' => [
'CryptRand', CryptRand::class ],
326 'CryptHKDF' => [
'CryptHKDF', CryptHKDF::class ],
327 'MediaHandlerFactory' => [
'MediaHandlerFactory', MediaHandlerFactory::class ],
328 'Parser' => [
'Parser', Parser::class ],
329 'ParserCache' => [
'ParserCache', ParserCache::class ],
330 'GenderCache' => [
'GenderCache', GenderCache::class ],
331 'LinkCache' => [
'LinkCache', LinkCache::class ],
332 'LinkRenderer' => [
'LinkRenderer', LinkRenderer::class ],
333 'LinkRendererFactory' => [
'LinkRendererFactory', LinkRendererFactory::class ],
334 '_MediaWikiTitleCodec' => [
'_MediaWikiTitleCodec', MediaWikiTitleCodec::class ],
335 'MimeAnalyzer' => [
'MimeAnalyzer', MimeAnalyzer::class ],
336 'TitleFormatter' => [
'TitleFormatter', TitleFormatter::class ],
337 'TitleParser' => [
'TitleParser', TitleParser::class ],
338 'ProxyLookup' => [
'ProxyLookup', ProxyLookup::class ],
339 'MainObjectStash' => [
'MainObjectStash', BagOStuff::class ],
340 'MainWANObjectCache' => [
'MainWANObjectCache', WANObjectCache::class ],
341 'LocalServerObjectCache' => [
'LocalServerObjectCache', BagOStuff::class ],
342 'VirtualRESTServiceClient' => [
'VirtualRESTServiceClient', VirtualRESTServiceClient::class ],
343 'ShellCommandFactory' => [
'ShellCommandFactory', CommandFactory::class ],
344 'BlobStoreFactory' => [
'BlobStoreFactory', BlobStoreFactory::class ],
345 'BlobStore' => [
'BlobStore', BlobStore::class ],
346 '_SqlBlobStore' => [
'_SqlBlobStore', SqlBlobStore::class ],
347 'RevisionStore' => [
'RevisionStore', RevisionStore::class ],
348 'RevisionLookup' => [
'RevisionLookup', RevisionLookup::class ],
349 'HttpRequestFactory' => [
'HttpRequestFactory', HttpRequestFactory::class ],
350 'CommentStore' => [
'CommentStore', CommentStore::class ],