本文整理汇总了PHP中MediaWiki\MediaWikiServices::forceGlobalInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP MediaWikiServices::forceGlobalInstance方法的具体用法?PHP MediaWikiServices::forceGlobalInstance怎么用?PHP MediaWikiServices::forceGlobalInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MediaWiki\MediaWikiServices
的用法示例。
在下文中一共展示了MediaWikiServices::forceGlobalInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testResetChildProcessServices
public function testResetChildProcessServices()
{
$newServices = $this->newMediaWikiServices();
$oldServices = MediaWikiServices::forceGlobalInstance($newServices);
$service1 = $this->getMock(DestructibleService::class);
$service1->expects($this->once())->method('destroy');
$service2 = $this->getMock(DestructibleService::class);
$service2->expects($this->never())->method('destroy');
// sequence of values the instantiator will return
$instantiatorReturnValues = [$service1, $service2];
$newServices->defineService('Test', function () use(&$instantiatorReturnValues) {
return array_shift($instantiatorReturnValues);
});
// force the service to become active, so we can check that it does get destroyed
$oldTestService = $newServices->getService('Test');
MediaWikiServices::resetChildProcessServices();
$finalServices = MediaWikiServices::getInstance();
$newTestService = $finalServices->getService('Test');
$this->assertNotSame($oldTestService, $newTestService);
MediaWikiServices::forceGlobalInstance($oldServices);
}
示例2: overrideMwServices
/**
* Stashes the global instance of MediaWikiServices, and installs a new one,
* allowing test cases to override settings and services.
* The previous instance of MediaWikiServices will be restored on tearDown.
*
* @since 1.27
*
* @param Config $configOverrides Configuration overrides for the new MediaWikiServices instance.
* @param callable[] $services An associative array of services to re-define. Keys are service
* names, values are callables.
*
* @return MediaWikiServices
* @throws MWException
*/
protected function overrideMwServices(Config $configOverrides = null, array $services = [])
{
if (!$configOverrides) {
$configOverrides = new HashConfig();
}
$oldInstance = MediaWikiServices::getInstance();
$oldConfigFactory = $oldInstance->getConfigFactory();
$testConfig = self::makeTestConfig(null, $configOverrides);
$newInstance = new MediaWikiServices($testConfig);
// Load the default wiring from the specified files.
// NOTE: this logic mirrors the logic in MediaWikiServices::newInstance.
$wiringFiles = $testConfig->get('ServiceWiringFiles');
$newInstance->loadWiringFiles($wiringFiles);
// Provide a traditional hook point to allow extensions to configure services.
Hooks::run('MediaWikiServices', [$newInstance]);
foreach ($services as $name => $callback) {
$newInstance->redefineService($name, $callback);
}
self::installTestServices($oldConfigFactory, $newInstance);
MediaWikiServices::forceGlobalInstance($newInstance);
return $newInstance;
}