wiki.techinc.nl/tests/phpunit/includes/filebackend/FileBackendGroupIntegrationTest.php
Aryeh Gregor bd2a439502 Integration tests for FileBackendGroup
100% coverage except for one bit of the code that I didn't understand.
Unit tests to come, together with rewrite as a service.

Change-Id: Ib01758d994a9e5587a4fcb5edc3d80010ef05615
2019-08-28 11:21:44 +03:00

57 lines
1.5 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();
foreach ( $serviceMembers as $key => $name ) {
$this->$key = $services->getService( $name );
}
return FileBackendGroup::singleton();
}
}