Drop clearCache() from (Configured)ReadOnlyMode
authorAryeh Gregor <ayg@aryeh.name>
Wed, 10 Apr 2019 13:20:28 +0000 (16:20 +0300)
committerAryeh Gregor <ayg@aryeh.name>
Wed, 10 Apr 2019 16:39:34 +0000 (19:39 +0300)
These are services, so tests should just override services to reset
them.

Change-Id: Icb1a041f8fac1ea0b7421e69b7b31b24171d868b

RELEASE-NOTES-1.33
includes/ConfiguredReadOnlyMode.php
includes/ReadOnlyMode.php
tests/phpunit/includes/GlobalFunctions/GlobalTest.php
tests/phpunit/includes/ReadOnlyModeTest.php

index fd316c4..39d502a 100644 (file)
@@ -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
index 17c28ec..7df2aed 100644 (file)
@@ -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;
-       }
 }
index e767359..1a09290 100644 (file)
@@ -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();
-       }
 }
index 22fe3ce..9443b19 100644 (file)
@@ -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() );
        }
 
index b14424f..2d91d4d 100644 (file)
@@ -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' );
-       }
 }