wiki.techinc.nl/tests/phpunit/includes/filebackend/FileBackendGroupIntegrationTest.php
Amir Sarabadani 7d137d0452 Deprecate ConfiguredReadOnlyMode service
Currently, we have two services: ReadOnlyMode and
ConfiguredReadOnlyMode. The former takes the latter and can easily
support every functionality of CRO. I added methods to support that
functionality (the current class is quite small so it's not adding a lot
more to a monster class) and basically fully deprecate the service
itself to improve developer experience.

It is only called in two extensions in production with straightforward
fix so I directly went with hard-deprecation.

Bug: T343917
Depends-On: Icec0ad3f30c471b428efe80dfb9129f55a351194
Change-Id: I421fd5c8fee7af41c059419c2bbc85b8dccc04ed
2023-09-12 23:22:13 +00:00

76 lines
2.1 KiB
PHP

<?php
use MediaWiki\FileBackend\LockManager\LockManagerGroupFactory;
use MediaWiki\MainConfigNames;
use MediaWiki\Tests\Unit\DummyServicesTrait;
use MediaWiki\WikiMap\WikiMap;
/**
* @coversDefaultClass FileBackendGroup
*/
class FileBackendGroupIntegrationTest extends MediaWikiIntegrationTestCase {
use FileBackendGroupTestTrait;
use DummyServicesTrait;
private static function getWikiID() {
return WikiMap::getCurrentWikiId();
}
private function getLockManagerGroupFactory( $domain ): LockManagerGroupFactory {
return $this->getServiceContainer()->getLockManagerGroupFactory();
}
private function newObj( array $options = [] ): FileBackendGroup {
$globals = [
MainConfigNames::DirectoryMode,
MainConfigNames::FileBackends,
MainConfigNames::ForeignFileRepos,
MainConfigNames::LocalFileRepo,
];
foreach ( $globals as $global ) {
$this->overrideConfigValue(
$global, $options[$global] ?? self::getDefaultOptions()[$global] );
}
$serviceMembers = [
'readOnlyMode' => 'ReadOnlyMode',
'srvCache' => 'LocalServerObjectCache',
'wanCache' => 'MainWANObjectCache',
'mimeAnalyzer' => 'MimeAnalyzer',
'lmgFactory' => 'LockManagerGroupFactory',
'tmpFileFactory' => 'TempFSFileFactory',
];
foreach ( $serviceMembers as $key => $name ) {
if ( isset( $options[$key] ) ) {
if ( $key === 'readOnlyMode' ) {
$this->setService( $name, $this->getDummyReadOnlyMode( $options[$key] ) );
} else {
$this->setService( $name, $options[$key] );
}
}
}
$this->assertSame( [],
array_diff( array_keys( $options ), $globals, array_keys( $serviceMembers ) ) );
$services = $this->getServiceContainer();
$obj = $services->getFileBackendGroup();
foreach ( $serviceMembers as $key => $name ) {
if ( $key === 'readOnlyMode' || $key === 'mimeAnalyzer' ) {
continue;
}
$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;
}
}