wiki.techinc.nl/tests/phpunit/includes/filebackend/FileBackendGroupIntegrationTest.php
Aryeh Gregor 0d3d6be18d Convert FileBackendGroup to service
Bug: T234228
Change-Id: I25575f565eba122cdf971a5945572811d17fa3e1
2019-10-25 10:46:20 +03:00

64 lines
1.7 KiB
PHP

<?php
use MediaWiki\MediaWikiServices;
/**
* @coversDefaultClass FileBackendGroup
* @covers ::singleton
* @covers ::destroySingleton
*/
class FileBackendGroupIntegrationTest extends MediaWikiIntegrationTestCase {
use FileBackendGroupTestTrait;
private static function getWikiID() {
return wfWikiID();
}
private function getLockManagerGroupFactory() {
return MediaWikiServices::getInstance()->getLockManagerGroupFactory();
}
private function newObj( array $options = [] ) : FileBackendGroup {
$globals = [ 'DirectoryMode', 'FileBackends', 'ForeignFileRepos', 'LocalFileRepo' ];
foreach ( $globals as $global ) {
$this->setMwGlobals(
"wg$global", $options[$global] ?? self::getDefaultOptions()[$global] );
}
$serviceMembers = [
'configuredROMode' => 'ConfiguredReadOnlyMode',
'srvCache' => 'LocalServerObjectCache',
'wanCache' => 'MainWANObjectCache',
'mimeAnalyzer' => 'MimeAnalyzer',
'lmgFactory' => 'LockManagerGroupFactory',
'tmpFileFactory' => 'TempFSFileFactory',
];
foreach ( $serviceMembers as $key => $name ) {
if ( isset( $options[$key] ) ) {
$this->setService( $name, $options[$key] );
}
}
$this->assertEmpty(
array_diff( array_keys( $options ), $globals, array_keys( $serviceMembers ) ) );
$this->resetServices();
FileBackendGroup::destroySingleton();
$services = MediaWikiServices::getInstance();
$obj = FileBackendGroup::singleton();
foreach ( $serviceMembers as $key => $name ) {
$this->$key = $services->getService( $name );
if ( $key === 'srvCache' && $this->$key instanceof EmptyBagOStuff ) {
// ServiceWiring will have created its own HashBagOStuff that we don't have a
// reference to. Set null instead.
$this->srvCache = null;
}
}
return $obj;
}
}