Merge "Don't trigger MessageBlobStore during tests"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 2 Apr 2015 21:16:37 +0000 (21:16 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 2 Apr 2015 21:16:37 +0000 (21:16 +0000)
includes/MessageBlobStore.php
includes/cache/LocalisationCache.php
includes/cache/MessageCache.php
includes/installer/DatabaseUpdater.php
includes/resourceloader/ResourceLoader.php
tests/phpunit/includes/OutputPageTest.php

index c384188..011cae6 100644 (file)
@@ -36,15 +36,12 @@ class MessageBlobStore {
         * Get the singleton instance
         *
         * @since 1.24
+        * @deprecated since 1.25
         * @return MessageBlobStore
         */
        public static function getInstance() {
-               static $instance = null;
-               if ( $instance === null ) {
-                       $instance = new self;
-               }
-
-               return $instance;
+               wfDeprecated( __METHOD__, '1.25' );
+               return new self;
        }
 
        /**
index e270f5f..dc5a2eb 100644 (file)
@@ -1020,7 +1020,8 @@ class LocalisationCache {
                # HACK: If using a null (i.e. disabled) storage backend, we
                # can't write to the MessageBlobStore either
                if ( $purgeBlobs && !$this->store instanceof LCStoreNull ) {
-                       MessageBlobStore::getInstance()->clear();
+                       $blobStore = new MessageBlobStore();
+                       $blobStore->clear();
                }
 
        }
index 04f5887..82919c7 100644 (file)
@@ -562,7 +562,8 @@ class MessageCache {
 
                // Update the message in the message blob store
                global $wgContLang;
-               MessageBlobStore::getInstance()->updateMessage( $wgContLang->lcfirst( $msg ) );
+               $blobStore = new MessageBlobStore();
+               $blobStore->updateMessage( $wgContLang->lcfirst( $msg ) );
 
                Hooks::run( 'MessageCacheReplace', array( $title, $text ) );
 
index b676f45..12ef91a 100644 (file)
@@ -932,7 +932,8 @@ abstract class DatabaseUpdater {
                if ( $wgLocalisationCacheConf['manualRecache'] ) {
                        $this->rebuildLocalisationCache();
                }
-               MessageBlobStore::getInstance()->clear();
+               $blobStore = new MessageBlobStore();
+               $blobStore->clear();
                $this->output( "done.\n" );
        }
 
index 5eab3cb..b9d1b2b 100644 (file)
@@ -72,6 +72,11 @@ class ResourceLoader {
         */
        protected $errors = array();
 
+       /**
+        * @var MessageBlobStore
+        */
+       protected $blobStore;
+
        /**
         * Load information stored in the database about modules.
         *
@@ -250,6 +255,7 @@ class ResourceLoader {
                        $this->registerTestModules();
                }
 
+               $this->setMessageBlobStore( new MessageBlobStore() );
        }
 
        /**
@@ -259,6 +265,14 @@ class ResourceLoader {
                return $this->config;
        }
 
+       /**
+        * @param MessageBlobStore $blobStore
+        * @since 1.25
+        */
+       public function setMessageBlobStore( MessageBlobStore $blobStore ) {
+               $this->blobStore = $blobStore;
+       }
+
        /**
         * Register a module with the ResourceLoader system.
         *
@@ -885,7 +899,7 @@ MESSAGE;
                // Pre-fetch blobs
                if ( $context->shouldIncludeMessages() ) {
                        try {
-                               $blobs = MessageBlobStore::getInstance()->get( $this, $modules, $context->getLanguage() );
+                               $blobs = $this->blobStore->get( $this, $modules, $context->getLanguage() );
                        } catch ( Exception $e ) {
                                MWExceptionHandler::logException( $e );
                                wfDebugLog(
index 2526fcc..ee6a8cf 100644 (file)
@@ -239,6 +239,7 @@ document.write("\u003Cscript src=\"http://127.0.0.1:8080/w/load.php?debug=false\
                $ctx->setLanguage( 'en' );
                $out = new OutputPage( $ctx );
                $rl = $out->getResourceLoader();
+               $rl->setMessageBlobStore( new NullMessageBlobStore() );
                $rl->register( array(
                        'test.foo' => new ResourceLoaderTestModule( array(
                                'script' => 'mw.test.foo( { a: true } );',
@@ -280,3 +281,26 @@ document.write("\u003Cscript src=\"http://127.0.0.1:8080/w/load.php?debug=false\
                $this->assertEquals( $expectedHtml, $actualHtml );
        }
 }
+
+/**
+ * MessageBlobStore that doesn't do anything
+ */
+class NullMessageBlobStore extends MessageBlobStore {
+       public function get ( ResourceLoader $resourceLoader, $modules, $lang ) {
+               return array();
+       }
+
+       public function insertMessageBlob ( $name, ResourceLoaderModule $module, $lang ) {
+               return false;
+       }
+
+       public function updateModule ( $name, ResourceLoaderModule $module, $lang ) {
+               return;
+       }
+
+       public function updateMessage ( $key ) {
+       }
+       public function clear() {
+       }
+}
+