From 9d5e3ad0f5a68b435e539315709866c677562adf Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Wed, 10 Apr 2019 16:20:28 +0300 Subject: [PATCH] Drop clearCache() from (Configured)ReadOnlyMode These are services, so tests should just override services to reset them. Change-Id: Icb1a041f8fac1ea0b7421e69b7b31b24171d868b --- RELEASE-NOTES-1.33 | 2 ++ includes/ConfiguredReadOnlyMode.php | 7 ------ includes/ReadOnlyMode.php | 7 ------ .../includes/GlobalFunctions/GlobalTest.php | 22 +++++++---------- tests/phpunit/includes/ReadOnlyModeTest.php | 24 ------------------- 5 files changed, 10 insertions(+), 52 deletions(-) diff --git a/RELEASE-NOTES-1.33 b/RELEASE-NOTES-1.33 index fd316c4e27..39d502a00d 100644 --- a/RELEASE-NOTES-1.33 +++ b/RELEASE-NOTES-1.33 @@ -366,6 +366,8 @@ because of Phabricator reports. For classes that inherit from MediaWikiTestCase and used setMwGlobals() to modify a variable that affects namespaces, caches will automatically be reset and any calls to MWNamespace::clearCaches() can be removed entirely. +* ReadOnlyMode::clearCache() and ConfiguredReadOnlyMode::clearCache() have been + removed. Use MediaWikiTestCase::overrideMwServices() instead. === Deprecations in 1.33 === * The configuration option $wgUseESI has been deprecated, and is expected diff --git a/includes/ConfiguredReadOnlyMode.php b/includes/ConfiguredReadOnlyMode.php index 17c28ec388..7df2aed281 100644 --- a/includes/ConfiguredReadOnlyMode.php +++ b/includes/ConfiguredReadOnlyMode.php @@ -63,11 +63,4 @@ class ConfiguredReadOnlyMode { public function setReason( $msg ) { $this->overrideReason = $msg; } - - /** - * Clear the cache of the read only file - */ - public function clearCache() { - $this->fileReason = null; - } } diff --git a/includes/ReadOnlyMode.php b/includes/ReadOnlyMode.php index e767359929..1a0929026f 100644 --- a/includes/ReadOnlyMode.php +++ b/includes/ReadOnlyMode.php @@ -58,11 +58,4 @@ class ReadOnlyMode { public function setReason( $msg ) { $this->configuredReadOnly->setReason( $msg ); } - - /** - * Clear the cache of the read only file - */ - public function clearCache() { - $this->configuredReadOnly->clearCache(); - } } diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php index 22fe3cec77..9443b19e06 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php @@ -14,6 +14,7 @@ class GlobalTest extends MediaWikiTestCase { unlink( $readOnlyFile ); $this->setMwGlobals( [ + 'wgReadOnly' => null, 'wgReadOnlyFile' => $readOnlyFile, 'wgUrlProtocols' => [ 'http://', @@ -108,10 +109,6 @@ class GlobalTest extends MediaWikiTestCase { * @covers ::wfReadOnly */ public function testReadOnlyEmpty() { - global $wgReadOnly; - $wgReadOnly = null; - - MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()->clearCache(); $this->assertFalse( wfReadOnly() ); $this->assertFalse( wfReadOnly() ); } @@ -121,23 +118,17 @@ class GlobalTest extends MediaWikiTestCase { * @covers ::wfReadOnly */ public function testReadOnlySet() { - global $wgReadOnly, $wgReadOnlyFile; - - $readOnlyMode = MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode(); - $readOnlyMode->clearCache(); + global $wgReadOnlyFile; $f = fopen( $wgReadOnlyFile, "wt" ); fwrite( $f, 'Message' ); fclose( $f ); - $wgReadOnly = null; # Check on $wgReadOnlyFile + + // Reset the service to avoid cached results + $this->overrideMwServices(); $this->assertTrue( wfReadOnly() ); $this->assertTrue( wfReadOnly() ); # Check cached - - unlink( $wgReadOnlyFile ); - $readOnlyMode->clearCache(); - $this->assertFalse( wfReadOnly() ); - $this->assertFalse( wfReadOnly() ); } /** @@ -146,9 +137,12 @@ class GlobalTest extends MediaWikiTestCase { */ public function testReadOnlyGlobalChange() { $this->assertFalse( wfReadOnlyReason() ); + $this->setMwGlobals( [ 'wgReadOnly' => 'reason' ] ); + $this->overrideMwServices(); + $this->assertSame( 'reason', wfReadOnlyReason() ); } diff --git a/tests/phpunit/includes/ReadOnlyModeTest.php b/tests/phpunit/includes/ReadOnlyModeTest.php index b14424fb3a..2d91d4de9f 100644 --- a/tests/phpunit/includes/ReadOnlyModeTest.php +++ b/tests/phpunit/includes/ReadOnlyModeTest.php @@ -167,28 +167,4 @@ class ReadOnlyModeTest extends MediaWikiTestCase { $rom->setReason( 'override' ); $this->assertSame( 'override', $rom->getReason() ); } - - /** - * @covers ReadOnlyMode::clearCache - * @covers ConfiguredReadOnlyMode::clearCache - */ - public function testClearCache() { - $fileName = $this->getNewTempFile(); - unlink( $fileName ); - $config = new HashConfig( [ - 'ReadOnly' => null, - 'ReadOnlyFile' => $fileName, - ] ); - $cro = new ConfiguredReadOnlyMode( $config ); - $lb = $this->createLB( [ 'lbMessage' => false ] ); - $rom = new ReadOnlyMode( $cro, $lb ); - - $this->assertSame( false, $rom->getReason(), 'initial' ); - - file_put_contents( $fileName, 'file' ); - $this->assertSame( false, $rom->getReason(), 'stale' ); - - $rom->clearCache(); - $this->assertSame( 'file', $rom->getReason(), 'fresh' ); - } } -- 2.20.1