2019-08-13 08:52:13 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
|
|
|
|
use MediaWiki\FileBackend\FSFile\TempFSFileFactory;
|
|
|
|
|
use MediaWiki\FileBackend\LockManager\LockManagerGroupFactory;
|
2019-10-23 13:34:53 +00:00
|
|
|
use Wikimedia\ObjectFactory;
|
2019-08-13 08:52:13 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @coversDefaultClass FileBackendGroup
|
|
|
|
|
*/
|
|
|
|
|
class FileBackendGroupTest extends MediaWikiUnitTestCase {
|
|
|
|
|
use FileBackendGroupTestTrait;
|
|
|
|
|
|
2020-03-16 18:07:56 +00:00
|
|
|
protected function setUp() : void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
// This config var is not yet dependency-injected.
|
|
|
|
|
// FileBackendGroup has a default option 'profiler', that holds a closure
|
|
|
|
|
// that calls Profiler::instance(), which doesn't use service wiring yet.
|
|
|
|
|
// Without this, the variable would be undefined there.
|
|
|
|
|
// TODO: Remove this once Profiler uses service wiring and is injected
|
|
|
|
|
// into FileBackendGroup.
|
|
|
|
|
$GLOBALS['wgProfiler'] = [];
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-13 08:52:13 +00:00
|
|
|
private static function getWikiID() {
|
|
|
|
|
return 'mywiki';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getNoOpMock( $class ) {
|
|
|
|
|
$mock = $this->createMock( $class );
|
|
|
|
|
$mock->expects( $this->never() )->method( $this->anything() );
|
|
|
|
|
return $mock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getLocalServerCache() : BagOStuff {
|
|
|
|
|
if ( !$this->srvCache ) {
|
|
|
|
|
$this->srvCache = new EmptyBagOStuff;
|
|
|
|
|
}
|
|
|
|
|
return $this->srvCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getWANObjectCache() : WANObjectCache {
|
|
|
|
|
if ( !$this->wanCache ) {
|
|
|
|
|
$this->wanCache = $this->getNoOpMock( WANObjectCache::class );
|
|
|
|
|
}
|
|
|
|
|
return $this->wanCache;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $domain Expected argument that LockManagerGroupFactory::getLockManagerGroup
|
|
|
|
|
* will receive
|
2021-01-16 19:44:17 +00:00
|
|
|
* @return LockManagerGroupFactory
|
2019-08-13 08:52:13 +00:00
|
|
|
*/
|
|
|
|
|
private function getLockManagerGroupFactory( $domain = 'mywiki' ) : LockManagerGroupFactory {
|
|
|
|
|
if ( !$this->lmgFactory ) {
|
|
|
|
|
$mockLmg = $this->createMock( LockManagerGroup::class );
|
|
|
|
|
$mockLmg->method( 'get' )->with( 'fsLockManager' )->willReturn( 'string lock manager' );
|
|
|
|
|
$mockLmg->expects( $this->never() )->method( $this->anythingBut( 'get' ) );
|
|
|
|
|
|
|
|
|
|
$this->lmgFactory = $this->createMock( LockManagerGroupFactory::class );
|
|
|
|
|
$this->lmgFactory->method( 'getLockManagerGroup' )->with( $domain )
|
|
|
|
|
->willReturn( $mockLmg );
|
|
|
|
|
$this->lmgFactory->expects( $this->never() )
|
|
|
|
|
->method( $this->anythingBut( 'getLockManagerGroup' ) );
|
|
|
|
|
}
|
|
|
|
|
return $this->lmgFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getTempFSFileFactory() : TempFSFileFactory {
|
|
|
|
|
if ( !$this->tmpFileFactory ) {
|
|
|
|
|
$this->tmpFileFactory = $this->getNoOpMock( TempFSFileFactory::class );
|
|
|
|
|
}
|
|
|
|
|
return $this->tmpFileFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $options Dictionary to use as a source for ServiceOptions before defaults, plus
|
|
|
|
|
* the following options are available to override other arguments:
|
|
|
|
|
* * 'configuredROMode'
|
|
|
|
|
* * 'lmgFactory'
|
|
|
|
|
* * 'mimeAnalyzer'
|
|
|
|
|
* * 'tmpFileFactory'
|
2021-01-16 19:44:17 +00:00
|
|
|
* @return FileBackendGroup
|
2019-08-13 08:52:13 +00:00
|
|
|
*/
|
|
|
|
|
private function newObj( array $options = [] ) : FileBackendGroup {
|
|
|
|
|
return new FileBackendGroup(
|
|
|
|
|
new ServiceOptions(
|
|
|
|
|
FileBackendGroup::CONSTRUCTOR_OPTIONS, $options, self::getDefaultOptions() ),
|
|
|
|
|
$options['configuredROMode'] ?? new ConfiguredReadOnlyMode( false ),
|
|
|
|
|
$this->getLocalServerCache(),
|
|
|
|
|
$this->getWANObjectCache(),
|
|
|
|
|
$options['mimeAnalyzer'] ?? $this->getNoOpMock( MimeAnalyzer::class ),
|
|
|
|
|
$options['lmgFactory'] ?? $this->getLockManagerGroupFactory(),
|
2019-10-23 13:34:53 +00:00
|
|
|
$options['tmpFileFactory'] ?? $this->getTempFSFileFactory(),
|
|
|
|
|
new ObjectFactory( $this->getNoOpMock( Psr\Container\ContainerInterface::class ) )
|
2019-08-13 08:52:13 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|