| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Config\ServiceOptions; |
| 4 |
use MediaWiki\FileBackend\FileBackendGroup; |
| 5 |
use MediaWiki\FileBackend\FSFile\TempFSFileFactory; |
| 6 |
use MediaWiki\FileBackend\LockManager\LockManagerGroupFactory; |
| 7 |
use MediaWiki\Tests\Unit\DummyServicesTrait; |
| 8 |
use Wikimedia\Mime\MimeAnalyzer; |
| 9 |
use Wikimedia\ObjectCache\BagOStuff; |
| 10 |
use Wikimedia\ObjectCache\EmptyBagOStuff; |
| 11 |
use Wikimedia\ObjectCache\WANObjectCache; |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class FileBackendGroupTest extends MediaWikiUnitTestCase { |
| 17 |
use DummyServicesTrait; |
| 18 |
use FileBackendGroupTestTrait; |
| 19 |
|
| 20 |
protected function setUp(): void { |
| 21 |
parent::setUp(); |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
$GLOBALS['wgProfiler'] = []; |
| 29 |
} |
| 30 |
|
| 31 |
private static function getWikiID() { |
| 32 |
return 'mywiki'; |
| 33 |
} |
| 34 |
|
| 35 |
private function getLocalServerCache(): BagOStuff { |
| 36 |
if ( !$this->srvCache ) { |
| 37 |
$this->srvCache = new EmptyBagOStuff; |
| 38 |
} |
| 39 |
return $this->srvCache; |
| 40 |
} |
| 41 |
|
| 42 |
private function getWANObjectCache(): WANObjectCache { |
| 43 |
if ( !$this->wanCache ) { |
| 44 |
$this->wanCache = $this->createNoOpMock( WANObjectCache::class ); |
| 45 |
} |
| 46 |
return $this->wanCache; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
private function getLockManagerGroupFactory( $domain = 'mywiki' ): LockManagerGroupFactory { |
| 55 |
if ( !$this->lmgFactory ) { |
| 56 |
$mockLmg = $this->createNoOpMock( LockManagerGroup::class, [ 'get' ] ); |
| 57 |
$mockLmg->method( 'get' )->with( 'fsLockManager' )->willReturn( 'string lock manager' ); |
| 58 |
|
| 59 |
$this->lmgFactory = $this->createNoOpMock( LockManagerGroupFactory::class, |
| 60 |
[ 'getLockManagerGroup' ] ); |
| 61 |
$this->lmgFactory->method( 'getLockManagerGroup' )->with( $domain ) |
| 62 |
->willReturn( $mockLmg ); |
| 63 |
} |
| 64 |
return $this->lmgFactory; |
| 65 |
} |
| 66 |
|
| 67 |
private function getTempFSFileFactory(): TempFSFileFactory { |
| 68 |
if ( !$this->tmpFileFactory ) { |
| 69 |
$this->tmpFileFactory = $this->createNoOpMock( TempFSFileFactory::class ); |
| 70 |
} |
| 71 |
return $this->tmpFileFactory; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
private function newObj( array $options = [] ): FileBackendGroup { |
| 84 |
return new FileBackendGroup( |
| 85 |
new ServiceOptions( |
| 86 |
FileBackendGroup::CONSTRUCTOR_OPTIONS, $options, self::getDefaultOptions() ), |
| 87 |
$this->getDummyReadOnlyMode( $options['readOnlyMode'] ?? false ), |
| 88 |
$this->getLocalServerCache(), |
| 89 |
$this->getWANObjectCache(), |
| 90 |
$options['mimeAnalyzer'] ?? $this->createNoOpMock( MimeAnalyzer::class ), |
| 91 |
$options['lmgFactory'] ?? $this->getLockManagerGroupFactory(), |
| 92 |
$options['tmpFileFactory'] ?? $this->getTempFSFileFactory(), |
| 93 |
$this->getDummyObjectFactory() |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
} |